use of org.jnosql.artemis.Pagination in project jnosql-artemis by eclipse.
the class ColumnQueryParserTest method shouldFindByNameWithPageSortArgument.
@Test
public void shouldFindByNameWithPageSortArgument() {
Pagination pagination = Pagination.of(2L, 10);
Sort sort = Sort.of("age", Sort.SortType.ASC);
ColumnQuery query = parser.parse("findByName", new Object[] { "name", pagination, sort }, classRepresentation, converters);
assertEquals("Person", query.getColumnFamily());
assertEquals(Condition.EQUALS, query.getCondition().get().getCondition());
assertEquals(Column.of("name", "name"), query.getCondition().get().getColumn());
assertEquals(pagination.getMaxResults(), query.getMaxResults());
assertEquals(pagination.getFirstResult(), query.getFirstResult());
assertEquals(sort, query.getSorts().get(0));
}
use of org.jnosql.artemis.Pagination in project jnosql-artemis by eclipse.
the class ColumnQueryParserTest method shouldFindByNameWithPageArgument.
@Test
public void shouldFindByNameWithPageArgument() {
Pagination pagination = Pagination.of(2L, 10);
ColumnQuery query = parser.parse("findByName", new Object[] { "name", pagination }, classRepresentation, converters);
assertEquals("Person", query.getColumnFamily());
assertEquals(Condition.EQUALS, query.getCondition().get().getCondition());
assertEquals(Column.of("name", "name"), query.getCondition().get().getColumn());
assertEquals(pagination.getMaxResults(), query.getMaxResults());
assertEquals(pagination.getFirstResult(), query.getFirstResult());
}
use of org.jnosql.artemis.Pagination 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.artemis.Pagination in project jnosql-artemis by eclipse.
the class DocumentQueryParser method parse.
public DocumentQuery parse(String methodName, Object[] args, ClassRepresentation representation, Converters converters) {
String[] tokens = methodName.replace(PREFIX, EMPTY).split(TOKENIZER);
String className = representation.getClassInstance().getName();
DocumentCondition condition = null;
List<Sort> sorts = new ArrayList<>();
long limit = 0;
long start = 0;
int index = 0;
for (String token : tokens) {
if (token.startsWith(AND)) {
DocumentQueryParserUtil.ConditionResult result = and(args, index, token, methodName, representation, condition, converters);
condition = result.getCondition();
index = result.getIndex();
} else {
if (token.startsWith(ORDER_BY)) {
sort(sorts, token, representation);
} else if (token.startsWith(DocumentQueryParserUtil.OR)) {
DocumentQueryParserUtil.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 ArtemisDocumentQuery(sorts, limit, start, condition, representation.getName());
}
use of org.jnosql.artemis.Pagination in project jnosql-artemis by eclipse.
the class DocumentQueryParserTest method shouldFindByNameWithPageSortArgument.
@Test
public void shouldFindByNameWithPageSortArgument() {
Pagination pagination = Pagination.of(2L, 10);
Sort sort = Sort.of("age", Sort.SortType.ASC);
DocumentQuery query = parser.parse("findByName", new Object[] { "name", pagination, sort }, classRepresentation, converters);
assertEquals("Person", query.getDocumentCollection());
assertEquals(Condition.EQUALS, query.getCondition().get().getCondition());
assertEquals(Document.of("name", "name"), query.getCondition().get().getDocument());
assertEquals(pagination.getMaxResults(), query.getMaxResults());
assertEquals(pagination.getFirstResult(), query.getFirstResult());
assertEquals(sort, query.getSorts().get(0));
}
Aggregations