use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class TemplateTest method testAddColumns.
public void testAddColumns() {
Template templ = new Template();
assertNotNull(templ);
Column col1 = new IntegerColumn("_id");
Column col2 = new LongColumn("time");
Column col3 = new DoubleColumn("fp");
Column col4 = new TextColumn("dummy");
assertNotNull(col1);
assertNotNull(col2);
assertNotNull(col3);
assertNotNull(col4);
Column[] array = { col1, col2, col3, col4 };
templ.addColumns(array);
List<Column> columns = templ.listColumns();
assertNotNull(columns);
assertEquals(4, columns.size());
List<Column> expected = new ArrayList<Column>();
expected.add(col1);
expected.add(col2);
expected.add(col3);
expected.add(col4);
Asserts.assertEquals(expected, columns);
}
use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class TemplateTest method testContainsColumns.
public void testContainsColumns() {
Template templ = new Template();
assertNotNull(templ);
Column col1 = new IntegerColumn("col1");
Column col2 = new LongColumn("col2");
Column col3 = new DoubleColumn("col3");
Column col4 = new TextColumn("col4");
assertNotNull(col1);
assertNotNull(col2);
assertNotNull(col3);
assertNotNull(col4);
templ.addColumn(col1);
templ.addColumn(col2);
templ.addColumn(col3);
templ.addColumn(col4);
assertEquals(true, templ.containsColumn("col1"));
assertEquals(true, templ.containsColumn("col2"));
assertEquals(true, templ.containsColumn("col3"));
assertEquals(true, templ.containsColumn("col4"));
assertEquals(true, templ.containsColumn(col1));
assertEquals(true, templ.containsColumn(col2));
assertEquals(true, templ.containsColumn(col3));
assertEquals(true, templ.containsColumn(col4));
Column col5 = new TextColumn("col5");
assertEquals(false, templ.containsColumn(col5));
assertEquals(false, templ.containsColumn("col5"));
assertEquals(false, templ.containsColumn((Column) null));
assertEquals(false, templ.containsColumn((String) null));
}
use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class AsyncDatabaseHelperTest 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;
}
AsyncDatabaseHelper helper = new TestAsyncDatabaseHelp(mTargetContext, AUTHORITY, QueryObject.class, true);
assertNotNull(helper);
helper.startBulkInsert(mRandom.nextInt(), "BulkInsert1", objects);
waitHelper(helper);
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);
helper.startQuery(mRandom.nextInt(), "testSimpleQuery", query);
waitHelper(helper);
AbsDatabaseConnectivity connectivity = new DatabaseConnectivity(mTargetContext, AUTHORITY, QueryObject.class);
assertNotNull(connectivity);
connectivity.delete(new Query(QueryObject.class));
}
use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class AsyncDatabaseHelperTest 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;
}
}
AsyncDatabaseHelper helper = new TestAsyncDatabaseHelp(mTargetContext, AUTHORITY, QueryObject.class, true);
assertNotNull(helper);
helper.startBulkInsert(mRandom.nextInt(), "BulkInsert1", objects);
waitHelper(helper);
final Template templ = object.getTemplate();
Column col = templ.getColumn("intValue");
Query query = null;
OrderingToken orderByToken = null;
query = new Query(QueryObject.class);
assertNotNull(query);
orderByToken = col.orderByAscending();
query.setOrderBy(orderByToken);
helper.startQuery(mRandom.nextInt(), "testQueryWithOrderBy1", query);
waitHelper(helper);
query = new Query(QueryObject.class);
assertNotNull(query);
orderByToken = col.orderByDescending();
query.setOrderBy(orderByToken);
helper.startQuery(mRandom.nextInt(), "testQueryWithOrderBy2", query);
waitHelper(helper);
AbsDatabaseConnectivity connectivity = new DatabaseConnectivity(mTargetContext, AUTHORITY, QueryObject.class);
assertNotNull(connectivity);
connectivity.delete(new Query(QueryObject.class));
}
use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class DatabaseConnectivityDirectSQLImplTest 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 DatabaseConnectivityDirectSQLiteImpl(mTargetContext, 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));
}
Aggregations