Search in sources :

Example 11 with TransientObject

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);
}
Also used : DAO(io.divide.shared.server.DAO) TypeLiteral(com.google.inject.TypeLiteral) MockKeyManager(io.divide.client.auth.MockKeyManager) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) TransientObject(io.divide.shared.transitory.TransientObject) MockKeyManager(io.divide.client.auth.MockKeyManager) KeyManager(io.divide.shared.server.KeyManager)

Example 12 with TransientObject

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);
        }
    }
}
Also used : TransientObject(io.divide.shared.transitory.TransientObject) CommitExpection(iBoxDB.LocalServer.E.CommitExpection)

Example 13 with TransientObject

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);
}
Also used : Query(io.divide.shared.transitory.query.Query) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) QueryBuilder(io.divide.shared.transitory.query.QueryBuilder) TransientObject(io.divide.shared.transitory.TransientObject) Test(org.junit.Test)

Example 14 with TransientObject

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
}
Also used : Query(io.divide.shared.transitory.query.Query) TransientObject(io.divide.shared.transitory.TransientObject) QueryBuilder(io.divide.shared.transitory.query.QueryBuilder) Test(org.junit.Test)

Example 15 with TransientObject

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);
}
Also used : TransientObject(io.divide.shared.transitory.TransientObject) Test(org.junit.Test)

Aggregations

TransientObject (io.divide.shared.transitory.TransientObject)21 QueryBuilder (io.divide.shared.transitory.query.QueryBuilder)10 Query (io.divide.shared.transitory.query.Query)9 Test (org.junit.Test)6 OTransaction (com.orientechnologies.orient.core.tx.OTransaction)3 NotImplementedException (sun.reflect.generics.reflectiveObjects.NotImplementedException)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 ServerTest (io.divide.server.ServerTest)2 DAOException (io.divide.shared.server.DAO.DAOException)2 Credentials (io.divide.shared.transitory.Credentials)2 AuthTokenUtils (io.divide.shared.util.AuthTokenUtils)2 PublicKey (java.security.PublicKey)2 ArrayList (java.util.ArrayList)2 JerseyTest (org.glassfish.jersey.test.JerseyTest)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 TypeLiteral (com.google.inject.TypeLiteral)1 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)1 CommitExpection (iBoxDB.LocalServer.E.CommitExpection)1 MockKeyManager (io.divide.client.auth.MockKeyManager)1