use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.
the class MockAndroidModule method additionalConfig.
@Override
protected void additionalConfig(AndroidConfig config) {
super.additionalConfig(config);
// ORDER MATTER
try {
bind(KeyManager.class).toInstance(new MockKeyManager("someKey"));
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
bind(new TypeLiteral<DAO<TransientObject, TransientObject>>() {
}).to(new TypeLiteral<MockLocalStorage<TransientObject, TransientObject>>() {
}).in(Singleton.class);
}
use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.
the class LocalStorageIBoxDb method save.
@Override
public void save(T1... objects) throws DAOException {
for (TransientObject b : objects) {
try {
boolean exists = exists(b);
System.out.println("Exists: " + exists);
if (exists) {
System.out.println("update: " + b.getObjectKey());
box.update("Wrapper", new Wrapper(b));
} else {
System.out.println("insert: " + b.getObjectKey());
box.insert("Wrapper", new Wrapper(b));
}
} catch (CommitExpection e) {
e.printStackTrace();
throw new DAOException(e);
}
}
}
use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.
the class DAOTest method testQueryEmbededCollections.
// [TransientObject{
// user_data={players_key=[2]}
// , meta_data={object_type=com.jug6ernaut.tactics.client.web.WGame, getKey()=049d74c7-511c-49ef-a312-3a782f2f41e3, create_date_key=1384732193542, modified_date_key=1384732193543}
// }]
// [TestObject1{
// user_data={players_key=[2]}
// , meta_data={object_type=io.divide.authenticator.se, create_date_key=1384733366530, getKey()=e842d295-cee8-45da-83df-d235f5b1801f, modified_date_key=1384733366530}
// }]
@Test
public void testQueryEmbededCollections() throws Exception {
TestObject1 t1 = new TestObject1();
List<String> l1 = Arrays.asList("2");
t1.put("players_key", l1);
System.out.println("embeded: " + Arrays.asList(t1));
TestObject1 t2 = new TestObject1();
List<String> l2 = Arrays.asList("3", "4", "5");
t2.put("players_key", l2);
dao.save(t1, t2);
Query q = new QueryBuilder().select().from(TestObject1.class).where("players_key", OPERAND.CONTAINS, "2").build();
List<TransientObject> results = dao.query(q);
assertNotEquals(null, results);
assertEquals(1, results.size());
assertEquals(t1.getObjectKey(), ObjectUtils.get1stOrNull(results).getObjectKey());
assertEquals(l1, ObjectUtils.get1stOrNull(results).get(l1.getClass(), "players_key"));
q = new QueryBuilder().select().from(TestObject1.class).where("players_key", OPERAND.CONTAINS, "4").build();
results = dao.query(q);
assertNotEquals(null, results);
assertEquals(1, results.size());
assertEquals(t2.getObjectKey(), ObjectUtils.get1stOrNull(results).getObjectKey());
assertEquals(l2, ObjectUtils.get1stOrNull(results).get(l2.getClass(), "players_key"));
Gson g = new GsonBuilder().create();
g.fromJson(g.toJson(t1), TransientObject.class);
}
use of io.divide.shared.transitory.TransientObject 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
}
use of io.divide.shared.transitory.TransientObject in project divide by HiddenStage.
the class DAOTest method testSave.
@Test
public void testSave() throws Exception {
dao.save(testObject1, testObject2);
String testObject1Table = Query.safeTable(TestObject1.class);
Collection<TransientObject> results = dao.get(testObject1Table, testObject1.getObjectKey(), testObject2.getObjectKey());
assertNotEquals(null, results);
assertEquals(String.valueOf(results), 2, results.size());
assertEquals(null, testObject1.get(String.class, "someKey"));
testObject1.put("someKey", "someValue");
dao.save(testObject1);
// dao.query(new QueryBuilder().select().from(TestObject1.class).where(TransientObject.OBJECT_KEY, OPERAND.EQ, testObject1.getObjectKey()).build());
Collection<TransientObject> objects = dao.get(testObject1Table, testObject1.getObjectKey());
assertEquals("Returned wrong number of objects", 1, objects.size());
TransientObject o = ObjectUtils.get1stOrNull(objects);
assertEquals("Value not updated", "someValue", o.get(String.class, "someKey"));
String bigString = CharBuffer.allocate(600).toString();
testObject1.put("big_string", bigString);
dao.save(testObject1);
}
Aggregations