Search in sources :

Example 1 with CompositeKey

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

the class EntityTypeParserTest method testGetKeyDataCompoundKey.

@Test
public void testGetKeyDataCompoundKey() {
    SimpleKey sk = new SimpleKey();
    sk.setName("name");
    sk.setRank(10);
    CompositeKey id = new CompositeKey();
    Date date = new Date();
    id.setKey(sk);
    id.setCreated(date);
    id.setEmail("email");
    EntityTypeMetadata meta = EntityTypeParser.getEntityMetadata(EntityWithCompositeKey.class);
    List<String> cols = meta.getPkColumns();
    assertEquals(6, cols.size());
    assertEquals("name", cols.get(0));
    assertEquals("rank", cols.get(1));
    assertEquals("t1", cols.get(2));
    assertEquals("t2", cols.get(3));
    assertEquals("created", cols.get(4));
    assertEquals("email", cols.get(5));
    List<Object> vals = meta.getIdValues(id);
    assertEquals(6, vals.size());
    assertEquals("name", vals.get(0));
    assertEquals(10, vals.get(1));
    assertEquals(date, vals.get(4));
    assertEquals("email", vals.get(5));
}
Also used : CompositeKey(com.datastax.driver.mapping.entity.CompositeKey) EntityWithCompositeKey(com.datastax.driver.mapping.entity.EntityWithCompositeKey) EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) Date(java.util.Date) SimpleKey(com.datastax.driver.mapping.entity.SimpleKey) Test(org.junit.Test)

Example 2 with CompositeKey

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

the class MappingSessionAsyncTest method saveAndGetAndDeleteWithCompoundCompositeKeyTest.

@Test
public void saveAndGetAndDeleteWithCompoundCompositeKeyTest() throws Exception {
    SimpleKey partition = new SimpleKey();
    partition.setName("name");
    partition.setRank(10);
    partition.setT1(UUIDs.timeBased());
    partition.setT2(UUIDs.timeBased());
    CompositeKey key = new CompositeKey();
    key.setKey(partition);
    Date created = new Date();
    key.setCreated(created);
    key.setEmail("email@at");
    EntityWithCompositeKey obj = new EntityWithCompositeKey();
    obj.setKey(key);
    obj.setTimestamp(1000);
    obj.setAsof(created);
    EntityWithCompositeKey loaded = target.get(EntityWithCompositeKey.class, key);
    assertNull(loaded);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCompositeKey.class, key);
    assertEquals(obj, loaded);
    f = target.deleteAsync(loaded);
    f.getUninterruptibly();
    loaded = target.get(EntityWithCompositeKey.class, key);
    assertNull(loaded);
}
Also used : CompositeKey(com.datastax.driver.mapping.entity.CompositeKey) EntityWithCompositeKey(com.datastax.driver.mapping.entity.EntityWithCompositeKey) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) EntityWithCompositeKey(com.datastax.driver.mapping.entity.EntityWithCompositeKey) Date(java.util.Date) SimpleKey(com.datastax.driver.mapping.entity.SimpleKey) Test(org.junit.Test)

Aggregations

CompositeKey (com.datastax.driver.mapping.entity.CompositeKey)2 EntityWithCompositeKey (com.datastax.driver.mapping.entity.EntityWithCompositeKey)2 SimpleKey (com.datastax.driver.mapping.entity.SimpleKey)2 Date (java.util.Date)2 Test (org.junit.Test)2 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)1 EntityTypeMetadata (com.datastax.driver.mapping.meta.EntityTypeMetadata)1