本文整理匯總了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));
}