Search in sources :

Example 1 with Database

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();
}
Also used : AbstractDaoMaster(org.greenrobot.greendao.AbstractDaoMaster) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Database(org.greenrobot.greendao.database.Database) StandardDatabase(org.greenrobot.greendao.database.StandardDatabase)

Example 2 with Database

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;
}
Also used : Database(org.greenrobot.greendao.database.Database) StandardDatabase(org.greenrobot.greendao.database.StandardDatabase) Cursor(android.database.Cursor) SQLiteQueryBuilder(android.database.sqlite.SQLiteQueryBuilder)

Example 3 with Database

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();
}
Also used : AbstractDaoMaster(org.greenrobot.greendao.AbstractDaoMaster) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Database(org.greenrobot.greendao.database.Database) StandardDatabase(org.greenrobot.greendao.database.StandardDatabase)

Example 4 with Database

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();
}
Also used : Database(org.greenrobot.greendao.database.Database) Before(org.junit.Before)

Example 5 with Database

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);
}
Also used : DatabaseStatement(org.greenrobot.greendao.database.DatabaseStatement) Database(org.greenrobot.greendao.database.Database)

Aggregations

Database (org.greenrobot.greendao.database.Database)21 StandardDatabase (org.greenrobot.greendao.database.StandardDatabase)10 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)9 AbstractDaoMaster (org.greenrobot.greendao.AbstractDaoMaster)9 DevOpenHelper (org.greenrobot.greendao.daotest.DaoMaster.DevOpenHelper)2 Cursor (android.database.Cursor)1 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)1 ArrayList (java.util.ArrayList)1 DaoException (org.greenrobot.greendao.DaoException)1 OpenHelper (org.greenrobot.greendao.daotest.DaoMaster.OpenHelper)1 DatabaseStatement (org.greenrobot.greendao.database.DatabaseStatement)1 DevOpenHelper (org.greenrobot.greendao.example.DaoMaster.DevOpenHelper)1 Before (org.junit.Before)1