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));
}
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));
}
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);
}
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);
}
Aggregations