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);
}
Aggregations