use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldSupportUDT.
@Test
public void shouldSupportUDT() {
ColumnEntity entity = ColumnEntity.of("users");
entity.add(Column.of("nickname", "ada"));
List<Column> columns = new ArrayList<>();
columns.add(Column.of("firstname", "Ada"));
columns.add(Column.of("lastname", "Lovelace"));
UDT udt = UDT.builder("fullname").withName("name").addUDT(columns).build();
entity.add(udt);
entityManager.insert(entity);
ColumnQuery query = select().from("users").build();
ColumnEntity columnEntity = entityManager.singleResult(query).get();
Column column = columnEntity.find("name").get();
udt = UDT.class.cast(column);
List<Column> udtColumns = (List<Column>) udt.get();
assertEquals("name", udt.getName());
assertEquals("fullname", udt.getUserType());
assertThat(udtColumns, Matchers.containsInAnyOrder(Column.of("firstname", "Ada"), Column.of("lastname", "Lovelace")));
}
use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldUpdateColumn.
@Test
public void shouldUpdateColumn() {
ColumnEntity columnEntity = getColumnFamily();
entityManager.update(columnEntity);
}
use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldDeleteColumnFamilyWithConsistencyLevel.
@Test
public void shouldDeleteColumnFamilyWithConsistencyLevel() {
entityManager.insert(getColumnFamily());
ColumnEntity.of(COLUMN_FAMILY, singletonList(Columns.of("id", 10L)));
ColumnDeleteQuery deleteQuery = delete().from(COLUMN_FAMILY).where("id").eq(10L).build();
entityManager.delete(deleteQuery, CONSISTENCY_LEVEL);
List<ColumnEntity> entities = entityManager.cql("select * from newKeySpace.newColumnFamily where id=10;");
assertTrue(entities.isEmpty());
}
use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldReturnSingleResult.
@Test
public void shouldReturnSingleResult() {
ColumnEntity columnEntity = getColumnFamily();
entityManager.insert(columnEntity);
ColumnQuery query = select().from(columnEntity.getName()).where("id").eq(10L).build();
Optional<ColumnEntity> entity = entityManager.singleResult(query);
query = select().from(columnEntity.getName()).where("id").eq(-10L).build();
entity = entityManager.singleResult(query);
assertFalse(entity.isPresent());
}
use of org.jnosql.diana.api.column.ColumnEntity in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldReturnListUDT.
@Test
public void shouldReturnListUDT() {
ColumnEntity entity = createEntityWithIterable();
entityManager.insert(entity);
ColumnQuery query = select().from("contacts").where("user").eq("otaviojava").build();
ColumnEntity columnEntity = entityManager.singleResult(query).get();
List<List<Column>> names = (List<List<Column>>) columnEntity.find("names").get().get();
assertEquals(3, names.size());
assertTrue(names.stream().allMatch(n -> n.size() == 2));
}
Aggregations