use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-artemis by eclipse.
the class ColumnRepositoryAsyncProxyTest method shoudFindByNameSort.
@Test
public void shoudFindByNameSort() {
Consumer<List<Person>> callback = v -> {
};
Sort sort = Sort.of("age", Sort.SortType.ASC);
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
personRepository.findByName("name", sort, 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));
}
use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-artemis by eclipse.
the class ColumnRepositoryAsyncProxyTest method shouldDeleteByNameCallBack.
@Test
public void shouldDeleteByNameCallBack() {
ArgumentCaptor<ColumnDeleteQuery> captor = ArgumentCaptor.forClass(ColumnDeleteQuery.class);
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
Consumer<Void> voidConsumer = v -> {
};
personRepository.deleteByName("name", voidConsumer);
verify(template).delete(captor.capture(), consumerCaptor.capture());
ColumnDeleteQuery 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(voidConsumer, consumerCaptor.getValue());
}
use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-artemis by eclipse.
the class ColumnRepositoryAsyncProxyTest method shouldFindByNameOrderByAgeDesc.
@Test
public void shouldFindByNameOrderByAgeDesc() {
Consumer<List<Person>> callback = v -> {
};
ArgumentCaptor<ColumnQuery> captor = ArgumentCaptor.forClass(ColumnQuery.class);
ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
personRepository.findByNameOrderByAgeDesc("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());
assertEquals(Sort.of("age", Sort.SortType.DESC), query.getSorts().get(0));
}
use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-artemis by eclipse.
the class ColumnQueryParser method parse.
public ColumnQuery parse(String methodName, Object[] args, ClassRepresentation representation, Converters converters) {
ColumnCondition condition = null;
String[] tokens = methodName.replace(PREFIX, ColumnQueryParserUtil.EMPTY).split(TOKENIZER);
String className = representation.getClassInstance().getName();
List<Sort> sorts = new ArrayList<>();
long limit = 0;
long start = 0;
int index = 0;
for (String token : tokens) {
if (token.startsWith(ColumnQueryParserUtil.AND)) {
ColumnQueryParserUtil.ConditionResult result = and(args, index, token, methodName, representation, condition, converters);
condition = result.getCondition();
index = result.getIndex();
} else if (token.startsWith(ColumnQueryParserUtil.ORDER_BY)) {
sort(sorts, token, representation);
} else if (token.startsWith(ColumnQueryParserUtil.OR)) {
ColumnQueryParserUtil.ConditionResult result = or(args, index, token, methodName, representation, condition, converters);
condition = result.getCondition();
index = result.getIndex();
} else {
condition = toCondition(token, index, args, methodName, representation, converters);
index++;
}
}
while (index < args.length) {
Object value = args[index];
if (Sort.class.isInstance(value)) {
sorts.add(Sort.class.cast(value));
} else if (Pagination.class.isInstance(value)) {
Pagination pagination = Pagination.class.cast(value);
limit = pagination.getMaxResults();
start = pagination.getFirstResult();
} else {
LOGGER.info(String.format("Ignoring parameter %s on methodName %s class name %s arg-number: %d", String.valueOf(value), methodName, className, index));
}
index++;
}
return new ArtemisColumnQuery(sorts, limit, start, condition, representation.getName());
}
use of org.jnosql.diana.api.column.ColumnCondition in project jnosql-artemis by eclipse.
the class ColumnQueryParserUtil method and.
static ConditionResult and(Object[] args, int index, String token, String methodName, ClassRepresentation representation, ColumnCondition queryCondition, Converters converters) {
String field = token.replace(ColumnQueryParserUtil.AND, ColumnQueryParserUtil.EMPTY);
ColumnCondition conditionResult = toCondition(field, index, args, methodName, representation, converters);
ColumnCondition condition = null;
if (queryCondition == null) {
condition = conditionResult;
} else {
condition = queryCondition.and(conditionResult);
}
if (Condition.BETWEEN.equals(condition.getCondition())) {
return new ConditionResult(index + 2, condition);
} else {
return new ConditionResult(++index, condition);
}
}
Aggregations