當前位置: 首頁>>代碼示例>>Java>>正文


Java StandardDatabase類代碼示例

本文整理匯總了Java中org.greenrobot.greendao.database.StandardDatabase的典型用法代碼示例。如果您正苦於以下問題:Java StandardDatabase類的具體用法?Java StandardDatabase怎麽用?Java StandardDatabase使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StandardDatabase類屬於org.greenrobot.greendao.database包,在下文中一共展示了StandardDatabase類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: query

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
@Override
public Cursor query(Uri uri, String[] projection, String selection,
        String[] selectionArgs, String sortOrder) {

    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    int uriType = sURIMatcher.match(uri);
    switch (uriType) {
    case SIMPLEENTITY_DIR:
        queryBuilder.setTables(TABLENAME);
        break;
    case SIMPLEENTITY_ID:
        queryBuilder.setTables(TABLENAME);
        queryBuilder.appendWhere(PK + "="
                + uri.getLastPathSegment());
        break;
    default:
        throw new IllegalArgumentException("Unknown URI: " + uri);
    }

    Database db = getDatabase();
    Cursor cursor = queryBuilder.query(((StandardDatabase) db).getSQLiteDatabase(), projection, selection,
            selectionArgs, null, null, sortOrder);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);

    return cursor;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:SimpleEntityContentProvider.java

示例2: migrate

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
/**
 * 數據遷移
 *
 * @param db
 * @param daoClasses
 */
public void migrate(SQLiteDatabase db, Class<? extends AbstractDao<?, ?>>... daoClasses) {
    Database database = new StandardDatabase(db);

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

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

    logger.log("Restore data start.");
    restoreData(database, daoClasses);
    logger.log("Restore data complete.");
}
 
開發者ID:RockyQu,項目名稱:MVVMFrames,代碼行數:22,代碼來源:MigrationHelper.java

示例3: getColumns

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
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;
}
 
開發者ID:cyrilpillai,項目名稱:GreenDao-Migrator,代碼行數:19,代碼來源:MigrationHelper.java

示例4: migrate

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
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");
    }
}
 
開發者ID:dtunctuncer,項目名稱:android-mvp-starter,代碼行數:21,代碼來源:DaoMigrationHelper.java

示例5: createDatabase

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
/** May be overriden by sub classes to set up a different db. */
protected Database createDatabase() {
    SQLiteDatabase sqLiteDatabase;
    if (inMemory) {
        sqLiteDatabase = SQLiteDatabase.create(null);

    } else {
        getContext().deleteDatabase(DB_NAME);
        sqLiteDatabase = getContext().openOrCreateDatabase(DB_NAME, 0, null);
    }
    return new StandardDatabase(sqLiteDatabase);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:DbTest.java

示例6: logTableDump

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
protected void logTableDump(String tablename) {
    if (db instanceof StandardDatabase) {
        DbUtils.logTableDump(((StandardDatabase) db).getSQLiteDatabase(), tablename);
    } else {
        DaoLog.w("Table dump unsupported for " + db);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:DbTest.java

示例7: createDatabase

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
@Override
protected Database createDatabase() {
    int MODE_ENABLE_WRITE_AHEAD_LOGGING = 8;
    getContext().deleteDatabase(DB_NAME);
    SQLiteDatabase sqLiteDatabase = getContext().openOrCreateDatabase(DB_NAME, MODE_ENABLE_WRITE_AHEAD_LOGGING, null);
    return new StandardDatabase(sqLiteDatabase);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:DaoSessionConcurrentWALTest.java

示例8: migrate

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
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");
}
 
開發者ID:z-chu,項目名稱:FriendBook,代碼行數:16,代碼來源:MigrationHelper.java

示例9: migrate

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
public static void migrate(SQLiteDatabase sqliteDatabase, List<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);
}
 
開發者ID:cyrilpillai,項目名稱:GreenDao-Migrator,代碼行數:9,代碼來源:MigrationHelper.java

示例10: generateTempTables

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
private static void generateTempTables(StandardDatabase db, List<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");
        String insertTableStringBuilder = "CREATE TEMP TABLE " + tempTableName +
                " AS SELECT * FROM " + tableName + ";";
        db.execSQL(insertTableStringBuilder);
    }
}
 
開發者ID:cyrilpillai,項目名稱:GreenDao-Migrator,代碼行數:11,代碼來源:MigrationHelper.java

示例11: restoreData

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
private static void restoreData(StandardDatabase db, List<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");
        // 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);

            String insertTableStringBuilder = "INSERT INTO " + tableName + " (" +
                    columnSQL +
                    ") SELECT " +
                    columnSQL +
                    " FROM " + tempTableName + ";";
            try {
                db.execSQL(insertTableStringBuilder);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        db.execSQL("DROP TABLE " + tempTableName);
    }
}
 
開發者ID:cyrilpillai,項目名稱:GreenDao-Migrator,代碼行數:32,代碼來源:MigrationHelper.java

示例12: createDbStructure

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
@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;
}
 
開發者ID:touchlab,項目名稱:android-orm-benchmark-updated,代碼行數:13,代碼來源:GreenDaoExecutor.java

示例13: dropDb

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
@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;
}
 
開發者ID:touchlab,項目名稱:android-orm-benchmark-updated,代碼行數:11,代碼來源:GreenDaoExecutor.java

示例14: setUp

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
@Override
protected void setUp() throws Exception {
    super.setUp();
    QueryBuilder.LOG_SQL = true;
    QueryBuilder.LOG_VALUES = true;
    Triggers.create(((StandardDatabase) db).getSQLiteDatabase());
}
 
開發者ID:sewerk,項目名稱:Bill-Calculator,代碼行數:8,代碼來源:TriggersTest.java

示例15: DaoMaster

import org.greenrobot.greendao.database.StandardDatabase; //導入依賴的package包/類
public DaoMaster(SQLiteDatabase db) {
    this(new StandardDatabase(db));
}
 
開發者ID:popo1379,項目名稱:popomusic,代碼行數:4,代碼來源:DaoMaster.java


注:本文中的org.greenrobot.greendao.database.StandardDatabase類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。