当前位置: 首页>>代码示例>>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;未经允许,请勿转载。