Search in sources :

Example 1 with StandardDatabase

use of org.greenrobot.greendao.database.StandardDatabase 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 2 with StandardDatabase

use of org.greenrobot.greendao.database.StandardDatabase in project greenDAO by greenrobot.

the class DbTest method createDatabase.

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

Example 3 with StandardDatabase

use of org.greenrobot.greendao.database.StandardDatabase in project greenDAO by greenrobot.

the class DaoSessionConcurrentWALTest method createDatabase.

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

Aggregations

StandardDatabase (org.greenrobot.greendao.database.StandardDatabase)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 Cursor (android.database.Cursor)1 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)1 Database (org.greenrobot.greendao.database.Database)1