de.greenrobot.daogenerator.ToMany Java Examples

The following examples show how to use de.greenrobot.daogenerator.ToMany. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DbDaoGenerator.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
private static void addCustomerOrder(Schema schema) {
    Entity customer = schema.addEntity("Customer");
    customer.addIdProperty();
    customer.addStringProperty("name").notNull();

    Entity order = schema.addEntity("Order");
    order.setTableName("ORDERS"); // "ORDER" is a reserved keyword
    order.addIdProperty();
    Property orderDate = order.addDateProperty("date").getProperty();
    Property customerId = order.addLongProperty("customerId").notNull().getProperty();
    order.addToOne(customer, customerId);

    ToMany customerToOrders = customer.addToMany(order, customerId);
    customerToOrders.setName("orders");
    customerToOrders.orderAsc(orderDate);
}
 
Example #2
Source File: BrainphaserDaoGenerator.java    From BrainPhaser with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String args[]) throws Exception {
    Schema schema = new Schema(DATABASE_VERSION, "de.fhdw.ergoholics.brainphaser.model");

    // Create entities
    Entity userEntity = createUserEntity(schema);
    Entity categoryEntity = createCategoryEntity(schema);
    Entity challengeEntity = createChallengeEntity(schema);
    Entity answerEntity = createAnswerEntity(schema);
    Entity completedEntity = createCompletedEntity(schema);
    Entity settingsEntity = createSettingsEntity(schema);
    Entity statisticsEntity = createStatisticsEntity(schema);

    // category HAS MANY challenge
    Property categoryId = challengeEntity.addLongProperty("categoryId").notNull().getProperty();
    ToMany categoryToChallenge = categoryEntity.addToMany(challengeEntity, categoryId);
    categoryToChallenge.setName("challenges");

    // challenge HAS MANY answer
    Property challengeIdAnswer = answerEntity.addLongProperty("challengeId").notNull().getProperty();
    ToMany challengeToAnswer = challengeEntity.addToMany(answerEntity, challengeIdAnswer);
    challengeToAnswer.setName("answers");

    // user HAS MANY completion
    Property userIdCompleted = completedEntity.addLongProperty("userId").notNull().getProperty();
    ToMany userToCompleted = userEntity.addToMany(completedEntity, userIdCompleted);
    userToCompleted.setName("completions");

    // completion TO ONE challenge
    Property challengeIdCompleted = completedEntity.addLongProperty("challengeId").notNull().getProperty();
    ToOne completedToChallenge = completedEntity.addToOne(challengeEntity, challengeIdCompleted);
    completedToChallenge.setName("challenge");

    // user HAS MANY statistics
    Property userIdStatistics = statisticsEntity.addLongProperty("userId").notNull().getProperty();
    ToMany userToStatistics = userEntity.addToMany(statisticsEntity, userIdStatistics);
    userToStatistics.setName("statistics");

    // statistics TO ONE challenge
    Property challengeIdStatistics = statisticsEntity.addLongProperty("challengeId").notNull().getProperty();
    ToOne completedToStatistics = statisticsEntity.addToOne(challengeEntity, challengeIdStatistics);
    completedToStatistics.setName("statistic");

    // user HAS ONE settings
    Property userIdSettings = userEntity.addLongProperty("settingsId").notNull().getProperty();
    ToOne userToSettings = userEntity.addToOne(settingsEntity, userIdSettings);
    userToSettings.setName("settings");

    new DaoGenerator().generateAll(schema, "../app/src/main/java/");
}