use of org.jnosql.diana.api.Condition in project jnosql-artemis by eclipse.
the class ColumnRepositoryAsyncProxyTest method shoudFindByNameSortPagination.
@Test
public void shoudFindByNameSortPagination() {
Consumer<List<Person>> callback = v -> {
};
Sort sort = Sort.of("age", Sort.SortType.ASC);
Pagination pagination = Pagination.of(10, 20);
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
personRepository.findByName("name", sort, pagination, callback);
verify(template).select(captor.capture(), consumerCaptor.capture());
ColumnQuery query = captor.getValue();
ColumnCondition condition = query.getCondition().get();
assertEquals("Person", query.getColumnFamily());
assertEquals(Condition.EQUALS, condition.getCondition());
assertEquals(Column.of("name", "name"), condition.getColumn());
assertEquals(callback, consumerCaptor.getValue());
assertEquals(sort, query.getSorts().get(0));
assertEquals(pagination.getFirstResult(), query.getFirstResult());
assertEquals(pagination.getMaxResults(), query.getMaxResults());
}
use of org.jnosql.diana.api.Condition in project jnosql-artemis by eclipse.
the class ColumnRepositoryAsyncProxyTest method shoudFindByName.
@Test
public void shoudFindByName() {
Consumer<List<Person>> callback = v -> {
};
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
personRepository.findByName("name", callback);
verify(template).select(captor.capture(), consumerCaptor.capture());
ColumnQuery query = captor.getValue();
ColumnCondition condition = query.getCondition().get();
assertEquals("Person", query.getColumnFamily());
assertEquals(Condition.EQUALS, condition.getCondition());
assertEquals(Column.of("name", "name"), condition.getColumn());
assertEquals(callback, consumerCaptor.getValue());
}
use of org.jnosql.diana.api.Condition in project jnosql-diana-driver by eclipse.
the class QueryUtils method createClause.
private static void createClause(Optional<ColumnCondition> columnConditionOptional, List<Clause> clauses) {
if (!columnConditionOptional.isPresent()) {
return;
}
ColumnCondition columnCondition = columnConditionOptional.get();
Column column = columnCondition.getColumn();
Condition condition = columnCondition.getCondition();
Object value = column.getValue().get();
switch(condition) {
case EQUALS:
clauses.add(QueryBuilder.eq(getName(column), value));
return;
case GREATER_THAN:
clauses.add(QueryBuilder.gt(getName(column), value));
return;
case GREATER_EQUALS_THAN:
clauses.add(QueryBuilder.gte(getName(column), value));
return;
case LESSER_THAN:
clauses.add(QueryBuilder.lt(getName(column), value));
return;
case LESSER_EQUALS_THAN:
clauses.add(QueryBuilder.lte(getName(column), value));
return;
case IN:
clauses.add(QueryBuilder.in(getName(column), getIinValue(value)));
return;
case LIKE:
clauses.add(QueryBuilder.like(getName(column), value));
return;
case AND:
for (ColumnCondition cc : column.get(new TypeReference<List<ColumnCondition>>() {
})) {
createClause(Optional.of(cc), clauses);
}
return;
case OR:
default:
throw new UnsupportedOperationException("The columnCondition " + condition + " is not supported in cassandra column driver");
}
}
use of org.jnosql.diana.api.Condition in project jnosql-artemis by eclipse.
the class DocumentRepositoryAsyncProxyTest method shouldDeleteByNameCallBack.
@Test
public void shouldDeleteByNameCallBack() {
ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
Consumer<Void> voidConsumer = v -> {
};
personRepository.deleteByName("name", voidConsumer);
verify(template).delete(captor.capture(), consumerCaptor.capture());
DocumentDeleteQuery query = captor.getValue();
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(Condition.EQUALS, condition.getCondition());
assertEquals(Document.of("name", "name"), condition.getDocument());
assertEquals(voidConsumer, consumerCaptor.getValue());
}
use of org.jnosql.diana.api.Condition in project jnosql-artemis by eclipse.
the class DocumentRepositoryAsyncProxyTest method shoudFindByNameSort.
@Test
public void shoudFindByNameSort() {
Consumer<List<Person>> callback = v -> {
};
Sort sort = Sort.of("age", Sort.SortType.ASC);
ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
personRepository.findByName("name", sort, callback);
verify(template).select(captor.capture(), consumerCaptor.capture());
DocumentQuery query = captor.getValue();
DocumentCondition condition = query.getCondition().get();
assertEquals("Person", query.getDocumentCollection());
assertEquals(Condition.EQUALS, condition.getCondition());
assertEquals(Document.of("name", "name"), condition.getDocument());
assertEquals(callback, consumerCaptor.getValue());
assertEquals(sort, query.getSorts().get(0));
}
Aggregations