org.greenrobot.greendao.internal.DaoConfig Java Examples

The following examples show how to use org.greenrobot.greendao.internal.DaoConfig. 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: DaoSession.java    From Android-IM with Apache License 2.0 6 votes vote down vote up
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
        daoConfigMap) {
    super(db);

    userDaoConfig = daoConfigMap.get(UserDao.class).clone();
    userDaoConfig.initIdentityScope(type);

    searchAddDaoConfig = daoConfigMap.get(SearchAddDao.class).clone();
    searchAddDaoConfig.initIdentityScope(type);

    requestListDaoConfig = daoConfigMap.get(RequestListDao.class).clone();
    requestListDaoConfig.initIdentityScope(type);

    chatLogDaoConfig = daoConfigMap.get(ChatLogDao.class).clone();
    chatLogDaoConfig.initIdentityScope(type);

    userDao = new UserDao(userDaoConfig, this);
    searchAddDao = new SearchAddDao(searchAddDaoConfig, this);
    requestListDao = new RequestListDao(requestListDaoConfig, this);
    chatLogDao = new ChatLogDao(chatLogDaoConfig, this);

    registerDao(User.class, userDao);
    registerDao(SearchAdd.class, searchAddDao);
    registerDao(RequestList.class, requestListDao);
    registerDao(ChatLog.class, chatLogDao);
}
 
Example #2
Source File: DaoSession.java    From enjoyshop with Apache License 2.0 6 votes vote down vote up
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
        daoConfigMap) {
    super(db);

    addressDaoConfig = daoConfigMap.get(AddressDao.class).clone();
    addressDaoConfig.initIdentityScope(type);

    userDaoConfig = daoConfigMap.get(UserDao.class).clone();
    userDaoConfig.initIdentityScope(type);

    addressDao = new AddressDao(addressDaoConfig, this);
    userDao = new UserDao(userDaoConfig, this);

    registerDao(Address.class, addressDao);
    registerDao(User.class, userDao);
}
 
Example #3
Source File: DaoSession.java    From KUtils-master with Apache License 2.0 6 votes vote down vote up
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
        daoConfigMap) {
    super(db);

    isFirstEnterAppDaoConfig = daoConfigMap.get(IsFirstEnterAppDao.class).clone();
    isFirstEnterAppDaoConfig.initIdentityScope(type);

    userDaoConfig = daoConfigMap.get(UserDao.class).clone();
    userDaoConfig.initIdentityScope(type);

    isFirstEnterAppDao = new IsFirstEnterAppDao(isFirstEnterAppDaoConfig, this);
    userDao = new UserDao(userDaoConfig, this);

    registerDao(IsFirstEnterApp.class, isFirstEnterAppDao);
    registerDao(User.class, userDao);
}
 
Example #4
Source File: DaoSession.java    From ClassSchedule with Apache License 2.0 6 votes vote down vote up
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
        daoConfigMap) {
    super(db);

    courseGroupDaoConfig = daoConfigMap.get(CourseGroupDao.class).clone();
    courseGroupDaoConfig.initIdentityScope(type);

    courseV2DaoConfig = daoConfigMap.get(CourseV2Dao.class).clone();
    courseV2DaoConfig.initIdentityScope(type);

    courseGroupDao = new CourseGroupDao(courseGroupDaoConfig, this);
    courseV2Dao = new CourseV2Dao(courseV2DaoConfig, this);

    registerDao(CourseGroup.class, courseGroupDao);
    registerDao(CourseV2.class, courseV2Dao);
}
 
Example #5
Source File: DaoSession.java    From MissZzzReader with Apache License 2.0 6 votes vote down vote up
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
        daoConfigMap) {
    super(db);

    bookDaoConfig = daoConfigMap.get(BookDao.class).clone();
    bookDaoConfig.initIdentityScope(type);

    chapterDaoConfig = daoConfigMap.get(ChapterDao.class).clone();
    chapterDaoConfig.initIdentityScope(type);

    searchHistoryDaoConfig = daoConfigMap.get(SearchHistoryDao.class).clone();
    searchHistoryDaoConfig.initIdentityScope(type);

    bookDao = new BookDao(bookDaoConfig, this);
    chapterDao = new ChapterDao(chapterDaoConfig, this);
    searchHistoryDao = new SearchHistoryDao(searchHistoryDaoConfig, this);

    registerDao(Book.class, bookDao);
    registerDao(Chapter.class, chapterDao);
    registerDao(SearchHistory.class, searchHistoryDao);
}
 
Example #6
Source File: MigrationHelper.java    From FimiX8-RE with MIT License 6 votes vote down vote up
private void restoreData(Database db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    for (Class daoConfig : daoClasses) {
        DaoConfig daoConfig2 = new DaoConfig(db, daoConfig);
        String tableName = daoConfig2.tablename;
        String tempTableName = daoConfig2.tablename.concat("_TEMP");
        ArrayList<String> properties = new ArrayList();
        for (Property property : daoConfig2.properties) {
            String columnName = property.columnName;
            if (getColumns(db, tempTableName).contains(columnName)) {
                properties.add(columnName);
            }
        }
        StringBuilder insertTableStringBuilder = new StringBuilder();
        insertTableStringBuilder.append("INSERT INTO ").append(tableName).append(" (");
        insertTableStringBuilder.append(TextUtils.join(",", properties));
        insertTableStringBuilder.append(") SELECT ");
        insertTableStringBuilder.append(TextUtils.join(",", properties));
        insertTableStringBuilder.append(" FROM ").append(tempTableName).append(";");
        StringBuilder dropTableStringBuilder = new StringBuilder();
        dropTableStringBuilder.append("DROP TABLE ").append(tempTableName);
        db.execSQL(insertTableStringBuilder.toString());
        db.execSQL(dropTableStringBuilder.toString());
    }
}
 
Example #7
Source File: DaoSession.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
        daoConfigMap) {
    super(db);

    userBeanDaoConfig = daoConfigMap.get(UserBeanDao.class).clone();
    userBeanDaoConfig.initIdentityScope(type);

    userBeanDao = new UserBeanDao(userBeanDaoConfig, this);

    registerDao(UserBean.class, userBeanDao);
}
 
Example #8
Source File: DaoSession.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
        daoConfigMap) {
    super(db);

    noteEntityDaoConfig = daoConfigMap.get(NoteEntityDao.class).clone();
    noteEntityDaoConfig.initIdentityScope(type);

    noteEntityDao = new NoteEntityDao(noteEntityDaoConfig, this);

    registerDao(NoteEntity.class, noteEntityDao);
}
 
Example #9
Source File: MigrationHelper.java    From FriendBook with GNU General Public License v3.0 5 votes vote down vote up
private static void generateTempTables(Database db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    for (int i = 0; i < daoClasses.length; i++) {
        String tempTableName = null;

        DaoConfig daoConfig = new DaoConfig(db, daoClasses[i]);
        String tableName = daoConfig.tablename;
        if (!isTableExists(db, false, tableName)) {
            printLog("【New Table】" + tableName);
            continue;
        }
        try {
            tempTableName = daoConfig.tablename.concat("_TEMP");
            StringBuilder dropTableStringBuilder = new StringBuilder();
            dropTableStringBuilder.append("DROP TABLE IF EXISTS ").append(tempTableName).append(";");
            db.execSQL(dropTableStringBuilder.toString());

            StringBuilder insertTableStringBuilder = new StringBuilder();
            insertTableStringBuilder.append("CREATE TEMPORARY TABLE ").append(tempTableName);
            insertTableStringBuilder.append(" AS SELECT * FROM ").append(tableName).append(";");
            db.execSQL(insertTableStringBuilder.toString());
            printLog("【Table】" + tableName +"\n ---Columns-->"+getColumnsStr(daoConfig));
            printLog("【Generate temp table】" + tempTableName);
        } catch (SQLException e) {
            Log.e(TAG, "【Failed to generate temp table】" + tempTableName, e);
        }
    }
}
 
Example #10
Source File: MigrationHelper.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
private static void generateTempTables(StandardDatabase db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    for (int i = 0; i < daoClasses.length; i++) {
        DaoConfig daoConfig = new DaoConfig(db, daoClasses[i]);
        String tableName = daoConfig.tablename;
        String tempTableName = daoConfig.tablename.concat("_TEMP");
        StringBuilder insertTableStringBuilder = new StringBuilder();
        insertTableStringBuilder.append("CREATE TEMP TABLE ").append(tempTableName);
        insertTableStringBuilder.append(" AS SELECT * FROM ").append(tableName).append(";");
        db.execSQL(insertTableStringBuilder.toString());
    }
}
 
Example #11
Source File: MyMigrationHelper.java    From MiPushFramework with GNU General Public License v3.0 5 votes vote down vote up
private static void generateTempTables(Database db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    for (int i = 0; i < daoClasses.length; i++) {
        String tempTableName = null;

        DaoConfig daoConfig = new DaoConfig(db, daoClasses[i]);
        String tableName = daoConfig.tablename;
        if (!isTableExists(db, false, tableName)) {
            printLog("【New Table】" + tableName);
            continue;
        }
        try {
            tempTableName = daoConfig.tablename.concat("_TEMP");
            StringBuilder dropTableStringBuilder = new StringBuilder();
            dropTableStringBuilder.append("DROP TABLE IF EXISTS ").append(tempTableName).append(";");
            db.execSQL(dropTableStringBuilder.toString());

            StringBuilder insertTableStringBuilder = new StringBuilder();
            insertTableStringBuilder.append("CREATE TEMPORARY TABLE ").append(tempTableName);
            insertTableStringBuilder.append(" AS SELECT * FROM ").append(tableName).append(";");
            db.execSQL(insertTableStringBuilder.toString());
            printLog("【Table】" + tableName +"\n ---Columns-->"+getColumnsStr(daoConfig));
            printLog("【Generate temp table】" + tempTableName);
        } catch (SQLException e) {
            Log.e(TAG, "【Failed to generate temp table】" + tempTableName, e);
        }
    }
}
 
Example #12
Source File: GreenDaoUpgrade.java    From MissZzzReader with Apache License 2.0 5 votes vote down vote up
@SafeVarargs
private final void restoreData(Database db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    for (Class<? extends AbstractDao<?, ?>> daoClass : daoClasses) {
        DaoConfig daoConfig = new DaoConfig(db, daoClass);

        String tableName = daoConfig.tablename;
        String tempTableName = daoConfig.tablename.concat("_TEMP");
        ArrayList<String> properties = new ArrayList<>();
        ArrayList<String> propertiesQuery = new ArrayList<>();
        for (int j = 0; j < daoConfig.properties.length; j++) {
            String columnName = daoConfig.properties[j].columnName;

            if (getColumns(db, tempTableName).contains(columnName)) {
                properties.add(columnName);
                propertiesQuery.add(columnName);
            } else {
                try {
                    if (getTypeByClass(daoConfig.properties[j].type).equals("INTEGER")) {
                        propertiesQuery.add("0 as " + columnName);
                        properties.add(columnName);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        String insertTableStringBuilder = "INSERT INTO " + tableName + " (" +
                TextUtils.join(",", properties) +
                ") SELECT " +
                TextUtils.join(",", propertiesQuery) +
                " FROM " + tempTableName + ";";
        db.execSQL(insertTableStringBuilder);
        db.execSQL("DROP TABLE " + tempTableName);
    }
}
 
Example #13
Source File: DaoSession.java    From frpc-Android with Apache License 2.0 5 votes vote down vote up
public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
        daoConfigMap) {
    super(db);

    suiDaoDaoConfig = daoConfigMap.get(SuiDaoDao.class).clone();
    suiDaoDaoConfig.initIdentityScope(type);

    suiDaoDao = new SuiDaoDao(suiDaoDaoConfig, this);

    registerDao(SuiDao.class, suiDaoDao);
}
 
Example #14
Source File: Update2Helper.java    From NovelReader with MIT License 5 votes vote down vote up
private void updateCollBook(Database db) {
    Class<? extends AbstractDao<?, ?>> collBookClass = CollBookBeanDao.class;

    // 遍历查找本地文件,然后修改本地文件的数据
    DaoConfig daoConfig = new DaoConfig(db, collBookClass);
    String tableName = daoConfig.tablename;

    Cursor cursor = db.rawQuery("select _ID,IS_LOCAL from " + tableName, null);
    String id = null;
    String cover = null;
    String isLocal = null;

    StringBuilder updateSb = new StringBuilder();
    while (cursor.moveToNext()) {
        cover = cursor.getString(0);
        id = MD5Utils.strToMd5By16(cover);
        isLocal = cursor.getString(1);

        //如果是本地文件
        if (isLocal.equals("1")) {
            // 数据更新
            updateSb.append("UPDATE " + tableName + " SET ");
            updateSb.append("_ID=").append(String.format(QUOTE, id)).append(DIVIDER);
            updateSb.append("COVER=").append(String.format(QUOTE, cover)).append(" ");
            updateSb.append("WHERE _ID=").append(String.format(QUOTE,cover)).append(";");

            db.execSQL(updateSb.toString());
            updateSb.delete(0, updateSb.length());
        }
    }
}
 
Example #15
Source File: MigrationHelper.java    From NovelReader with MIT License 5 votes vote down vote up
/**
 * 存储新的数据库表 以及数据
 *
 * @param db
 * @param daoClasses
 */
private void restoreData(Database db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    for (int i = 0; i < daoClasses.length; i++) {
        DaoConfig daoConfig = new DaoConfig(db, daoClasses[i]);
        String tableName = daoConfig.tablename;
        String tempTableName = daoConfig.tablename.concat("_TEMP");
        ArrayList<String> properties = new ArrayList();

        for (int j = 0; j < daoConfig.properties.length; j++) {
            String columnName = daoConfig.properties[j].columnName;

            if (getColumns(db, tempTableName).contains(columnName)) {
                properties.add(columnName);
            }
        }

        StringBuilder insertTableStringBuilder = new StringBuilder();

        insertTableStringBuilder.append("INSERT INTO ").append(tableName).append(" (");
        insertTableStringBuilder.append(TextUtils.join(",", properties));
        insertTableStringBuilder.append(") SELECT ");
        insertTableStringBuilder.append(TextUtils.join(",", properties));
        insertTableStringBuilder.append(" FROM ").append(tempTableName).append(";");

        StringBuilder dropTableStringBuilder = new StringBuilder();
        dropTableStringBuilder.append("DROP TABLE ").append(tempTableName);
        db.execSQL(insertTableStringBuilder.toString());
        db.execSQL(dropTableStringBuilder.toString());
    }
}
 
Example #16
Source File: MigrationHelper.java    From Android with MIT License 5 votes vote down vote up
private static void generateTempTables(Database db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    for (int i = 0; i < daoClasses.length; i++) {
        String tempTableName = null;

        DaoConfig daoConfig = new DaoConfig(db, daoClasses[i]);
        String tableName = daoConfig.tablename;
        if (!isTableExists(db, false, tableName)) {
            LogManager.getLogger().d(TAG, "[New Table]" + tableName);
            continue;
        }
        try {
            tempTableName = daoConfig.tablename.concat("_TEMP");
            StringBuilder dropTableStringBuilder = new StringBuilder();
            dropTableStringBuilder.append("DROP TABLE IF EXISTS ").append(tempTableName).append(";");
            db.execSQL(dropTableStringBuilder.toString());

            StringBuilder insertTableStringBuilder = new StringBuilder();
            insertTableStringBuilder.append("CREATE TEMPORARY TABLE ").append(tempTableName);
            insertTableStringBuilder.append(" AS SELECT * FROM ").append(tableName).append(";");
            db.execSQL(insertTableStringBuilder.toString());
            LogManager.getLogger().d(TAG,"[Table]" + tableName +"\n ---Columns-->"+getColumnsStr(daoConfig));
            LogManager.getLogger().d(TAG,"[Generate temp table]" + tempTableName);
        } catch (SQLException e) {
            Log.e(TAG, "[Failed to generate temp table]" + tempTableName, e);
        }
    }
}
 
Example #17
Source File: UserDao.java    From KUtils with Apache License 2.0 4 votes vote down vote up
public UserDao(DaoConfig config) {
    super(config);
}
 
Example #18
Source File: BookInfoBeanDao.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
public BookInfoBeanDao(DaoConfig config) {
    super(config);
}
 
Example #19
Source File: MigrationHelper.java    From Android-Architecture with Apache License 2.0 4 votes vote down vote up
@SafeVarargs
private final void generateTempTables(Database db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    for (Class<? extends AbstractDao<?, ?>> daoClass : daoClasses) {
        DaoConfig daoConfig = new DaoConfig(db, daoClass);

        String divider = "";
        String tableName = daoConfig.tablename;
        String tempTableName = daoConfig.tablename.concat("_TEMP");
        ArrayList<String> properties = new ArrayList<>();

        StringBuilder createTableStringBuilder = new StringBuilder();

        createTableStringBuilder.append("CREATE TABLE ").append(tempTableName).append(" (");

        for (int j = 0; j < daoConfig.properties.length; j++) {
            String columnName = daoConfig.properties[j].columnName;

            if (getColumns(db, tableName).contains(columnName)) {
                properties.add(columnName);

                String type = null;

                try {
                    type = getTypeByClass(daoConfig.properties[j].type);
                } catch (Exception exception) {
                    //                        Crashlytics.logException(exception);
                }

                createTableStringBuilder.append(divider).append(columnName).append(" ").append(type);

                if (daoConfig.properties[j].primaryKey) {
                    createTableStringBuilder.append(" PRIMARY KEY");
                }

                divider = ",";
            }
        }
        createTableStringBuilder.append(");");

        db.execSQL(createTableStringBuilder.toString());

        StringBuilder insertTableStringBuilder = new StringBuilder();

        insertTableStringBuilder.append("INSERT INTO ").append(tempTableName).append(" (");
        insertTableStringBuilder.append(TextUtils.join(",", properties));
        insertTableStringBuilder.append(") SELECT ");
        insertTableStringBuilder.append(TextUtils.join(",", properties));
        insertTableStringBuilder.append(" FROM ").append(tableName).append(";");

        db.execSQL(insertTableStringBuilder.toString());
    }
}
 
Example #20
Source File: CookieBeanDao.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
public CookieBeanDao(DaoConfig config, DaoSession daoSession) {
    super(config, daoSession);
}
 
Example #21
Source File: ParamEntityDao.java    From Android with MIT License 4 votes vote down vote up
public ParamEntityDao(DaoConfig config) {
    super(config);
}
 
Example #22
Source File: TraceDao.java    From OpenHub with GNU General Public License v3.0 4 votes vote down vote up
public TraceDao(DaoConfig config) {
    super(config);
}
 
Example #23
Source File: SearchHistoryDao.java    From MissZzzReader with Apache License 2.0 4 votes vote down vote up
public SearchHistoryDao(DaoConfig config, DaoSession daoSession) {
    super(config, daoSession);
}
 
Example #24
Source File: SearchHistoryBeanDao.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
public SearchHistoryBeanDao(DaoConfig config, DaoSession daoSession) {
    super(config, daoSession);
}
 
Example #25
Source File: ChapterBeanDao.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
public ChapterBeanDao(DaoConfig config) {
    super(config);
}
 
Example #26
Source File: AddressDao.java    From enjoyshop with Apache License 2.0 4 votes vote down vote up
public AddressDao(DaoConfig config) {
    super(config);
}
 
Example #27
Source File: ChapterBeanDao.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
public ChapterBeanDao(DaoConfig config, DaoSession daoSession) {
    super(config, daoSession);
}
 
Example #28
Source File: NoteEntityDao.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
public NoteEntityDao(DaoConfig config) {
    super(config);
}
 
Example #29
Source File: RequestListDao.java    From Android-IM with Apache License 2.0 4 votes vote down vote up
public RequestListDao(DaoConfig config) {
    super(config);
}
 
Example #30
Source File: CourseGroupDao.java    From ClassSchedule with Apache License 2.0 4 votes vote down vote up
public CourseGroupDao(DaoConfig config) {
    super(config);
}