Search in sources :

Example 26 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method saveEntityWithStringEnumTest.

@Test
public void saveEntityWithStringEnumTest() throws Exception {
    UUID uuid = UUID.randomUUID();
    EntityWithStringEnum obj = new EntityWithStringEnum();
    obj.setId(uuid);
    obj.setPage(Page.GITHUB);
    EntityWithStringEnum loaded = target.get(EntityWithStringEnum.class, uuid);
    assertNull(loaded);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    loaded = target.get(EntityWithStringEnum.class, uuid);
    assertEquals(obj, loaded);
    obj.setPage(Page.CASSANDRA);
    f = target.saveAsync(obj);
    f.getUninterruptibly();
    loaded = target.get(EntityWithStringEnum.class, uuid);
    assertEquals(obj, loaded);
    f = target.deleteAsync(loaded);
    f.getUninterruptibly();
    loaded = target.get(EntityWithStringEnum.class, uuid);
    assertNull(loaded);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) UUID(java.util.UUID) EntityWithStringEnum(com.datastax.driver.mapping.entity.EntityWithStringEnum) Test(org.junit.Test)

Example 27 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method appendAllToListTest.

@Test
public void appendAllToListTest() throws Exception {
    UUID id = UUID.randomUUID();
    EntityWithCollections obj = new EntityWithCollections();
    obj.setId(id);
    List<Integer> trades = new ArrayList<Integer>();
    trades.add(1);
    trades.add(2);
    obj.setTrades(trades);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
    assertEquals(2, loaded.getTrades().size());
    List<Integer> adds = new ArrayList<Integer>();
    adds.add(5);
    adds.add(6);
    f = target.appendAsync(id, EntityWithCollections.class, "trades", adds);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertTrue(loaded.getTrades().contains(5));
    assertEquals(4, loaded.getTrades().size());
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) ArrayList(java.util.ArrayList) EntityWithCollections(com.datastax.driver.mapping.entity.EntityWithCollections) UUID(java.util.UUID) Test(org.junit.Test)

Example 28 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method saveAndGetAndDeleteMixedCaseTest.

@Test
public void saveAndGetAndDeleteMixedCaseTest() throws Exception {
    int id = 12245;
    EntityMixedCase obj = new EntityMixedCase();
    obj.setId(id);
    obj.setFirstName("firstName");
    obj.setLastName("lastName");
    obj.setAge(25);
    EntityMixedCase loaded = target.get(EntityMixedCase.class, id);
    assertNull(loaded);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    loaded = target.get(EntityMixedCase.class, id);
    assertEquals(obj, loaded);
    f = target.deleteAsync(loaded);
    f.getUninterruptibly();
    loaded = target.get(EntityMixedCase.class, id);
    assertNull(loaded);
}
Also used : EntityMixedCase(com.datastax.driver.mapping.entity.EntityMixedCase) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Test(org.junit.Test)

Example 29 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method updateIndividualPropertyTest.

@Test
public void updateIndividualPropertyTest() throws Exception {
    UUID uuid = UUID.randomUUID();
    Simple obj = new Simple();
    obj.setName("myName");
    obj.setAge(55);
    obj.setId(uuid);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    f = target.updateValueAsync(uuid, Simple.class, "name", "yourName");
    f.getUninterruptibly();
    f = target.updateValueAsync(uuid, Simple.class, "age", 25);
    f.getUninterruptibly();
    Simple loaded = target.get(Simple.class, uuid);
    assertEquals(25, loaded.getAge());
    assertEquals("yourName", loaded.getName());
    // String-Enum
    EntityWithStringEnum seobj = new EntityWithStringEnum();
    seobj.setId(uuid);
    seobj.setPage(Page.DATASTAX);
    f = target.saveAsync(seobj);
    f.getUninterruptibly();
    f = target.updateValueAsync(uuid, EntityWithStringEnum.class, "page", Page.CASSANDRA.toString());
    f.getUninterruptibly();
    EntityWithStringEnum eloaded = target.get(EntityWithStringEnum.class, uuid);
    assertEquals(Page.CASSANDRA, Page.getPage(eloaded.getPage()));
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) UUID(java.util.UUID) EntityWithStringEnum(com.datastax.driver.mapping.entity.EntityWithStringEnum) Simple(com.datastax.driver.mapping.entity.Simple) Test(org.junit.Test)

Example 30 with ResultSetFuture

use of com.datastax.driver.core.ResultSetFuture in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method testCollections.

@Test
public void testCollections() throws Exception {
    EntityWithCollections obj = new EntityWithCollections();
    UUID uuid = UUID.randomUUID();
    obj.setId(uuid);
    target.save(obj);
    EntityWithCollections loaded = target.get(EntityWithCollections.class, uuid);
    Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
    map.put("key1", new BigDecimal(100.55));
    map.put("key1", new BigDecimal(100.55555));
    map.put("key1", new BigDecimal(101.5500000333));
    obj.setRates(map);
    List<Integer> list = new ArrayList<Integer>();
    list.add(100);
    list.add(200);
    list.add(300);
    obj.setTrades(list);
    Set<String> set = new HashSet<String>();
    set.add("100");
    set.add("200");
    set.add("300");
    obj.setRefs(set);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, uuid);
    assertEquals(obj, loaded);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EntityWithCollections(com.datastax.driver.mapping.entity.EntityWithCollections) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ResultSetFuture (com.datastax.driver.core.ResultSetFuture)78 Test (org.junit.Test)35 UUID (java.util.UUID)26 ResultSet (com.datastax.driver.core.ResultSet)20 EntityWithCollections (com.datastax.driver.mapping.entity.EntityWithCollections)13 BoundStatement (com.datastax.driver.core.BoundStatement)12 PreparedStatement (com.datastax.driver.core.PreparedStatement)10 ArrayList (java.util.ArrayList)8 Date (java.util.Date)8 Row (com.datastax.driver.core.Row)7 Statement (com.datastax.driver.core.Statement)7 List (java.util.List)6 Session (com.datastax.driver.core.Session)5 Simple (com.datastax.driver.mapping.entity.Simple)5 Cell (com.palantir.atlasdb.keyvalue.api.Cell)5 BigDecimal (java.math.BigDecimal)5 HashSet (java.util.HashSet)5 Result (com.datastax.driver.mapping.Result)4 WriteOptions (com.datastax.driver.mapping.option.WriteOptions)4 Nullable (javax.annotation.Nullable)4