Search in sources :

Example 1 with SimpleKey

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

the class EntityTypeParserTest method testGetKeyDataSimpleKey.

@Test
public void testGetKeyDataSimpleKey() {
    SimpleKey sk = new SimpleKey();
    sk.setName("name");
    sk.setRank(10);
    EntityTypeMetadata meta = EntityTypeParser.getEntityMetadata(EntityWithKey.class);
    List<String> cols = meta.getPkColumns();
    assertEquals(4, cols.size());
    assertEquals("name", cols.get(0));
    assertEquals("rank", cols.get(1));
    assertEquals("t1", cols.get(2));
    assertEquals("t2", cols.get(3));
    List<Object> vals = meta.getIdValues(sk);
    assertEquals(4, vals.size());
    assertEquals("name", vals.get(0));
    assertEquals(10, vals.get(1));
}
Also used : EntityTypeMetadata(com.datastax.driver.mapping.meta.EntityTypeMetadata) SimpleKey(com.datastax.driver.mapping.entity.SimpleKey) Test(org.junit.Test)

Example 2 with SimpleKey

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

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

Example 4 with SimpleKey

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

the class MappingSessionAsyncTest method saveAndGetAndDeleteWithSimpleCompositeKeyTest.

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

Aggregations

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