use of jakarta.nosql.column.ColumnQuery in project jnosql-diana-driver by eclipse.
the class QueryUtils method select.
public static Select select(ColumnQuery query, String keyspace) {
String columnFamily = query.getColumnFamily();
final List<String> columns = query.getColumns();
Select select = null;
if (columns.isEmpty()) {
select = QueryBuilder.selectFrom(keyspace, columnFamily).all();
} else {
select = QueryBuilder.selectFrom(keyspace, columnFamily).columns(columns);
}
select = select.where(Relations.createClause(query.getCondition().orElse(null)));
final Map<String, ClusteringOrder> sort = query.getSorts().stream().collect(Collectors.toMap(s -> s.getName(), mapSort()));
select = select.orderBy(sort);
return select;
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana-driver by eclipse.
the class HBaseColumnFamilyManagerTest method shouldFindInBatch.
@Test
public void shouldFindInBatch() {
columnFamilyManager.insert(createEntity());
columnFamilyManager.insert(createEntity2());
ColumnQuery query = select().from(FAMILY).where(ID_FIELD).eq("otaviojava").or(ID_FIELD).eq("poliana").build();
List<ColumnEntity> entities = columnFamilyManager.select(query).collect(Collectors.toList());
assertEquals(Integer.valueOf(2), Integer.valueOf(entities.size()));
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana-driver by eclipse.
the class HBaseColumnFamilyManagerTest method shouldFind.
@Test
public void shouldFind() {
columnFamilyManager.insert(createEntity());
ColumnQuery query = select().from(FAMILY).where(ID_FIELD).eq("otaviojava").build();
List<ColumnEntity> columnFamilyEntities = columnFamilyManager.select(query).collect(Collectors.toList());
assertNotNull(columnFamilyEntities);
assertFalse(columnFamilyEntities.isEmpty());
ColumnEntity entity = columnFamilyEntities.get(0);
assertEquals(FAMILY, entity.getName());
assertThat(entity.getColumns(), containsInAnyOrder(Column.of(ID_FIELD, "otaviojava"), Column.of("age", "26"), Column.of("country", "Brazil")));
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana-driver by eclipse.
the class HBaseColumnFamilyManagerTest method shouldDeleteEntities.
@Test
public void shouldDeleteEntities() {
columnFamilyManager.insert(createEntity());
columnFamilyManager.insert(createEntity2());
ColumnQuery query = select().from(FAMILY).where(ID_FIELD).eq("otaviojava").or(ID_FIELD).eq("poliana").build();
ColumnDeleteQuery deleteQuery = delete().from(FAMILY).where(ID_FIELD).eq("otaviojava").or(ID_FIELD).eq("poliana").build();
columnFamilyManager.delete(deleteQuery);
List<ColumnEntity> entities = columnFamilyManager.select(query).collect(Collectors.toList());
assertTrue(entities.isEmpty());
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana-driver by eclipse.
the class HBaseColumnFamilyManagerTest method shouldDeleteEntity.
@Test
public void shouldDeleteEntity() {
columnFamilyManager.insert(createEntity());
ColumnQuery query = select().from(FAMILY).where(ID_FIELD).eq("otaviojava").build();
ColumnDeleteQuery deleteQuery = delete().from(FAMILY).where(ID_FIELD).eq("otaviojava").build();
columnFamilyManager.delete(deleteQuery);
List<ColumnEntity> entities = columnFamilyManager.select(query).collect(Collectors.toList());
assertTrue(entities.isEmpty());
}
Aggregations