use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldSupportAnUDTElement.
@Test
public void shouldSupportAnUDTElement() {
ColumnEntity entity = ColumnEntity.of("users");
entity.add(Column.of("nickname", "Ioda"));
List<Column> columns = new ArrayList<>();
columns.add(Column.of("firstname", "Ioda"));
UDT udt = UDT.builder("fullname").withName("name").addUDT(columns).build();
entity.add(udt);
entityManager.insert(entity);
ColumnQuery query = select().from("users").where("nickname").eq("Ioda").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", "Ioda")));
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldFindAll.
@Test
public void shouldFindAll() {
ColumnEntity columnEntity = getColumnFamily();
entityManager.insert(columnEntity);
ColumnQuery query = select().from(columnEntity.getName()).build();
List<ColumnEntity> entities = entityManager.select(query);
assertFalse(entities.isEmpty());
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldSupportDate.
@Test
public void shouldSupportDate() {
ColumnEntity entity = ColumnEntity.of("history");
entity.add(Column.of("name", "World war II"));
ZoneId defaultZoneId = ZoneId.systemDefault();
Date dateEnd = Date.from(java.time.LocalDate.of(1945, Month.SEPTEMBER, 2).atStartOfDay(defaultZoneId).toInstant());
Calendar dataStart = Calendar.getInstance();
entity.add(Column.of("dataStart", LocalDate.fromYearMonthDay(1939, 9, 1)));
entity.add(Column.of("dateEnd", dateEnd));
entityManager.insert(entity);
ColumnQuery query = select().from("history").where("name").eq("World war II").build();
ColumnEntity entity1 = entityManager.singleResult(query).get();
assertNotNull(entity1);
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldDeleteColumnFamily.
@Test
public void shouldDeleteColumnFamily() {
entityManager.insert(getColumnFamily());
ColumnEntity.of(COLUMN_FAMILY, singletonList(Columns.of("id", 10L)));
ColumnQuery query = select().from(COLUMN_FAMILY).where("id").eq(10L).build();
ColumnDeleteQuery deleteQuery = delete().from(COLUMN_FAMILY).where("id").eq(10L).build();
entityManager.delete(deleteQuery);
List<ColumnEntity> entities = entityManager.cql("select * from newKeySpace.newColumnFamily where id=10;");
assertTrue(entities.isEmpty());
}
use of org.jnosql.diana.api.column.ColumnQuery in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldFindById.
@Test
public void shouldFindById() {
entityManager.insert(getColumnFamily());
ColumnQuery query = select().from(COLUMN_FAMILY).where("id").eq(10L).build();
List<ColumnEntity> columnEntity = entityManager.select(query);
assertFalse(columnEntity.isEmpty());
List<Column> columns = columnEntity.get(0).getColumns();
assertThat(columns.stream().map(Column::getName).collect(toList()), containsInAnyOrder("name", "version", "options", "id"));
assertThat(columns.stream().map(Column::getValue).map(Value::get).collect(toList()), containsInAnyOrder("Cassandra", 3.2, asList(1, 2, 3), 10L));
}
Aggregations