Skip to content

Instantly share code, notes, and snippets.

@xvarlez
Created February 11, 2016 14:46
Show Gist options
  • Save xvarlez/c946baf78eb2853e5115 to your computer and use it in GitHub Desktop.
Save xvarlez/c946baf78eb2853e5115 to your computer and use it in GitHub Desktop.
GreenDao schema generator snippet with one-to-many relation
public class RFDaoGenerator {
public static void main(String args[]) throws Exception {
Schema schema = new Schema(1, "com.orange.reunionflash.data");
// Member
Entity member = schema.addEntity("Member");
member.addIdProperty();
Property addressBookId = member.addStringProperty("addressBookId").notNull().getProperty();
Property groupId = member.addLongProperty("groupId").notNull().getProperty();
// Group
Entity group = schema.addEntity("Group");
group.addIdProperty();
group.addStringProperty("name").notNull();
// 1-To-Many using Member.groupId
member.addToOne(group, groupId);
ToMany contactsList = group.addToMany(member, groupId);
contactsList.setName("contacts");
// Unique index
Index indexUnique = new Index();
indexUnique.addProperty(addressBookId);
indexUnique.addProperty(groupId);
indexUnique.makeUnique();
member.addIndex(indexUnique);
new DaoGenerator().generateAll(schema, "app/src-gen");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment