Search in sources :

Example 1 with EntityWithStringEnum

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

the class MappingSessionAsyncTest method saveEntityWithStringEnumTest.

@Test
public void saveEntityWithStringEnumTest() throws Exception {
    UUID uuid = UUID.randomUUID();
    EntityWithStringEnum obj = new EntityWithStringEnum();
    obj.setId(uuid);
    obj.setPage(Page.GITHUB);
    EntityWithStringEnum loaded = target.get(EntityWithStringEnum.class, uuid);
    assertNull(loaded);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    loaded = target.get(EntityWithStringEnum.class, uuid);
    assertEquals(obj, loaded);
    obj.setPage(Page.CASSANDRA);
    f = target.saveAsync(obj);
    f.getUninterruptibly();
    loaded = target.get(EntityWithStringEnum.class, uuid);
    assertEquals(obj, loaded);
    f = target.deleteAsync(loaded);
    f.getUninterruptibly();
    loaded = target.get(EntityWithStringEnum.class, uuid);
    assertNull(loaded);
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) UUID(java.util.UUID) EntityWithStringEnum(com.datastax.driver.mapping.entity.EntityWithStringEnum) Test(org.junit.Test)

Example 2 with EntityWithStringEnum

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

the class MappingSessionAsyncTest method updateIndividualPropertyTest.

@Test
public void updateIndividualPropertyTest() throws Exception {
    UUID uuid = UUID.randomUUID();
    Simple obj = new Simple();
    obj.setName("myName");
    obj.setAge(55);
    obj.setId(uuid);
    ResultSetFuture f = target.saveAsync(obj);
    f.getUninterruptibly();
    f = target.updateValueAsync(uuid, Simple.class, "name", "yourName");
    f.getUninterruptibly();
    f = target.updateValueAsync(uuid, Simple.class, "age", 25);
    f.getUninterruptibly();
    Simple loaded = target.get(Simple.class, uuid);
    assertEquals(25, loaded.getAge());
    assertEquals("yourName", loaded.getName());
    // String-Enum
    EntityWithStringEnum seobj = new EntityWithStringEnum();
    seobj.setId(uuid);
    seobj.setPage(Page.DATASTAX);
    f = target.saveAsync(seobj);
    f.getUninterruptibly();
    f = target.updateValueAsync(uuid, EntityWithStringEnum.class, "page", Page.CASSANDRA.toString());
    f.getUninterruptibly();
    EntityWithStringEnum eloaded = target.get(EntityWithStringEnum.class, uuid);
    assertEquals(Page.CASSANDRA, Page.getPage(eloaded.getPage()));
}
Also used : ResultSetFuture(com.datastax.driver.core.ResultSetFuture) UUID(java.util.UUID) EntityWithStringEnum(com.datastax.driver.mapping.entity.EntityWithStringEnum) Simple(com.datastax.driver.mapping.entity.Simple) Test(org.junit.Test)

Aggregations

ResultSetFuture (com.datastax.driver.core.ResultSetFuture)2 EntityWithStringEnum (com.datastax.driver.mapping.entity.EntityWithStringEnum)2 UUID (java.util.UUID)2 Test (org.junit.Test)2 Simple (com.datastax.driver.mapping.entity.Simple)1