Search in sources :

Example 6 with Sort

use of org.jnosql.diana.api.Sort in project jnosql-diana-driver by eclipse.

the class QueryOSQLConverter method appendSort.

private static void appendSort(List<Sort> sorts, StringBuilder query) {
    query.append(SORT);
    String separator = SPACE;
    for (Sort sort : sorts) {
        query.append(separator).append(sort.getName()).append(SPACE).append(sort.getType());
        separator = ", ";
    }
}
Also used : Sort(org.jnosql.diana.api.Sort)

Example 7 with Sort

use of org.jnosql.diana.api.Sort in project jnosql-diana-driver by eclipse.

the class QueryAQLConverter method sort.

private static void sort(List<Sort> sorts, StringBuilder aql, char entity) {
    aql.append(SORT);
    String separator = SEPARATOR;
    for (Sort sort : sorts) {
        aql.append(separator).append(entity).append('.').append(sort.getName()).append(SEPARATOR).append(sort.getType());
        separator = " , ";
    }
}
Also used : Sort(org.jnosql.diana.api.Sort)

Example 8 with Sort

use of org.jnosql.diana.api.Sort in project jnosql-artemis by eclipse.

the class DocumentQueryParserTest method shouldFindByNameWithSortArgument.

@Test
public void shouldFindByNameWithSortArgument() {
    Sort sort = Sort.of("age", Sort.SortType.ASC);
    DocumentQuery query = parser.parse("findByName", new Object[] { "name", sort }, classRepresentation, converters);
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.EQUALS, query.getCondition().get().getCondition());
    assertEquals(Document.of("name", "name"), query.getCondition().get().getDocument());
    assertEquals(sort, query.getSorts().get(0));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) Sort(org.jnosql.diana.api.Sort) Test(org.junit.jupiter.api.Test)

Example 9 with Sort

use of org.jnosql.diana.api.Sort 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));
}
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) 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 10 with Sort

use of org.jnosql.diana.api.Sort 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)

Aggregations

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