use of org.greenrobot.greendao.database.Database in project greenDAO by greenrobot.
the class DaoMaster method newDevSession.
/**
* WARNING: Drops all table on Upgrade! Use only during development.
* Convenience method using a {@link DevOpenHelper}.
*/
public static DaoSession newDevSession(Context context, String name) {
Database db = new DevOpenHelper(context, name).getWritableDb();
DaoMaster daoMaster = new DaoMaster(db);
return daoMaster.newSession();
}
use of org.greenrobot.greendao.database.Database in project greenDAO by greenrobot.
the class SimpleEntityContentProvider method query.
@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;
}
use of org.greenrobot.greendao.database.Database in project greenDAO by greenrobot.
the class DaoMaster method newDevSession.
/**
* WARNING: Drops all table on Upgrade! Use only during development.
* Convenience method using a {@link DevOpenHelper}.
*/
public static DaoSession newDevSession(Context context, String name) {
Database db = new DevOpenHelper(context, name).getWritableDb();
DaoMaster daoMaster = new DaoMaster(db);
return daoMaster.newSession();
}
use of org.greenrobot.greendao.database.Database in project greenDAO by greenrobot.
the class MinimalEntityTest method setUp.
@Before
public void setUp() {
DaoMaster.DevOpenHelper openHelper = new DaoMaster.DevOpenHelper(RuntimeEnvironment.application, null);
Database db = openHelper.getWritableDb();
daoSession = new DaoMaster(db).newSession();
minimalEntityDao = daoSession.getMinimalEntityDao();
}
use of org.greenrobot.greendao.database.Database in project greenDAO by greenrobot.
the class DaoSessionConcurrentTest method _testThreadLocalSpeed.
/**
* We could put the statements inside ThreadLocals (fast enough), but it comes with initialization penalty for new
* threads and costs more memory.
*/
public void _testThreadLocalSpeed() {
final Database db = dao.getDatabase();
ThreadLocal<DatabaseStatement> threadLocal = new ThreadLocal<DatabaseStatement>() {
@Override
protected DatabaseStatement initialValue() {
return db.compileStatement("SELECT 42");
}
};
threadLocal.get();
long start = SystemClock.currentThreadTimeMillis();
for (int i = 0; i < 1000; i++) {
DatabaseStatement sqLiteStatement = threadLocal.get();
assertNotNull(sqLiteStatement);
}
Long time = SystemClock.currentThreadTimeMillis() - start;
DaoLog.d("TIME: " + time + "ms");
// Around 1ms on a S3
assertTrue(time < 10);
}
Aggregations