Search in sources :

Example 1 with EntityWithCollections

use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method appendToListTest.

@Test
public void appendToListTest() 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());
    f = target.appendAsync(id, EntityWithCollections.class, "trades", 3);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertTrue(loaded.getTrades().contains(3));
    assertEquals(new Integer(3), loaded.getTrades().get(2));
}
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 2 with EntityWithCollections

use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method appendAllToSetTest.

@Test
public void appendAllToSetTest() throws Exception {
    UUID id = UUID.randomUUID();
    EntityWithCollections obj = new EntityWithCollections();
    obj.setId(id);
    Set<String> refs = new HashSet<String>();
    refs.add("100");
    refs.add("abc");
    obj.setRefs(refs);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
    assertEquals(2, loaded.getRefs().size());
    Set<String> adds = new HashSet<String>();
    adds.add("fgdsfgdsfgd");
    adds.add("200");
    f = target.appendAsync(id, EntityWithCollections.class, "refs", adds);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertTrue(loaded.getRefs().contains("fgdsfgdsfgd"));
    assertEquals(4, loaded.getRefs().size());
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) EntityWithCollections(com.datastax.driver.mapping.entity.EntityWithCollections) UUID(java.util.UUID) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with EntityWithCollections

use of com.datastax.driver.mapping.entity.EntityWithCollections 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 4 with EntityWithCollections

use of com.datastax.driver.mapping.entity.EntityWithCollections 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)

Example 5 with EntityWithCollections

use of com.datastax.driver.mapping.entity.EntityWithCollections in project cassandra-driver-mapping by valchkou.

the class MappingSessionAsyncTest method appendToMapTest.

@Test
public void appendToMapTest() throws Exception {
    UUID id = UUID.randomUUID();
    EntityWithCollections obj = new EntityWithCollections();
    obj.setId(id);
    Map<String, BigDecimal> rates = new HashMap<String, BigDecimal>();
    rates.put("abc", new BigDecimal(100));
    rates.put("cde", new BigDecimal(10000.554154));
    obj.setRates(rates);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
    assertEquals(2, loaded.getRates().size());
    Map<String, BigDecimal> add = new HashMap<String, BigDecimal>();
    add.put("bcd", new BigDecimal(0.000005555));
    f = target.appendAsync(id, EntityWithCollections.class, "rates", add);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertTrue(loaded.getRates().containsKey("bcd"));
    assertEquals(new BigDecimal(0.000005555), loaded.getRates().get("bcd"));
    assertEquals(3, loaded.getRates().size());
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) HashMap(java.util.HashMap) EntityWithCollections(com.datastax.driver.mapping.entity.EntityWithCollections) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

ResultSetFuture (com.datastax.driver.core.ResultSetFuture)13 EntityWithCollections (com.datastax.driver.mapping.entity.EntityWithCollections)13 UUID (java.util.UUID)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)5 BigDecimal (java.math.BigDecimal)4 HashSet (java.util.HashSet)4 HashMap (java.util.HashMap)3 WriteOptions (com.datastax.driver.mapping.option.WriteOptions)1