use of jakarta.nosql.column.ColumnQuery in project jnosql-diana by eclipse.
the class SelectQueryParser method getColumnQuery.
private ColumnQuery getColumnQuery(Params params, SelectQuery selectQuery, ColumnObserverParser observer) {
String columnFamily = observer.fireEntity(selectQuery.getEntity());
long limit = selectQuery.getLimit();
long skip = selectQuery.getSkip();
List<String> columns = selectQuery.getFields().stream().map(f -> observer.fireField(columnFamily, f)).collect(Collectors.toList());
List<Sort> sorts = selectQuery.getOrderBy().stream().map(s -> toSort(s, observer, columnFamily)).collect(toList());
ColumnCondition condition = null;
if (selectQuery.getWhere().isPresent()) {
condition = selectQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, columnFamily)).get();
}
return new DefaultColumnQuery(limit, skip, columnFamily, columns, sorts, condition);
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana by eclipse.
the class SelectQueryParser method getColumnQuery.
private ColumnQuery getColumnQuery(String query, ColumnObserverParser observer) {
SelectQuery selectQuery = selectQueryProvider.apply(query);
String columnFamily = observer.fireEntity(selectQuery.getEntity());
long limit = selectQuery.getLimit();
long skip = selectQuery.getSkip();
List<String> columns = selectQuery.getFields().stream().map(f -> observer.fireField(columnFamily, f)).collect(Collectors.toList());
List<Sort> sorts = selectQuery.getOrderBy().stream().map(s -> toSort(s, observer, columnFamily)).collect(toList());
ColumnCondition condition = null;
Params params = Params.newParams();
if (selectQuery.getWhere().isPresent()) {
condition = selectQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, columnFamily)).get();
}
if (params.isNotEmpty()) {
throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
}
return new DefaultColumnQuery(limit, skip, columnFamily, columns, sorts, condition);
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana by eclipse.
the class ColumnRepositoryProxyTest method shouldFindBySalary_Currency.
@Test
public void shouldFindBySalary_Currency() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
personRepository.findBySalary_Currency("USD");
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
verify(template).select(captor.capture());
ColumnQuery query = captor.getValue();
ColumnCondition condition = query.getCondition().get();
final Column column = condition.getColumn();
assertEquals("Person", query.getColumnFamily());
assertEquals("salary.currency", column.getName());
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana by eclipse.
the class ColumnRepositoryProxyTest method shouldFindByIn.
@Test
public void shouldFindByIn() {
Vendor vendor = new Vendor("vendor");
vendor.setPrefixes(Collections.singleton("prefix"));
when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(vendor));
vendorRepository.findByPrefixesIn(singletonList("prefix"));
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
verify(template).singleResult(captor.capture());
ColumnQuery query = captor.getValue();
ColumnCondition condition = query.getCondition().get();
assertEquals("vendors", query.getColumnFamily());
assertEquals(IN, condition.getCondition());
}
use of jakarta.nosql.column.ColumnQuery in project jnosql-diana by eclipse.
the class ColumnRepositoryProxyTest method shouldFindBySalary_CurrencyAndSalary_Value.
@Test
public void shouldFindBySalary_CurrencyAndSalary_Value() {
Person ada = Person.builder().withAge(20).withName("Ada").build();
when(template.select(any(ColumnQuery.class))).thenReturn(Stream.of(ada));
personRepository.findBySalary_CurrencyAndSalary_Value("USD", BigDecimal.TEN);
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
verify(template).select(captor.capture());
ColumnQuery query = captor.getValue();
ColumnCondition condition = query.getCondition().get();
final Column column = condition.getColumn();
final List<ColumnCondition> conditions = column.get(new TypeReference<List<ColumnCondition>>() {
});
final List<String> names = conditions.stream().map(ColumnCondition::getColumn).map(Column::getName).collect(Collectors.toList());
assertEquals("Person", query.getColumnFamily());
MatcherAssert.assertThat(names, Matchers.containsInAnyOrder("salary.currency", "salary.value"));
}
Aggregations