use of com.dailystudio.dataobject.query.ExpressionToken in project devbricks by dailystudio.
the class DatabaseConnectivityTest 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;
}
AbsDatabaseConnectivity connectivity = new DatabaseConnectivity(mTargetContext, AUTHORITY, QueryObject.class);
assertNotNull(connectivity);
connectivity.insert(objects);
Query query = new Query(QueryObject.class);
assertNotNull(query);
ExpressionToken limit = new ExpressionToken("5");
query.setLimit(limit);
List<DatabaseObject> results = connectivity.query(query);
assertNotNull(results);
assertEquals(5, results.size());
DatabaseObject resultObject = null;
for (int i = 0; i < 5; i++) {
resultObject = results.get(i);
assertNotNull(resultObject);
Logger.debug("resultObject(%s)", resultObject.toSQLSelectionString());
Integer iVal = resultObject.getIntegerValue("intValue");
assertNotNull(iVal);
assertEquals(i, iVal.intValue());
Double dVal = resultObject.getDoubleValue("doubleValue");
assertNotNull(dVal);
assertEquals(((double) i * 2), dVal.doubleValue());
String sVal = resultObject.getTextValue("textValue");
assertNotNull(sVal);
assertEquals(String.format("%04d", i * 3), sVal);
}
connectivity.delete(new Query(QueryObject.class));
}
use of com.dailystudio.dataobject.query.ExpressionToken in project devbricks by dailystudio.
the class DatabaseConnectivityTest 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;
}
AbsDatabaseConnectivity connectivity = new DatabaseConnectivity(mTargetContext, AUTHORITY, QueryObject.class);
assertNotNull(connectivity);
connectivity.insert(objects);
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);
List<DatabaseObject> results = connectivity.query(query);
assertNotNull(results);
assertEquals(3, results.size());
DatabaseObject resultObject = null;
for (int i = 6; i <= 8; i++) {
resultObject = results.get(i - 6);
assertNotNull(resultObject);
Logger.debug("resultObject(%s)", resultObject.toSQLSelectionString());
Integer iVal = resultObject.getIntegerValue("intValue");
assertNotNull(iVal);
assertEquals(i, iVal.intValue());
Double dVal = resultObject.getDoubleValue("doubleValue");
assertNotNull(dVal);
assertEquals(((double) i * 2), dVal.doubleValue());
String sVal = resultObject.getTextValue("textValue");
assertNotNull(sVal);
assertEquals(String.format("%04d", i * 3), sVal);
}
connectivity.delete(new Query(QueryObject.class));
}
use of com.dailystudio.dataobject.query.ExpressionToken in project devbricks by dailystudio.
the class AbsTimeCapsuleModel method getObject.
public T getObject(Context context, DatabaseObjectKeys keys) {
if (context == null || keys == null) {
return null;
}
TimeCapsuleDatabaseReader<T> reader = new TimeCapsuleDatabaseReader<>(context, mObjectClass);
Query query = new Query(mObjectClass);
ExpressionToken selToken = objectsToken(keys, TOKEN_TYPE_EXISTENCE);
if (selToken == null) {
return null;
}
query.setSelection(selToken);
return (reader.queryLastOne(query));
}
use of com.dailystudio.dataobject.query.ExpressionToken in project devbricks by dailystudio.
the class TimeCapsuleDatabaseWriter method update.
public int update(T object) {
if (object == null) {
return 0;
}
final DatabaseConnectivity connectivity = getConnectivity();
if (connectivity == null) {
return 0;
}
Query query = getQuery();
ExpressionToken token = TimeCapsule.COLUMN_ID.eq(object.getId());
query.setSelection(token);
return connectivity.update(query, object);
}
use of com.dailystudio.dataobject.query.ExpressionToken in project devbricks by dailystudio.
the class TimeCapsuleQueryBuilder method getQuery.
public Query getQuery(long start, long end, boolean orderByAscending) {
Logger.debug("peroid: start(%s), end(%s), orderByAscending(%s)", CalendarUtils.timeToReadableString(start), CalendarUtils.timeToReadableString(end), orderByAscending);
Query query = getQuery();
if (query != null) {
if (start < end) {
ExpressionToken selection = TimeCapsule.COLUMN_TIME.gte(start).and(TimeCapsule.COLUMN_TIME.lte(end));
if (selection != null) {
query.setSelection(selection);
}
}
OrderingToken orderBy = (orderByAscending ? TimeCapsule.COLUMN_TIME.orderByAscending() : TimeCapsule.COLUMN_TIME.orderByDescending());
if (orderBy != null) {
query.setOrderBy(orderBy);
}
}
return query;
}
Aggregations