Search in sources :

Example 1 with ProjectionObject

use of com.dailystudio.dataobject.samples.ProjectionObject in project devbricks by dailystudio.

the class DatabaseConnectivityProviderTest method testQueryWithProjectionClass.

public void testQueryWithProjectionClass() {
    ContentResolver cr = mTargetContext.getContentResolver();
    assertNotNull(cr);
    final int count = 10;
    ContentValues[] values = new ContentValues[count];
    assertNotNull(values);
    DatabaseObject object = null;
    for (int i = 0; i < count; i++) {
        object = DatabaseObjectFactory.createDatabaseObject(QueryObject.class);
        assertNotNull(object);
        object.setValue("intValue", i);
        object.setValue("doubleValue", ((double) i * 2));
        object.setValue("textValue", String.format("%04d", i * 3));
        values[i] = object.getValues();
    }
    final Template tmpl = object.getTemplate();
    long serial = 0;
    Uri queryUri = null;
    serial = System.currentTimeMillis();
    queryUri = ProviderUriBuilder.buildQueryUri(AUTHORITY, QueryObject.class, serial);
    assertNotNull(queryUri);
    queryUri = ProviderUriBuilder.attachCreateTableParamter(queryUri, object.toSQLTableCreationString());
    assertNotNull(queryUri);
    cr.bulkInsert(queryUri, values);
    Column col = tmpl.getColumn("intValue");
    ExpressionToken selection = col.gt(5).and(col.lt(9));
    assertNotNull(selection);
    DatabaseObject projectionObject = new ProjectionObject(mContext);
    assertNotNull(projectionObject);
    Cursor c = null;
    serial = System.currentTimeMillis();
    queryUri = ProviderUriBuilder.buildQueryUri(AUTHORITY, QueryObject.class, serial);
    assertNotNull(queryUri);
    c = cr.query(queryUri, projectionObject.toSQLProjection(), selection.toString(), null, null);
    assertNotNull(c);
    assertEquals(1, c.getCount());
    assertEquals(true, c.moveToFirst());
    int columnIndex = -1;
    columnIndex = c.getColumnIndex(ProjectionObject.COLUMN_ID_COUNT.getName());
    assertEquals(3, c.getInt(columnIndex));
    c.close();
    cr.delete(queryUri, null, null);
}
Also used : ContentValues(android.content.ContentValues) ProjectionObject(com.dailystudio.dataobject.samples.ProjectionObject) Cursor(android.database.Cursor) QueryObject(com.dailystudio.dataobject.samples.QueryObject) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) Template(com.dailystudio.dataobject.Template) Column(com.dailystudio.dataobject.Column) ExpressionToken(com.dailystudio.dataobject.query.ExpressionToken) DatabaseObject(com.dailystudio.dataobject.DatabaseObject)

Aggregations

ContentResolver (android.content.ContentResolver)1 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 Column (com.dailystudio.dataobject.Column)1 DatabaseObject (com.dailystudio.dataobject.DatabaseObject)1 Template (com.dailystudio.dataobject.Template)1 ExpressionToken (com.dailystudio.dataobject.query.ExpressionToken)1 ProjectionObject (com.dailystudio.dataobject.samples.ProjectionObject)1 QueryObject (com.dailystudio.dataobject.samples.QueryObject)1