use of io.divide.shared.transitory.query.QueryBuilder in project divide by HiddenStage.
the class MyActivity method getObjects.
@OnClick(R.id.getObjects)
public void getObjects() {
final Query q = new QueryBuilder().select().from(BackendObject.class).limit(10).build();
BackendServices.remote().query(BackendObject.class, q).subscribe(new Action1<Collection<BackendObject>>() {
@Override
public void call(Collection<BackendObject> objects) {
objectList.clear();
objectList.addAll(objects);
adapter.notifyDataSetChanged();
// BackendServices.local().save((BackendObject[]) objects.toArray());
// List<BackendObject> col = BackendServices.local().query(q);
// for (BackendObject o : col) logger.debug(o);
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
logger.debug("", throwable);
}
});
}
use of io.divide.shared.transitory.query.QueryBuilder in project divide by HiddenStage.
the class DAOTest method testDelete.
@Test
public void testDelete() throws Exception {
rawSave(object1, object2, object3, object4);
dao.delete(testObject1);
dao.delete(testObject4);
Collection<TransientObject> results = dao.get(testObject1Table, testObject1.getObjectKey(), testObject2.getObjectKey());
assertNotEquals(null, results);
assertEquals(1, results.size());
assertEquals(ObjectUtils.get1stOrNull(results).getObjectKey(), testObject2.getObjectKey());
Query q = new QueryBuilder().select().from(TestObject1.class).build();
results = dao.query(q);
assertNotEquals("Select All", null, results);
assertEquals("Select All", 2, results.size());
q = new QueryBuilder().select().from(TestObject2.class).build();
results = dao.query(q);
assertNotEquals("Select All", null, results);
assertEquals("Select All", 0, results.size());
}
use of io.divide.shared.transitory.query.QueryBuilder in project divide by HiddenStage.
the class MyActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DivideDrawer.attach(this, R.layout.main);
// setContentView(R.layout.main);
ButterKnife.inject(this);
getActionBar().setHomeButtonEnabled(true);
// au = AuthUtils.get(this, AuthManager.ACCOUNT_TYPE); TODO replace this
app = (MyApplication) this.getApplication();
BackendServices.addLoginListener(new LoginListener() {
@Override
public void onNext(BackendUser user) {
System.out.println("loginListener: setUser: " + user);
if (user != null) {
setUser(user);
}
}
});
adapter = new BackendObjectAdaper(this, objectList);
usersLV.setAdapter(adapter);
usersLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
BackendObject o = adapter.getItem(position);
Query q = new QueryBuilder().delete().from(BackendObject.class).where(TransientObject.OBJECT_KEY, OPERAND.EQ, o.getObjectKey()).build();
BackendServices.remote().query(BackendObject.class, q).subscribe(new Action1<Collection<BackendObject>>() {
@Override
public void call(Collection<BackendObject> backendObjects) {
getObjects();
}
});
BackendServices.local().delete(o);
}
});
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (BackendUser.isLoggedIn())
getObjects();
else
logger.debug("Not signed in, not querying data.");
}
}, 1000);
Storage s = new XmlStorage(new File(this.getFilesDir() + File.separator + "something.xml"), Storage.MODE_WORLD_WRITEABLE);
String id = "something";
System.out.println("Stored: " + s.getString(id, ""));
System.out.println("Stored: " + s.contains(id));
s.edit().putString(id, "something2").commit();
s.edit().putInt("int", 55).commit();
}
use of io.divide.shared.transitory.query.QueryBuilder in project divide by HiddenStage.
the class OrientDBDao method delete.
@Override
public void delete(TransientObject... objects) throws DAOException {
checkDb();
if (objects.length == 0)
return;
QueryBuilder.WhereMoreBuilder builder = new QueryBuilder().select().from(objects[0].getClass()).where(TransientObject.OBJECT_KEY, OPERAND.EQ, objects[0].getObjectKey());
for (int x = 1; x < objects.length; x++) {
builder.or(TransientObject.OBJECT_KEY, OPERAND.EQ, objects[x].getObjectKey());
}
Query q = builder.build();
// StringBuilder sb = new StringBuilder();
// sb.append("SELECT * FROM " + objects[0].getClass().getName() + " WHERE ");
// for(int x=0;x<objects.length;x++){
// sb.append("meta_data.object_key = '" + objects[x].getObjectKey() +"'");
// if(x+1<objects.length)
// sb.append( " OR ");
// }
System.out.println("Delete: " + q.getSQL());
List<ODocument> list = db.query(new OSQLSynchQuery<ODocument>(q.getSQL()));
for (ODocument w : list) {
System.out.println("Deleting: " + w);
w.delete();
}
}
use of io.divide.shared.transitory.query.QueryBuilder in project divide by HiddenStage.
the class DAOTest method testQuery.
@Test
public void testQuery() throws Exception {
rawSave(object1, object2, object3, object4);
Query q;
List<TransientObject> results;
String key = testObject1.getObjectKey();
// where
q = new QueryBuilder().select().from(TestObject1.class).where(TransientObject.OBJECT_KEY, OPERAND.EQ, key).build();
results = dao.query(q);
assertNotNull("1.", results);
assertEquals("2.", 1, results.size());
TransientObject to = ObjectUtils.get1stOrNull(results);
assertEquals(results + "", to.getObjectKey(), testObject1.getObjectKey());
q = new QueryBuilder().select().from(TestObject1.class).build();
results = dao.query(q);
assertNotEquals("Select All", null, results);
assertEquals("Select All", 3, results.size());
q = new QueryBuilder().select().from(TestObject1.class).where("key1", OPERAND.EQ, "1").build();
results = dao.query(q);
assertNotEquals("key1=", null, results);
assertEquals("key1=", 2, results.size());
q = new QueryBuilder().select().from(TestObject1.class).where("key1", OPERAND.GREATER_THAN, "1").build();
results = dao.query(q);
assertNotEquals("key1>", null, results);
assertEquals("key1>", 1, results.size());
q = new QueryBuilder().select().from(TestObject1.class).where("key1", OPERAND.GREATER_THAN_EQ, "1").build();
results = dao.query(q);
assertNotEquals("key1>=", null, results);
assertEquals("key1>=", 3, results.size());
q = new QueryBuilder().select().from(TestObject1.class).where("key1", OPERAND.LESS_THAN, "3").build();
results = dao.query(q);
assertNotEquals("key1<", null, results);
assertEquals("key1<", 2, results.size());
q = new QueryBuilder().select().from(TestObject1.class).where("key1", OPERAND.LESS_THAN_EQ, "3").build();
results = dao.query(q);
assertNotEquals("key1<=", null, results);
assertEquals("key1<=", 3, results.size());
q = new QueryBuilder().select().from(TestObject2.class).where("key1", OPERAND.EQ, "1").or("key2", OPERAND.EQ, "2").build();
results = dao.query(q);
assertNotEquals("2where", null, results);
assertEquals("2where", 1, results.size());
assertEquals("2where", testObject4.getObjectKey(), ObjectUtils.get1stOrNull(results).getObjectKey());
// limit
q = new QueryBuilder().select().from(TestObject1.class).where("key1", OPERAND.LESS_THAN_EQ, "3").limit(2).build();
results = dao.query(q);
assertNotEquals("limit test failed", null, results);
assertEquals("limit test failed", 2, results.size());
// q = new QueryBuilder().delete().from(TestObject1.class).where("key1",OPERAND.LESS_THAN_EQ,"3").build();
// results = dao.query(q);
// assertNotEquals("delete", null, results);
// assertEquals("delete test failed", 1, results.size());
// assertEquals("delete test failed", 3, (int)results.get(0).get(Integer.class,"count"));
//
// q = new QueryBuilder().delete().from(TestObject1.class).build();
// results = dao.query(q);
// assertNotEquals("delete test failed", null, results);
// assertEquals("delete test failed", 1, results.size());
// assertEquals("delete test failed", 0, (int)results.get(0).get(Integer.class,"count"));
// offset
}
Aggregations