use of com.dailystudio.dataobject.DatabaseObject in project devbricks by dailystudio.
the class DatabaseReader method queryCount.
public long queryCount(Query query) {
if (query == null) {
return 0l;
}
List<DatabaseObject> objects = query(query, CountObject.class);
if (objects == null || objects.size() <= 0) {
return 0l;
}
DatabaseObject object0 = objects.get(0);
if (object0 instanceof CountObject == false) {
return 0l;
}
return ((CountObject) object0).getCount();
}
use of com.dailystudio.dataobject.DatabaseObject in project devbricks by dailystudio.
the class AsyncDatabaseHelperTest method testLimitQuery.
public void testLimitQuery() {
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);
Query query = new Query(QueryObject.class);
assertNotNull(query);
ExpressionToken limit = new ExpressionToken("5");
query.setLimit(limit);
helper.startQuery(mRandom.nextInt(), "testLimitQuery", query);
waitHelper(helper);
AbsDatabaseConnectivity connectivity = new DatabaseConnectivity(mTargetContext, AUTHORITY, QueryObject.class);
assertNotNull(connectivity);
connectivity.delete(new Query(QueryObject.class));
}
use of com.dailystudio.dataobject.DatabaseObject in project devbricks by dailystudio.
the class AsyncDatabaseHelperTest method testDeleteDatabaseObjects.
public void testDeleteDatabaseObjects() {
AsyncDatabaseHelper helper1 = new TestAsyncDatabaseHelp(mTargetContext, AUTHORITY, SampleObject1.class, true);
assertNotNull(helper1);
AsyncDatabaseHelper helper2 = new TestAsyncDatabaseHelp(mTargetContext, AUTHORITY, SampleObject2.class, true);
assertNotNull(helper2);
final int count = 10;
DatabaseObject object = null;
DatabaseObject[] objects = new DatabaseObject[count];
assertNotNull(objects);
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
object = DatabaseObjectFactory.createDatabaseObject(SampleObject1.class);
assertNotNull(object);
object.setValue(SampleObject1.COLUMN_TIME, (1000l * i));
} else {
object = DatabaseObjectFactory.createDatabaseObject(SampleObject2.class);
assertNotNull(object);
object.setValue(SampleObject2.COLUMN_LAT, 0.1 * i);
object.setValue(SampleObject2.COLUMN_LON, 0.2 * i);
object.setValue(SampleObject2.COLUMN_ALT, 0.3 * i);
}
objects[i] = object;
}
helper1.startBulkInsert(mRandom.nextInt(), "BulkInsert1", objects);
waitHelper(helper1);
helper2.startBulkInsert(mRandom.nextInt(), "BulkInsert2", objects);
waitHelper(helper2);
Query query1 = new Query(SampleObject1.class);
assertNotNull(query1);
ExpressionToken selection1 = SampleObject1.COLUMN_TIME.gt(5000l);
assertNotNull(selection1);
query1.setSelection(selection1);
helper1.startDelete(mRandom.nextInt(), "BulkInsert2", query1);
waitHelper(helper1);
Query qParams2 = new Query(SampleObject2.class);
assertNotNull(qParams2);
ExpressionToken selection2 = SampleObject2.COLUMN_LAT.gt(0.2).and(SampleObject2.COLUMN_LON.lt(0.8));
assertNotNull(selection2);
qParams2.setSelection(selection2);
helper2.startDelete(mRandom.nextInt(), "BulkInsert2", qParams2);
waitHelper(helper2);
AbsDatabaseConnectivity connectivity1 = new DatabaseConnectivity(mTargetContext, AUTHORITY, SampleObject1.class);
assertNotNull(connectivity1);
AbsDatabaseConnectivity connectivity2 = new DatabaseConnectivity(mTargetContext, AUTHORITY, SampleObject2.class);
assertNotNull(connectivity2);
DatabaseOpenHandler handler1 = DatabaseOpenHandler.getInstance(mTargetContext, DatabaseObject.classToDatabase(SampleObject1.class), 0x1);
assertNotNull(handler1);
DatabaseOpenHandler handler2 = DatabaseOpenHandler.getInstance(mTargetContext, DatabaseObject.classToDatabase(SampleObject2.class), 0x1);
assertNotNull(handler2);
SQLiteDatabase sqlDB = null;
Cursor c = null;
sqlDB = handler1.getReadableDatabase();
assertNotNull(sqlDB);
c = sqlDB.query(DatabaseObject.classToTable(SampleObject1.class), null, null, null, null, null, null);
assertNotNull(c);
assertEquals(3, c.getCount());
assertEquals(true, c.moveToFirst());
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
if (i * 1000l > 5000l) {
continue;
} else {
assertEquals(i * 1000l, c.getLong(c.getColumnIndex("time")));
}
c.moveToNext();
}
}
c.close();
// sqlDB.delete(AbsDatabaseConnectivity.classToTable(SampleObject1.class),
// null, null);
sqlDB.close();
sqlDB = handler2.getReadableDatabase();
assertNotNull(sqlDB);
c = sqlDB.query(DatabaseObject.classToTable(SampleObject2.class), null, null, null, null, null, null);
assertNotNull(c);
assertEquals(4, c.getCount());
assertEquals(true, c.moveToFirst());
for (int i = 0; i < 5; i++) {
if (i % 2 != 0) {
if ((0.1 * i > 0.2) && (0.2 * i < 0.8)) {
continue;
} else {
assertEquals(0.1 * i, c.getDouble(c.getColumnIndex("latitude")));
assertEquals(0.2 * i, c.getDouble(c.getColumnIndex("longitude")));
assertEquals(0.3 * i, c.getDouble(c.getColumnIndex("altitude")));
}
c.moveToNext();
}
}
c.close();
// sqlDB.delete(AbsDatabaseConnectivity.classToTable(SampleObject2.class),
// null, null);
sqlDB.close();
connectivity1.delete(new Query(SampleObject1.class));
connectivity2.delete(new Query(SampleObject2.class));
}
use of com.dailystudio.dataobject.DatabaseObject 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.DatabaseObject in project devbricks by dailystudio.
the class AsyncDatabaseHelperTest method testInsertDatabaseObject.
public void testInsertDatabaseObject() {
AsyncDatabaseHelper helper = new TestAsyncDatabaseHelp(mTargetContext, AUTHORITY, SampleObject2.class, true);
assertNotNull(helper);
DatabaseObject object = DatabaseObjectFactory.createDatabaseObject(SampleObject2.class);
assertNotNull(object);
object.setValue(SampleObject2.COLUMN_LAT, 0.1);
object.setValue(SampleObject2.COLUMN_LON, 0.2);
object.setValue(SampleObject2.COLUMN_ALT, 0.3);
helper.startInsert(mRandom.nextInt(), "InsertCookie", object);
waitHelper(helper);
AbsDatabaseConnectivity connectivity = new DatabaseConnectivity(mTargetContext, AUTHORITY, SampleObject2.class);
assertNotNull(connectivity);
DatabaseOpenHandler handler = DatabaseOpenHandler.getInstance(mTargetContext, DatabaseObject.classToDatabase(SampleObject2.class), 0x1);
assertNotNull(handler);
SQLiteDatabase sqlDB = handler.getReadableDatabase();
assertNotNull(sqlDB);
Cursor c = sqlDB.query(DatabaseObject.classToTable(SampleObject2.class), null, null, null, null, null, null);
assertNotNull(c);
assertEquals(1, c.getCount());
assertEquals(true, c.moveToFirst());
assertEquals(0.1, c.getDouble(c.getColumnIndex(SampleObject2.COLUMN_LAT.getName())));
assertEquals(0.2, c.getDouble(c.getColumnIndex(SampleObject2.COLUMN_LON.getName())));
assertEquals(0.3, c.getDouble(c.getColumnIndex(SampleObject2.COLUMN_ALT.getName())));
c.close();
// sqlDB.delete(AbsDatabaseConnectivity.classToTable(SampleObject2.class),
// null, null);
sqlDB.close();
connectivity.delete(new Query(SampleObject2.class));
}
Aggregations