use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class QueryTest method testCreateQuery.
public void testCreateQuery() {
Template template = new Template();
assertNotNull(template);
Query query = null;
query = new Query(TestDatabaseObject.class);
assertNotNull(query);
assertEquals(TestDatabaseObject.class, query.getObjectClass());
}
use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class DatabaseConnectivityDirectSQLiteImpl method onInsert.
@Override
protected int onInsert(DatabaseObject[] objects) {
if (objects == null) {
return 0;
}
final int count = objects.length;
if (count <= 0) {
return 0;
}
if (mOpenHandler == null) {
return 0;
}
final SQLiteDatabase db = mOpenHandler.getWritableDatabase();
if (db == null) {
return 0;
}
int successful = 0;
try {
db.beginTransaction();
ContentValues values = null;
DatabaseObject object = null;
Template template = null;
String table = null;
long rowId = -1;
for (int i = 0; i < count; i++) {
object = objects[i];
if (object == null || object.isEmpty()) {
continue;
}
values = object.getValues();
if (values == null) {
continue;
}
template = object.getTemplate();
if (template == null) {
continue;
}
table = DatabaseObject.classToTable(object.getClass());
if (table == null) {
continue;
}
if (checkOrCreateTable(db, table, object) == false) {
continue;
}
rowId = db.insert(table, object.handleNullProjection(), values);
if (rowId <= 0) {
continue;
}
successful++;
}
db.setTransactionSuccessful();
} catch (SQLException e) {
Logger.warn("database failure: %s", e.toString());
} catch (IllegalStateException e) {
Logger.warn("database failure: %s", e.toString());
} finally {
try {
db.endTransaction();
} catch (Exception e) {
Logger.warn("database failure: %s", e.toString());
}
}
db.close();
return successful;
}
use of com.dailystudio.dataobject.Template in project devbricks by dailystudio.
the class DatabaseConnectivity method onUpdate.
@Override
protected int onUpdate(Query query, DatabaseObject object) {
if (query == null || object == null || object.isEmpty()) {
return 0;
}
if (checkProviderPreparation() == false) {
return 0;
}
final ContentValues values = object.getValues();
if (values == null) {
return 0;
}
Uri uri = ProviderUriBuilder.buildQueryUri(mAuthority, mObjectClass, getDatabaseVersion());
if (uri == null) {
return 0;
}
final Template template = object.getTemplate();
if (template == null) {
return 0;
}
final String table = DatabaseObject.classToTable(mObjectClass);
if (table == null) {
return 0;
}
uri = ProviderUriBuilder.attachCreateTableParamter(uri, object.toSQLTableCreationString());
if (uri == null) {
return 0;
}
String selection = null;
QueryToken selToken = query.getSelection();
if (selToken != null) {
selection = selToken.toString();
}
return mContentResovler.update(uri, values, selection, null);
}
use of com.dailystudio.dataobject.Template 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.Template in project devbricks by dailystudio.
the class ExpressionTokenTest method testSamples.
public void testSamples() {
Template templ = new Template();
assertNotNull(templ);
templ.addColumn(new IntegerColumn("_id", false, true));
templ.addColumn(new IntegerColumn("intValue"));
templ.addColumn(new DoubleColumn("doubleValue"));
templ.addColumn(new TextColumn("textValue"));
assertEquals(new QueryToken("( intValue > 1000 ) AND ( intValue < 2000 )"), templ.getColumn("intValue").gt(1000).and(templ.getColumn("intValue").lt(2000)));
}
Aggregations