use of jakarta.nosql.column.Column in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method shouldFindById.
@Test
public void shouldFindById() {
entityManager.insert(getColumnFamily());
ColumnQuery query = select().from(Constants.COLUMN_FAMILY).where("id").eq(10L).build();
List<ColumnEntity> columnEntity = entityManager.select(query).collect(toList());
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));
}
use of jakarta.nosql.column.Column in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method getEntities.
private List<ColumnEntity> getEntities() {
Map<String, Object> fields = new HashMap<>();
fields.put("name", "Cassandra");
fields.put("version", 3.2);
fields.put("options", asList(1, 2, 3));
List<Column> columns = Columns.of(fields);
ColumnEntity entity = ColumnEntity.of(Constants.COLUMN_FAMILY, singletonList(Columns.of("id", 1L)));
ColumnEntity entity1 = ColumnEntity.of(Constants.COLUMN_FAMILY, singletonList(Columns.of("id", 2L)));
ColumnEntity entity2 = ColumnEntity.of(Constants.COLUMN_FAMILY, singletonList(Columns.of("id", 3L)));
columns.forEach(entity::add);
columns.forEach(entity1::add);
columns.forEach(entity2::add);
return asList(entity, entity1, entity2);
}
use of jakarta.nosql.column.Column 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));
}
use of jakarta.nosql.column.Column in project jnosql-diana-driver by eclipse.
the class CassandraColumnFamilyManagerTest method getColumnFamily.
private ColumnEntity getColumnFamily() {
Map<String, Object> fields = new HashMap<>();
fields.put("name", "Cassandra");
fields.put("version", 3.2);
fields.put("options", asList(1, 2, 3));
List<Column> columns = Columns.of(fields);
ColumnEntity columnFamily = ColumnEntity.of(Constants.COLUMN_FAMILY, singletonList(Columns.of("id", 10L)));
columns.forEach(columnFamily::add);
return columnFamily;
}
use of jakarta.nosql.column.Column 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")));
}
Aggregations