Created
February 11, 2016 14:46
-
-
Save xvarlez/c946baf78eb2853e5115 to your computer and use it in GitHub Desktop.
GreenDao schema generator snippet with one-to-many relation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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