Search in sources :

Example 6 with Pagination

use of org.jnosql.artemis.Pagination in project jnosql-artemis by eclipse.

the class DocumentQueryParserTest method shouldFindByNameWithPageSortArgumentAndIgnore.

@Test
public void shouldFindByNameWithPageSortArgumentAndIgnore() {
    Pagination pagination = Pagination.of(2L, 10);
    Sort sort = Sort.of("age", Sort.SortType.ASC);
    DocumentQuery query = parser.parse("findByName", new Object[] { "name", pagination, sort, "ignore" }, 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));
}
Also used : Pagination(org.jnosql.artemis.Pagination) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Sort(org.jnosql.diana.api.Sort) Test(org.junit.jupiter.api.Test)

Example 7 with Pagination

use of org.jnosql.artemis.Pagination in project jnosql-artemis by eclipse.

the class DocumentQueryParserTest method shouldFindByNameWithPageArgument.

@Test
public void shouldFindByNameWithPageArgument() {
    Pagination pagination = Pagination.of(2L, 10);
    DocumentQuery query = parser.parse("findByName", new Object[] { "name", pagination }, 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());
}
Also used : Pagination(org.jnosql.artemis.Pagination) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Test(org.junit.jupiter.api.Test)

Example 8 with Pagination

use of org.jnosql.artemis.Pagination in project jnosql-artemis by eclipse.

the class DocumentRepositoryAsyncProxyTest 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<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    ArgumentCaptor<Consumer> consumerCaptor = ArgumentCaptor.forClass(Consumer.class);
    personRepository.findByName("name", sort, pagination, 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));
    assertEquals(pagination.getFirstResult(), query.getFirstResult());
    assertEquals(pagination.getMaxResults(), query.getMaxResults());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Document(org.jnosql.diana.api.document.Document) Converters(org.jnosql.artemis.Converters) Proxy(java.lang.reflect.Proxy) Matchers(org.mockito.Matchers) RepositoryAsync(org.jnosql.artemis.RepositoryAsync) Pagination(org.jnosql.artemis.Pagination) DynamicQueryException(org.jnosql.artemis.DynamicQueryException) Collections.singletonList(java.util.Collections.singletonList) Person(org.jnosql.artemis.model.Person) Reflections(org.jnosql.artemis.reflection.Reflections) Condition(org.jnosql.diana.api.Condition) Inject(javax.inject.Inject) CDIExtension(org.jnosql.artemis.CDIExtension) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Duration(java.time.Duration) DocumentTemplateAsync(org.jnosql.artemis.document.DocumentTemplateAsync) DocumentQueryBuilder.delete(org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentQueryBuilder.select(org.jnosql.diana.api.document.query.DocumentQueryBuilder.select) Sort(org.jnosql.diana.api.Sort) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) ClassRepresentations(org.jnosql.artemis.reflection.ClassRepresentations) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) Pagination(org.jnosql.artemis.Pagination) DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Consumer(java.util.function.Consumer) Sort(org.jnosql.diana.api.Sort) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 9 with Pagination

use of org.jnosql.artemis.Pagination in project jnosql-artemis by eclipse.

the class ColumnQueryParserTest method shouldFindByNameWithPageSortArgumentAndIgnore.

@Test
public void shouldFindByNameWithPageSortArgumentAndIgnore() {
    Pagination pagination = Pagination.of(2L, 10);
    Sort sort = Sort.of("age", Sort.SortType.ASC);
    ColumnQuery query = parser.parse("findByName", new Object[] { "name", pagination, sort, "ignore" }, 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));
}
Also used : Pagination(org.jnosql.artemis.Pagination) ColumnQuery(org.jnosql.diana.api.column.ColumnQuery) Sort(org.jnosql.diana.api.Sort) Test(org.junit.jupiter.api.Test)

Example 10 with Pagination

use of org.jnosql.artemis.Pagination 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());
}
Also used : ArrayList(java.util.ArrayList) Pagination(org.jnosql.artemis.Pagination) Sort(org.jnosql.diana.api.Sort) ColumnCondition(org.jnosql.diana.api.column.ColumnCondition)

Aggregations

Pagination (org.jnosql.artemis.Pagination)10 Sort (org.jnosql.diana.api.Sort)8 Test (org.junit.jupiter.api.Test)8 ColumnQuery (org.jnosql.diana.api.column.ColumnQuery)4 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)4 Proxy (java.lang.reflect.Proxy)2 Duration (java.time.Duration)2 ArrayList (java.util.ArrayList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Optional (java.util.Optional)2 Consumer (java.util.function.Consumer)2 Inject (javax.inject.Inject)2 CDIExtension (org.jnosql.artemis.CDIExtension)2 Converters (org.jnosql.artemis.Converters)2 DynamicQueryException (org.jnosql.artemis.DynamicQueryException)2 RepositoryAsync (org.jnosql.artemis.RepositoryAsync)2 Person (org.jnosql.artemis.model.Person)2 ClassRepresentations (org.jnosql.artemis.reflection.ClassRepresentations)2 Reflections (org.jnosql.artemis.reflection.Reflections)2