de.greenrobot.daogenerator.Property Java Examples

The following examples show how to use de.greenrobot.daogenerator.Property. 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: DBClass.java    From MeiZiNews with MIT License 6 votes vote down vote up
private static void addHtml(Schema schema) {

        // 实体类
        Entity mHtmlEntity = schema.addEntity("HtmlEntity");//表名

        //列名
        mHtmlEntity.addIdProperty();//主键id
        mHtmlEntity.addStringProperty("url");//连接
        mHtmlEntity.addStringProperty("type");//类型
        mHtmlEntity.addStringProperty("title");//标题
        mHtmlEntity.addStringProperty("html");//html
        mHtmlEntity.addStringProperty("summary");//总结
        mHtmlEntity.addStringProperty("collect");//是否收藏



        mHtmlEntity.addDateProperty("hireDate");


        // 收藏实体类
        Entity mCollectEntity = schema.addEntity("CollectEntity");//表名
        mCollectEntity.addIdProperty();//主键id
        Property htmlID =   mCollectEntity.addLongProperty("html_id").getProperty();//收藏的id
        mCollectEntity.addStringProperty("collect");//是否收藏
        mCollectEntity.addToOne(mHtmlEntity, htmlID);
    }
 
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: Generator.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
private static void createTodoSchema(Schema schema){
    Entity todo = schema.addEntity("Todo");
    Property id = todo.addIdProperty().getProperty();
    todo.addStringProperty("todo");
    todo.addDateProperty("addDate").notNull();
    todo.addDateProperty("endDate");
    todo.addIntProperty("status").notNull().unique();
}
 
Example #5
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/");
}
 
Example #6
Source File: Generator.java    From android-orm-benchmark with Apache License 2.0 4 votes vote down vote up
private static Property addCommonColumns(Entity entity) {
    entity.addStringProperty(LAST_NAME_COLUMN);
    entity.addStringProperty(FIRST_NAME_COLUMN);
    return entity.addIdProperty().autoincrement().getProperty();
}