use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class ProjectionObject method initMembers.
private void initMembers() {
final Template templ = getTemplate();
templ.addColumn(COLUMN_ID_COUNT);
}
use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class QueryObject method initMembers.
private void initMembers() {
final Template templ = getTemplate();
templ.addColumn(new IntegerColumn("_id", false, true));
templ.addColumn(new IntegerColumn("intValue"));
templ.addColumn(new DoubleColumn("doubleValue"));
templ.addColumn(new TextColumn("textValue"));
}
use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class DatabaseConnectivityDirectSQLImplTest 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 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, 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 DatabaseConnectivityDirectSQLImplTest 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 DatabaseConnectivityDirectSQLiteImpl(mTargetContext, 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 DatabaseConnectivityDirectSQLImplTest method testQueryWithGroupBy.
public void testQueryWithGroupBy() {
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", i);
object.setValue("doubleValue", ((double) i * 2));
object.setValue("textValue", String.format("%04d", i * 3));
objects[i * 10 + j] = 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.gte(0).and(col.lt(2));
query.setSelection(selToken);
OrderingToken groupByToken = col.groupBy();
query.setGroupBy(groupByToken);
List<DatabaseObject> results = connectivity.query(query);
assertNotNull(results);
assertEquals(2, results.size());
DatabaseObject resultObject = null;
for (int i = 0; i < 2; i++) {
resultObject = results.get(i);
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));
}
Aggregations