Search in sources :

Example 16 with SampleObject1

use of com.dailystudio.dataobject.samples.SampleObject1 in project devbricks by dailystudio.

the class ProviderQueryUriParserTest method testGetDatabase.

public void testGetDatabase() {
    final long now = System.currentTimeMillis();
    Uri queryUri = null;
    ProviderQueryUriParser parser = null;
    queryUri = ProviderUriBuilder.buildQueryUri(AUTHORITY, SampleObject1.class, now);
    assertNotNull(queryUri);
    parser = new ProviderQueryUriParser(queryUri);
    assertNotNull(parser);
    assertEquals("com.dailystudio.dataobject.samples.SampleObject1.db", parser.getDatabase());
    queryUri = ProviderUriBuilder.buildQueryUri(AUTHORITY, QueryUriTestObject.class, now);
    assertNotNull(queryUri);
    parser = new ProviderQueryUriParser(queryUri);
    assertNotNull(parser);
    assertEquals("com.dailystudio.dataobject.database.ProviderQueryUriParserTest_QueryUriTestObject.db", parser.getDatabase());
}
Also used : SampleObject1(com.dailystudio.dataobject.samples.SampleObject1) Uri(android.net.Uri)

Example 17 with SampleObject1

use of com.dailystudio.dataobject.samples.SampleObject1 in project devbricks by dailystudio.

the class ProviderQueryUriParserTest method testGetTable.

public void testGetTable() {
    final long now = System.currentTimeMillis();
    Uri queryUri = null;
    ProviderQueryUriParser parser = null;
    queryUri = ProviderUriBuilder.buildQueryUri(AUTHORITY, SampleObject1.class, now);
    assertNotNull(queryUri);
    parser = new ProviderQueryUriParser(queryUri);
    assertNotNull(parser);
    assertEquals("SampleObject1", parser.getTable());
    queryUri = ProviderUriBuilder.buildQueryUri(AUTHORITY, QueryUriTestObject.class, now);
    assertNotNull(queryUri);
    parser = new ProviderQueryUriParser(queryUri);
    assertNotNull(parser);
    assertEquals("ProviderQueryUriParserTest_QueryUriTestObject", parser.getTable());
}
Also used : SampleObject1(com.dailystudio.dataobject.samples.SampleObject1) Uri(android.net.Uri)

Example 18 with SampleObject1

use of com.dailystudio.dataobject.samples.SampleObject1 in project devbricks by dailystudio.

the class ProviderQueryUriParserTest method testGetVersion.

public void testGetVersion() {
    final long now = System.currentTimeMillis();
    Uri queryUri = null;
    ProviderQueryUriParser parser = null;
    queryUri = ProviderUriBuilder.buildQueryUri(AUTHORITY, SampleObject1.class, now);
    assertNotNull(queryUri);
    parser = new ProviderQueryUriParser(queryUri);
    assertNotNull(parser);
    assertEquals(DatabaseObject.VERSION_START, parser.getVersion());
    queryUri = ProviderUriBuilder.buildQueryUri(AUTHORITY, SampleObject1.class, 10, now);
    assertNotNull(queryUri);
    parser = new ProviderQueryUriParser(queryUri);
    assertNotNull(parser);
    assertEquals(10, parser.getVersion());
}
Also used : SampleObject1(com.dailystudio.dataobject.samples.SampleObject1) Uri(android.net.Uri)

Example 19 with SampleObject1

use of com.dailystudio.dataobject.samples.SampleObject1 in project devbricks by dailystudio.

the class ProviderQueryUriParserTest method testGetSerial.

public void testGetSerial() {
    final long now = System.currentTimeMillis();
    Uri queryUri = null;
    ProviderQueryUriParser parser = null;
    queryUri = ProviderUriBuilder.buildQueryUri(AUTHORITY, SampleObject1.class, now);
    assertNotNull(queryUri);
    parser = new ProviderQueryUriParser(queryUri);
    assertNotNull(parser);
    assertEquals(now, parser.getSerial());
}
Also used : SampleObject1(com.dailystudio.dataobject.samples.SampleObject1) Uri(android.net.Uri)

Example 20 with SampleObject1

use of com.dailystudio.dataobject.samples.SampleObject1 in project devbricks by dailystudio.

the class AsyncDatabaseHelperTest method testInsertDatabaseObjects.

public void testInsertDatabaseObjects() {
    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(), "BulkInsertCookie1", objects);
    waitHelper(helper1);
    helper2.startBulkInsert(mRandom.nextInt(), "BulkInsertCookie2", objects);
    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) {
            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(5, c.getCount());
    assertEquals(true, c.moveToFirst());
    for (int i = 0; i < 5; i++) {
        if (i % 2 != 0) {
            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));
}
Also used : Query(com.dailystudio.dataobject.query.Query) SampleObject1(com.dailystudio.dataobject.samples.SampleObject1) SampleObject2(com.dailystudio.dataobject.samples.SampleObject2) Cursor(android.database.Cursor) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) DatabaseObject(com.dailystudio.dataobject.DatabaseObject)

Aggregations

SampleObject1 (com.dailystudio.dataobject.samples.SampleObject1)24 DatabaseObject (com.dailystudio.dataobject.DatabaseObject)14 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)12 Uri (android.net.Uri)12 Query (com.dailystudio.dataobject.query.Query)12 Cursor (android.database.Cursor)9 SampleObject2 (com.dailystudio.dataobject.samples.SampleObject2)9 ExpressionToken (com.dailystudio.dataobject.query.ExpressionToken)6 SQLException (android.database.SQLException)3 Template (com.dailystudio.dataobject.Template)3