use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class DatabaseConnectivityDirectSQLImplTest method testSimpleQuery.
public void testSimpleQuery() {
final int count = 10;
DatabaseObject object = null;
DatabaseObject[] objects = new DatabaseObject[count];
assertNotNull(objects);
for (int i = 0; i < 10; 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));
objects[i] = object;
}
AbsDatabaseConnectivity connectivity = new DatabaseConnectivityDirectSQLiteImpl(mTargetContext, QueryObject.class);
assertNotNull(connectivity);
connectivity.insert(objects);
final Template templ = object.getTemplate();
Column col = templ.getColumn("intValue");
Query query = new Query(QueryObject.class);
assertNotNull(query);
ExpressionToken selToken = col.gt(5).and(col.lt(9));
query.setSelection(selToken);
List<DatabaseObject> results = connectivity.query(query);
assertNotNull(results);
assertEquals(3, results.size());
DatabaseObject resultObject = null;
for (int i = 6; i <= 8; i++) {
resultObject = results.get(i - 6);
assertNotNull(resultObject);
Logger.debug("resultObject(%s)", resultObject.toSQLSelectionString());
Integer iVal = resultObject.getIntegerValue("intValue");
assertNotNull(iVal);
assertEquals(i, iVal.intValue());
Double dVal = resultObject.getDoubleValue("doubleValue");
assertNotNull(dVal);
assertEquals(((double) i * 2), dVal.doubleValue());
String sVal = resultObject.getTextValue("textValue");
assertNotNull(sVal);
assertEquals(String.format("%04d", i * 3), sVal);
}
connectivity.delete(new Query(QueryObject.class));
}
use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class DatabaseConnectivityTest method testQueryWithOrderBy.
public void testQueryWithOrderBy() {
final int count = (3 * 10);
DatabaseObject object = null;
DatabaseObject[] objects = new DatabaseObject[count];
assertNotNull(objects);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 10; j++) {
object = DatabaseObjectFactory.createDatabaseObject(QueryObject.class);
assertNotNull(object);
object.setValue("intValue", j);
object.setValue("doubleValue", ((double) j * 2));
object.setValue("textValue", String.format("%04d", j * 3));
objects[i * 10 + j] = object;
}
}
AbsDatabaseConnectivity connectivity = new DatabaseConnectivity(mTargetContext, AUTHORITY, QueryObject.class);
assertNotNull(connectivity);
connectivity.insert(objects);
final Template templ = object.getTemplate();
Column col = templ.getColumn("intValue");
Query query = null;
List<DatabaseObject> results = null;
OrderingToken orderByToken = null;
DatabaseObject resultObject = null;
query = new Query(QueryObject.class);
assertNotNull(query);
orderByToken = col.orderByAscending();
query.setOrderBy(orderByToken);
results = connectivity.query(query);
assertNotNull(results);
assertEquals(30, results.size());
for (int j = 0; j < 10; j++) {
for (int i = 0; i < 3; i++) {
resultObject = results.get(j * 3 + i);
assertNotNull(resultObject);
Logger.debug("resultObject(%s)", resultObject.toSQLSelectionString());
Integer iVal = resultObject.getIntegerValue("intValue");
assertNotNull(iVal);
assertEquals(j, iVal.intValue());
Double dVal = resultObject.getDoubleValue("doubleValue");
assertNotNull(dVal);
assertEquals(((double) j * 2), dVal.doubleValue());
String sVal = resultObject.getTextValue("textValue");
assertNotNull(sVal);
assertEquals(String.format("%04d", j * 3), sVal);
}
}
query = new Query(QueryObject.class);
assertNotNull(query);
orderByToken = col.orderByDescending();
query.setOrderBy(orderByToken);
results = connectivity.query(query);
assertNotNull(results);
assertEquals(30, results.size());
for (int j = 9; j >= 0; j--) {
for (int i = 0; i < 3; i++) {
resultObject = results.get((9 - j) * 3 + i);
assertNotNull(resultObject);
Logger.debug("resultObject(%s)", resultObject.toSQLSelectionString());
Integer iVal = resultObject.getIntegerValue("intValue");
assertNotNull(iVal);
assertEquals(j, iVal.intValue());
Double dVal = resultObject.getDoubleValue("doubleValue");
assertNotNull(dVal);
assertEquals(((double) j * 2), dVal.doubleValue());
String sVal = resultObject.getTextValue("textValue");
assertNotNull(sVal);
assertEquals(String.format("%04d", j * 3), sVal);
}
}
connectivity.delete(new Query(QueryObject.class));
}
use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class DatabaseConnectivityTest method testQueryCursor.
public void testQueryCursor() {
final int count = 10;
DatabaseObject object = null;
DatabaseObject[] objects = new DatabaseObject[count];
assertNotNull(objects);
for (int i = 0; i < 10; 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));
objects[i] = object;
}
AbsDatabaseConnectivity connectivity = new DatabaseConnectivity(mTargetContext, AUTHORITY, QueryObject.class);
assertNotNull(connectivity);
connectivity.insert(objects);
final Template templ = object.getTemplate();
Column col = templ.getColumn("intValue");
Query query = null;
ExpressionToken selToken = null;
DatabaseObject resultObject = null;
Cursor c = null;
query = new Query(QueryObject.class);
assertNotNull(query);
selToken = col.gt(5).and(col.lt(9));
query.setSelection(selToken);
c = connectivity.queryCursor(query);
assertNotNull(c);
assertEquals(3, c.getCount());
assertTrue(c.moveToFirst());
for (int i = 6; i <= 8; i++, c.moveToNext()) {
resultObject = connectivity.fromCursor(c, QueryObject.class);
assertNotNull(resultObject);
Logger.debug("resultObject(%s)", resultObject.toSQLSelectionString());
Integer iVal = resultObject.getIntegerValue("intValue");
assertNotNull(iVal);
assertEquals(i, iVal.intValue());
Double dVal = resultObject.getDoubleValue("doubleValue");
assertNotNull(dVal);
assertEquals(((double) i * 2), dVal.doubleValue());
String sVal = resultObject.getTextValue("textValue");
assertNotNull(sVal);
assertEquals(String.format("%04d", i * 3), sVal);
}
c.close();
selToken = col.gt(5).and(col.lt(9));
query.setSelection(selToken);
c = connectivity.queryCursor(query, ProjectionObject.class);
assertNotNull(c);
assertEquals(1, c.getCount());
assertTrue(c.moveToFirst());
resultObject = connectivity.fromCursor(c, ProjectionObject.class);
Integer iCount = resultObject.getIntegerValue("count( _id )");
assertNotNull(iCount);
assertEquals(3, iCount.intValue());
c.close();
connectivity.delete(new Query(QueryObject.class));
}
use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class DatabaseConnectivityTest method testQueryWithProjectionClass.
public void testQueryWithProjectionClass() {
final int count = 10;
DatabaseObject object = null;
DatabaseObject[] objects = new DatabaseObject[count];
assertNotNull(objects);
for (int i = 0; i < 10; 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));
objects[i] = object;
}
AbsDatabaseConnectivity connectivity = new DatabaseConnectivity(mTargetContext, AUTHORITY, QueryObject.class);
assertNotNull(connectivity);
connectivity.insert(objects);
final Template templ = object.getTemplate();
Column col = templ.getColumn("intValue");
Query query = new Query(QueryObject.class);
assertNotNull(query);
ExpressionToken selToken = col.gt(5).and(col.lt(9));
query.setSelection(selToken);
List<DatabaseObject> results = connectivity.query(query, ProjectionObject.class);
assertNotNull(results);
assertEquals(1, results.size());
DatabaseObject resultObject = results.get(0);
Integer iCount = resultObject.getIntegerValue("count( _id )");
assertNotNull(iCount);
assertEquals(3, iCount.intValue());
connectivity.delete(new Query(QueryObject.class));
}
use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class ProviderUriBuilderTest method testBuildQueryUri.
public void testBuildQueryUri() {
final long serial = System.currentTimeMillis();
Uri uri1 = ProviderUriBuilder.buildQueryUri(AUTHORITY, SampleObject1.class, serial);
assertNotNull(uri1);
Uri uri2 = ProviderUriBuilder.buildQueryUri(AUTHORITY, SampleObject1.class, 0x3, serial);
assertNotNull(uri2);
Uri uri3 = ProviderUriBuilder.buildQueryUri(AUTHORITY, SampleObject1.class, 0x4);
assertNotNull(uri3);
Uri uri4 = ProviderUriBuilder.buildQueryUri(AUTHORITY, SampleObject1.class);
assertNotNull(uri4);
final Template template = new SampleObject1(mContext).getTemplate();
assertNotNull(template);
final String table = DatabaseObject.classToTable(SampleObject1.class);
assertNotNull(table);
String uristr = null;
Uri expectedUri = null;
uristr = String.format("content://com.dailystudio/query/com.dailystudio.dataobject.samples.SampleObject1.db/1/SampleObject1?serial=%d", serial);
expectedUri = Uri.parse(uristr);
assertEquals(expectedUri, uri1);
uristr = String.format("content://com.dailystudio/query/com.dailystudio.dataobject.samples.SampleObject1.db/3/SampleObject1?serial=%d", serial);
expectedUri = Uri.parse(uristr);
assertEquals(expectedUri, uri2);
uristr = "content://com.dailystudio/query/com.dailystudio.dataobject.samples.SampleObject1.db/4/SampleObject1";
expectedUri = Uri.parse(uristr);
assertEquals(expectedUri, uri3);
uristr = "content://com.dailystudio/query/com.dailystudio.dataobject.samples.SampleObject1.db/1/SampleObject1";
expectedUri = Uri.parse(uristr);
assertEquals(expectedUri, uri4);
}
Aggregations