use of com.dailystudio.dataobject.samples.SampleObject1 in project devbricks by dailystudio.
the class AsyncDatabaseHelperTest method testUpdateDatabaseObjects.
public void testUpdateDatabaseObjects() {
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);
DatabaseObject updateObject = null;
Query query1 = new Query(SampleObject1.class);
assertNotNull(query1);
ExpressionToken selection1 = SampleObject1.COLUMN_TIME.gt(5000l);
assertNotNull(selection1);
query1.setSelection(selection1);
updateObject = DatabaseObjectFactory.createDatabaseObject(SampleObject1.class);
updateObject.setValue(SampleObject1.COLUMN_TIME, 0l);
helper1.startUpdate(mRandom.nextInt(), "update1", query1, updateObject);
waitHelper(helper1);
Query query2 = new Query(SampleObject2.class);
assertNotNull(query2);
ExpressionToken selection2 = SampleObject2.COLUMN_LAT.gt(0.2).and(SampleObject2.COLUMN_LON.lt(0.8));
assertNotNull(selection2);
query2.setSelection(selection2);
updateObject = DatabaseObjectFactory.createDatabaseObject(SampleObject2.class);
updateObject.setValue(SampleObject2.COLUMN_ALT, 12.34);
helper2.startUpdate(mRandom.nextInt(), "update2", query2, updateObject);
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(5, c.getCount());
assertEquals(true, c.moveToFirst());
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
if (i * 1000l > 5000l) {
assertEquals(0, c.getLong(c.getColumnIndex("time")));
} else {
assertEquals(i * 1000l, c.getLong(c.getColumnIndex("time")));
}
c.moveToNext();
}
}
c.close();
sqlDB.close();
sqlDB = handler2.getReadableDatabase();
assertNotNull(sqlDB);
c = sqlDB.query(DatabaseObject.classToTable(SampleObject2.class), null, null, null, null, null, null);
assertNotNull(c);
assertEquals(5, 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)) {
assertEquals(0.1 * i, c.getDouble(c.getColumnIndex("latitude")));
assertEquals(0.2 * i, c.getDouble(c.getColumnIndex("longitude")));
assertEquals(12.34, c.getDouble(c.getColumnIndex("altitude")));
} 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.close();
connectivity1.delete(new Query(SampleObject1.class));
connectivity2.delete(new Query(SampleObject2.class));
}
use of com.dailystudio.dataobject.samples.SampleObject1 in project devbricks by dailystudio.
the class AsyncDatabaseHelperTest method testDeleteAllDatabaseObjects.
public void testDeleteAllDatabaseObjects() {
AsyncDatabaseHelper helper = new TestAsyncDatabaseHelp(mTargetContext, AUTHORITY, SampleObject1.class, true);
assertNotNull(helper);
final int count = 10;
DatabaseObject object = null;
DatabaseObject[] objects = new DatabaseObject[count];
assertNotNull(objects);
for (int i = 0; i < 10; i++) {
object = DatabaseObjectFactory.createDatabaseObject(SampleObject1.class);
assertNotNull(object);
object.setValue(SampleObject1.COLUMN_TIME, (1000l * i));
objects[i] = object;
}
helper.startBulkInsert(mRandom.nextInt(), "BulkInsert", objects);
waitHelper(helper);
Query query = new Query(SampleObject1.class);
assertNotNull(query);
helper.startDelete(mRandom.nextInt(), "BulkInsert", query);
waitHelper(helper);
AbsDatabaseConnectivity connectivity = new DatabaseConnectivity(mTargetContext, AUTHORITY, SampleObject1.class);
assertNotNull(connectivity);
DatabaseOpenHandler handler = DatabaseOpenHandler.getInstance(mTargetContext, DatabaseObject.classToDatabase(SampleObject1.class), 0x1);
assertNotNull(handler);
SQLiteDatabase sqlDB = handler.getReadableDatabase();
assertNotNull(sqlDB);
boolean catched = false;
try {
sqlDB.query(DatabaseObject.classToTable(SampleObject1.class), null, null, null, null, null, null);
catched = false;
} catch (SQLException e) {
e.printStackTrace();
catched = true;
}
sqlDB.close();
assertTrue(catched);
connectivity.delete(new Query(SampleObject1.class));
}
use of com.dailystudio.dataobject.samples.SampleObject1 in project devbricks by dailystudio.
the class ProviderUriBuilderTest method testAttachCreateTableParamter.
public void testAttachCreateTableParamter() {
final long serial = System.currentTimeMillis();
Uri uri = ProviderUriBuilder.buildQueryUri(AUTHORITY, SampleObject1.class, serial);
assertNotNull(uri);
DatabaseObject sample = new SampleObject1(mContext);
assertNotNull(sample);
final Template template = sample.getTemplate();
assertNotNull(template);
final String table = DatabaseObject.classToTable(SampleObject1.class);
assertNotNull(table);
uri = ProviderUriBuilder.attachCreateTableParamter(uri, sample.toSQLTableCreationString());
String uristr = String.format("content://com.dailystudio/query/com.dailystudio.dataobject.samples.SampleObject1.db/1/SampleObject1?serial=%d&createTable=%s", serial, "CREATE%20TABLE%20IF%20NOT%20EXISTS%20SampleObject1%20(%20_id%20INTEGER%20NOT%20NULL%20PRIMARY%20KEY%2C%20time%20LONG%20NOT%20NULL%20)%3B");
Uri expectedUri = Uri.parse(uristr);
assertEquals(expectedUri, uri);
}
use of com.dailystudio.dataobject.samples.SampleObject1 in project devbricks by dailystudio.
the class ProviderUriBuilderTest method testBuildCommandUri.
public void testBuildCommandUri() {
Uri uri = null;
String uristr = null;
Uri expectedUri = null;
uri = ProviderUriBuilder.buildCommandUri(AUTHORITY, SampleObject1.class, GetUpdateInfoCmdCursor.COMMAND_NAME);
assertNotNull(uri);
uristr = "content://com.dailystudio/command/com.dailystudio.dataobject.samples.SampleObject1.db/1/SampleObject1/cmd_get_update_info";
expectedUri = Uri.parse(uristr);
assertEquals(expectedUri, uri);
uri = ProviderUriBuilder.buildCommandUri(AUTHORITY, SampleObject1.class, 10, GetUpdateInfoCmdCursor.COMMAND_NAME);
assertNotNull(uri);
uristr = "content://com.dailystudio/command/com.dailystudio.dataobject.samples.SampleObject1.db/10/SampleObject1/cmd_get_update_info";
expectedUri = Uri.parse(uristr);
assertEquals(expectedUri, uri);
}
Aggregations