本文整理汇总了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;
}
示例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.");
}
示例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;
}
示例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");
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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");
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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());
}
示例15: DaoMaster
import org.greenrobot.greendao.database.StandardDatabase; //导入依赖的package包/类
public DaoMaster(SQLiteDatabase db) {
this(new StandardDatabase(db));
}