Java Code Examples for de.greenrobot.daogenerator.Entity#addToMany()

The following examples show how to use de.greenrobot.daogenerator.Entity#addToMany() . 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: Generator.java    From AndroidDatabaseLibraryComparison with MIT License 6 votes vote down vote up
public static void main(String[] args) {
    Schema schema = new Schema(1, "com.raizlabs.android.databasecomparison.greendao.gen");


    Entity simpleAddressItem = getAddressItemEntity(schema, "SimpleAddressItem");

    Entity addressItem = getAddressItemEntity(schema, "AddressItem");
    Entity contactItem = getContactItemEntity(schema);

    Entity addressBook = getAddressBookEntity(schema);

    addressItem.addToOne(addressBook,  addressItem.getProperties().get(0));
    contactItem.addToOne(addressBook,  contactItem.getProperties().get(0));
    addressBook.addToMany(addressItem, addressItem.getProperties().get(0));
    addressBook.addToMany(contactItem, contactItem.getProperties().get(0));

    try {
        new DaoGenerator().generateAll(schema,
                "../app/src/main/java");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
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 3
Source File: Generator.java    From android-orm-benchmark with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    Schema schema = new Schema(DB_VERSION, PACKAGE);

    Entity user = schema.addEntity(USER_ENTITY);
    Property userPk = addCommonColumns(user);

    Entity message = schema.addEntity(MESSAGE_ENTITY);
    message.addIdProperty().autoincrement();
    message.addStringProperty(CONTENT);
    message.addLongProperty(CLIENT_ID);
    message.addIntProperty(CREATED_AT);
    message.addDoubleProperty(SORTED_BY);
    message.addLongProperty(COMMAND_ID).index();
    message.addLongProperty(SENDER_ID).notNull();
    message.addLongProperty(CHANNEL_ID).notNull();

    // One-to-many relationship
    message.addToMany(user, userPk, READERS);

    try {
        new DaoGenerator().generateAll(schema, "../ORM-Benchmark/src/");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 4
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/");
}