use of jakarta.nosql.Sort 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.Sort in project jnosql-diana-driver by eclipse.
the class QueryOSQLConverter method appendSort.
private static void appendSort(List<Sort> sorts, StringBuilder query) {
query.append(SORT);
String separator = SPACE;
for (Sort sort : sorts) {
query.append(separator).append(sort.getName()).append(SPACE).append(sort.getType());
separator = ", ";
}
}
use of jakarta.nosql.Sort in project jnosql-diana by eclipse.
the class DynamicReturnTest method shouldShouldFindSortAtMethod.
@Test
public void shouldShouldFindSortAtMethod() {
Sort name = Sort.asc("name");
Sort age = Sort.desc("age");
List<Sort> sorts = DynamicReturn.findSorts(new Object[] { "Otavio", 23, Pagination.page(2).size(2), name, age });
assertThat(sorts, Matchers.contains(name, age));
}
use of jakarta.nosql.Sort in project jnosql-diana by eclipse.
the class DynamicReturnTest method shouldShouldFindSortsAtMethod.
@Test
public void shouldShouldFindSortsAtMethod() {
Sort name = Sort.asc("name");
Sort age = Sort.desc("age");
List<Sort> sorts = DynamicReturn.findSorts(new Object[] { "Otavio", 23, Pagination.page(2).size(2), sorts().add(name).add(age) });
assertThat(sorts, Matchers.contains(name, age));
}
use of jakarta.nosql.Sort in project jnosql-diana by eclipse.
the class DocumentRepositoryProxyTest method shouldFindBySalary_CurrencyOrderByCurrency_Name.
@Test
public void shouldFindBySalary_CurrencyOrderByCurrency_Name() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
personRepository.findBySalary_CurrencyOrderByCurrency_Name("USD");
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
verify(template).select(captor.capture());
DocumentQuery query = captor.getValue();
DocumentCondition condition = query.getCondition().get();
final Sort sort = query.getSorts().get(0);
final Document document = condition.getDocument();
assertEquals("Person", query.getDocumentCollection());
assertEquals("salary.currency", document.getName());
assertEquals("currency.name", sort.getName());
}
Aggregations