org.greenrobot.greendao.database.StandardDatabase Java Examples

The following examples show how to use org.greenrobot.greendao.database.StandardDatabase. 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: MigrationHelper.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
private static List<String> getColumns(StandardDatabase db, String tableName) {
    List<String> columns = null;
    Cursor cursor = null;
    try {
        cursor = db.rawQuery("SELECT * FROM " + tableName + " limit 0", null);
        if (null != cursor && cursor.getColumnCount() > 0) {
            columns = Arrays.asList(cursor.getColumnNames());
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null)
            cursor.close();
        if (null == columns)
            columns = new ArrayList<>();
    }
    return columns;
}
 
Example #2
Source File: DaoMigrationHelper.java    From android-mvp-starter with MIT License 6 votes vote down vote up
public void migrate(SQLiteDatabase db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    Database database = new StandardDatabase(db);
    if (DEBUG) {
        Log.d(TAG, "【Database Version】" + db.getVersion());
        Log.d(TAG, "【Generate temp table】start");
    }
    generateTempTables(database, daoClasses);
    if (DEBUG) {
        Log.d(TAG, "【Generate temp table】complete");
    }
    dropAllTables(database, true, daoClasses);
    createAllTables(database, false, daoClasses);
    if (DEBUG) {
        Log.d(TAG, "【Restore data】start");
    }
    restoreData(database, daoClasses);
    if (DEBUG) {
        Log.d(TAG, "【Restore data】complete");
    }
}
 
Example #3
Source File: MigrationHelper.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
public static void migrate(SQLiteDatabase sqliteDatabase, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    StandardDatabase db = new StandardDatabase(sqliteDatabase);
    generateNewTablesIfNotExists(db, daoClasses);
    generateTempTables(db, daoClasses);
    dropAllTables(db, true, daoClasses);
    createAllTables(db, false, daoClasses);
    restoreData(db, daoClasses);
}
 
Example #4
Source File: MigrationHelper.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
public static void migrate(StandardDatabase db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    generateNewTablesIfNotExists(db, daoClasses);
    generateTempTables(db, daoClasses);
    dropAllTables(db, true, daoClasses);
    createAllTables(db, false, daoClasses);
    restoreData(db, daoClasses);
}
 
Example #5
Source File: GreenDaoExecutor.java    From android-orm-benchmark-updated with Apache License 2.0 5 votes vote down vote up
@Override
public long dropDb() throws SQLException {
    long start = System.nanoTime();
    final SQLiteDatabase sqliteDb = mHelper.getWritableDatabase();
    final StandardDatabase db = new StandardDatabase(sqliteDb);
    DaoMaster.dropAllTables(db, true);
    // Reset version, so OpenHelper does not get confused
    sqliteDb.setVersion(0);
    return System.nanoTime() - start;
}
 
Example #6
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 #7
Source File: GreenDaoExecutor.java    From android-orm-benchmark-updated with Apache License 2.0 5 votes vote down vote up
@Override
public long createDbStructure() throws SQLException {
    long start = System.nanoTime();
    final StandardDatabase db = new StandardDatabase(mHelper.getWritableDatabase());
    if (mDaoSession == null) {
        mDaoSession = new DaoMaster(db).newSession(USE_IDENTITY_SCOPE ?
                IdentityScopeType.Session : IdentityScopeType.None);
    } else {
        DaoMaster.createAllTables(db, true);
    }
    return System.nanoTime() - start;
}
 
Example #8
Source File: MigrationHelper.java    From FriendBook with GNU General Public License v3.0 5 votes vote down vote up
public static void migrate(SQLiteDatabase db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    Database database = new StandardDatabase(db);

    printLog("【The Old Database Version】" + db.getVersion());
    printLog("【Generate temp table】start");
    generateTempTables(database, daoClasses);
    printLog("【Generate temp table】complete");

    dropAllTables(database, true, daoClasses);
    createAllTables(database, false, daoClasses);

    printLog("【Restore data】start");
    restoreData(database, daoClasses);
    printLog("【Restore data】complete");
}
 
Example #9
Source File: MigrationHelper.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
private static void restoreData(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");
        // get all columns from tempTable, take careful to use the columns list
        List<String> columns = getColumns(db, tempTableName);
        ArrayList<String> properties = new ArrayList<>(columns.size());
        for (int j = 0; j < daoConfig.properties.length; j++) {
            String columnName = daoConfig.properties[j].columnName;
            if (columns.contains(columnName)) {
                properties.add(columnName);
            }
        }
        if (properties.size() > 0) {
            final String columnSQL = TextUtils.join(",", properties);

            StringBuilder insertTableStringBuilder = new StringBuilder();
            insertTableStringBuilder.append("INSERT INTO ").append(tableName).append(" (");
            insertTableStringBuilder.append(columnSQL);
            insertTableStringBuilder.append(") SELECT ");
            insertTableStringBuilder.append(columnSQL);
            insertTableStringBuilder.append(" FROM ").append(tempTableName).append(";");
            db.execSQL(insertTableStringBuilder.toString());
        }
        StringBuilder dropTableStringBuilder = new StringBuilder();
        dropTableStringBuilder.append("DROP TABLE ").append(tempTableName);
        db.execSQL(dropTableStringBuilder.toString());
    }
}
 
Example #10
Source File: DaoMaster.java    From Dictionary with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #11
Source File: DaoMaster.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #12
Source File: DaoMaster.java    From likequanmintv with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #13
Source File: DaoMaster.java    From Android-Architecture with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #14
Source File: MyMigrationHelper.java    From MiPushFramework with GNU General Public License v3.0 4 votes vote down vote up
public static void migrate(SQLiteDatabase db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    printLog("【The Old Database Version】" + db.getVersion());
    Database database = new StandardDatabase(db);
    migrate(database, daoClasses);
}
 
Example #15
Source File: DaoMaster.java    From Ency with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #16
Source File: DaoMaster.java    From KUtils-master with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #17
Source File: DaoMaster.java    From Android-IM with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #18
Source File: DaoMaster.java    From OpenHub with GNU General Public License v3.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #19
Source File: DaoMaster.java    From CoolChat with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #20
Source File: DaoMaster.java    From ml-authentication with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #21
Source File: DaoMaster.java    From GreenDAO3_Demo with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #22
Source File: DaoMaster.java    From GreenDaoSample with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #23
Source File: DaoMaster.java    From KUtils with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #24
Source File: DaoMaster.java    From easyweather with MIT License 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #25
Source File: MigrationHelper2.java    From HHComicViewer with Apache License 2.0 4 votes vote down vote up
public static void migrate(SQLiteDatabase db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    printLog("【The Old Database Version】" + db.getVersion());
    Database database = new StandardDatabase(db);
    migrate(database, daoClasses);
}
 
Example #26
Source File: DaoMaster.java    From android-orm-benchmark-updated with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #27
Source File: DaoMaster.java    From ml-authentication with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #28
Source File: DaoMaster.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #29
Source File: DaoMaster.java    From SoloPi with Apache License 2.0 4 votes vote down vote up
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
Example #30
Source File: MigrationHelper.java    From DevUtils with Apache License 2.0 4 votes vote down vote up
private static void generateNewTablesIfNotExists(StandardDatabase db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    reflectMethod(db, "createTable", true, daoClasses);
}