Search in sources :

Example 6 with EntityWithCollections

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

the class MappingSessionAsyncTest method deleteTest.

@Test
public void deleteTest() 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());
    f = target.deleteValueAsync(id, EntityWithCollections.class, "rates");
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertEquals(0, 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)

Example 7 with EntityWithCollections

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

the class MappingSessionAsyncTest method appendAtTest.

@Test
public void appendAtTest() throws Exception {
    UUID id = UUID.randomUUID();
    EntityWithCollections obj = new EntityWithCollections();
    obj.setId(id);
    List<Integer> trades = new ArrayList<Integer>();
    trades.add(100);
    trades.add(200);
    trades.add(300);
    obj.setTrades(trades);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
    assertEquals(3, loaded.getTrades().size());
    f = target.replaceAtAsync(id, EntityWithCollections.class, "trades", 3, 0);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertEquals(new Integer(3), loaded.getTrades().get(0));
    assertEquals(3, loaded.getTrades().size());
    f = target.replaceAtAsync(id, EntityWithCollections.class, "trades", 33, 2);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertEquals(new Integer(33), loaded.getTrades().get(2));
    assertEquals(3, loaded.getTrades().size());
    f = target.replaceAtAsync(id, EntityWithCollections.class, "trades", 22, 1);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertEquals(new Integer(22), loaded.getTrades().get(1));
    assertEquals(3, 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 8 with EntityWithCollections

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

the class MappingSessionAsyncTest method prependTest.

@Test
public void prependTest() 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.prependAsync(id, EntityWithCollections.class, "trades", adds);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertEquals(new Integer(6), loaded.getTrades().get(0));
    assertEquals(new Integer(5), loaded.getTrades().get(1));
    assertEquals(new Integer(1), loaded.getTrades().get(2));
    assertEquals(new Integer(2), loaded.getTrades().get(3));
    f = target.prependAsync(id, EntityWithCollections.class, "trades", 10);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertEquals(new Integer(10), loaded.getTrades().get(0));
}
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 9 with EntityWithCollections

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

the class MappingSessionAsyncTest method addToListTest.

@Test
public void addToListTest() throws Exception {
    UUID id = UUID.randomUUID();
    EntityWithCollections obj = new EntityWithCollections();
    obj.setId(id);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
    assertEquals(0, loaded.getTrades().size());
    loaded.addTrade(200);
    f = target.saveAsync(loaded);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertTrue(loaded.getTrades().contains(200));
    assertEquals(1, loaded.getTrades().size());
    loaded.addTrade(300);
    f = target.saveAsync(loaded);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertTrue(loaded.getTrades().contains(300));
    assertEquals(2, loaded.getTrades().size());
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) EntityWithCollections(com.datastax.driver.mapping.entity.EntityWithCollections) UUID(java.util.UUID) Test(org.junit.Test)

Example 10 with EntityWithCollections

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

the class MappingSessionAsyncTest method addToMapTest.

@Test
public void addToMapTest() throws Exception {
    UUID id = UUID.randomUUID();
    EntityWithCollections obj = new EntityWithCollections();
    obj.setId(id);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    EntityWithCollections loaded = target.get(EntityWithCollections.class, id);
    assertEquals(0, loaded.getRates().size());
    loaded.addRate("200", new BigDecimal("100"));
    f = target.saveAsync(loaded);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertTrue(loaded.getRates().containsKey("200"));
    assertEquals(1, loaded.getRates().size());
    loaded.addRate("300", new BigDecimal("300"));
    f = target.saveAsync(loaded);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCollections.class, id);
    assertTrue(loaded.getRates().containsKey("300"));
    assertEquals(2, loaded.getRates().size());
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) 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