Search in sources :

Example 26 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class SelectQueryParserTest method shouldReturnParserQuery26.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select  * from God where name = \"Ada\" and age = 20 or" + " siblings = {\"apollo\": \"Brother\", \"Zeus\": \"Father\"} and birthday =" + " convert(\"2007-12-03\", java.time.LocalDate)" })
public void shouldReturnParserQuery26(String query) {
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    parser.query(query, documentCollection, observer);
    Mockito.verify(documentCollection).select(captor.capture());
    DocumentQuery documentQuery = captor.getValue();
    checkBaseQuery(documentQuery, 0L, 0L);
    assertTrue(documentQuery.getCondition().isPresent());
    DocumentCondition condition = documentQuery.getCondition().get();
    Document document = condition.getDocument();
    assertEquals(Condition.AND, condition.getCondition());
    List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
    });
    assertEquals(Condition.EQUALS, conditions.get(0).getCondition());
    assertEquals(Condition.EQUALS, conditions.get(1).getCondition());
    assertEquals(Condition.OR, conditions.get(2).getCondition());
    assertEquals(Condition.EQUALS, conditions.get(3).getCondition());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class BaseDocumentRepository method getQuery.

protected DocumentQuery getQuery(Method method, Object[] args) {
    SelectMethodProvider methodProvider = SelectMethodProvider.get();
    SelectQuery selectQuery = methodProvider.apply(method, getClassMapping().getName());
    SelectQueryConverter converter = ServiceLoaderProvider.get(SelectQueryConverter.class);
    DocumentQueryParams queryParams = converter.apply(selectQuery, getParser());
    DocumentQuery query = queryParams.getQuery();
    Params params = queryParams.getParams();
    getParamsBinder().bind(params, args, method);
    return getQuerySorts(args, query);
}
Also used : SelectQuery(jakarta.nosql.query.SelectQuery) DocumentQuery(jakarta.nosql.document.DocumentQuery) SelectQueryConverter(jakarta.nosql.document.SelectQueryConverter) SelectMethodProvider(org.eclipse.jnosql.communication.query.method.SelectMethodProvider) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) DocumentQueryParams(jakarta.nosql.document.DocumentQueryParams) DocumentDeleteQueryParams(jakarta.nosql.document.DocumentDeleteQueryParams) Params(jakarta.nosql.Params)

Example 28 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class DocumentReactiveRepositoryProxyTest method shouldFindAll.

@Test
public void shouldFindAll() {
    Person ada = Person.builder().withAge(20).withName("Ada").build();
    when(template.select(any(DocumentQuery.class))).thenReturn(Stream.of(ada));
    List<Person> persons = personRepository.findAll();
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    verify(template).select(captor.capture());
    DocumentQuery query = captor.getValue();
    assertFalse(query.getCondition().isPresent());
    assertEquals("Person", query.getDocumentCollection());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Example 29 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class AbstractReactiveDocumentRepositoryProxy method invoke.

@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
    RepositoryType type = ReactiveRepositoryType.of(method);
    Class<?> typeClass = getClassMapping().getClassInstance();
    switch(type) {
        case DEFAULT:
            return method.invoke(getRepository(), args);
        case FIND_BY:
            DocumentQuery query = getQuery(method, args);
            return executeQuery(method, args, typeClass, query);
        case FIND_ALL:
            DocumentQuery queryFindAll = select().from(getClassMapping().getName()).build();
            return executeQuery(method, args, typeClass, getQuerySorts(args, queryFindAll));
        case DELETE_BY:
            DocumentDeleteQuery documentDeleteQuery = getDeleteQuery(method, args);
            Iterable<Void> iterable = () -> {
                getTemplate().delete(documentDeleteQuery);
                return Collections.emptyIterator();
            };
            return ReactiveStreams.fromIterable(iterable).buildRs();
        case OBJECT_METHOD:
            return method.invoke(this, args);
        case JNOSQL_QUERY:
            DynamicQueryMethodReturn methodReturn = DynamicQueryMethodReturn.builder().withArgs(args).withMethod(method).withTypeClass(typeClass).withPrepareConverter(q -> getTemplate().prepare(q)).withQueryConverter(q -> getTemplate().query(q)).build();
            return methodReturn.execute();
        default:
            return Void.class;
    }
}
Also used : DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) ReactiveRepositoryType(org.eclipse.jnosql.mapping.reactive.ReactiveRepositoryType) DocumentQuery.select(jakarta.nosql.document.DocumentQuery.select) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) DocumentTemplate(jakarta.nosql.mapping.document.DocumentTemplate) ReactiveRepository(org.eclipse.jnosql.mapping.reactive.ReactiveRepository) DocumentQuery(jakarta.nosql.document.DocumentQuery) BaseDocumentRepository(org.eclipse.jnosql.mapping.document.query.BaseDocumentRepository) DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) InvocationHandler(java.lang.reflect.InvocationHandler) ReactiveStreams(org.eclipse.microprofile.reactive.streams.operators.ReactiveStreams) Method(java.lang.reflect.Method) Collections(java.util.Collections) DocumentQuery(jakarta.nosql.document.DocumentQuery) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) ReactiveRepositoryType(org.eclipse.jnosql.mapping.reactive.ReactiveRepositoryType) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery)

Example 30 with DocumentQuery

use of jakarta.nosql.document.DocumentQuery in project jnosql-diana by eclipse.

the class DefaultReactiveDocumentTemplateTest method shouldSelect.

@Test
public void shouldSelect() {
    DocumentQuery query = Mockito.mock(DocumentQuery.class);
    AtomicReference<List<Person>> reference = new AtomicReference<>();
    Person ada = Person.builder().withId(1L).withAge(30).withName("Ada").build();
    Mockito.when(template.select(query)).thenReturn(Stream.of(ada));
    final Observable<Person> observable = manager.select(query);
    Mockito.verify(template, Mockito.never()).select(query);
    CompletionStage<List<Person>> completion = observable.getList();
    completion.thenAccept(reference::set);
    Mockito.verify(template).select(query);
    MatcherAssert.assertThat(reference.get(), Matchers.containsInAnyOrder(ada));
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) Person(jakarta.nosql.tck.entities.Person) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentQuery (jakarta.nosql.document.DocumentQuery)292 Test (org.junit.jupiter.api.Test)234 DocumentEntity (jakarta.nosql.document.DocumentEntity)123 Document (jakarta.nosql.document.Document)98 DocumentCondition (jakarta.nosql.document.DocumentCondition)64 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)55 Person (jakarta.nosql.tck.entities.Person)50 List (java.util.List)50 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)44 Arrays.asList (java.util.Arrays.asList)34 ValueSource (org.junit.jupiter.params.provider.ValueSource)30 Pagination (jakarta.nosql.mapping.Pagination)27 ArrayList (java.util.ArrayList)26 Collectors (java.util.stream.Collectors)19 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)18 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)16 Matchers.contains (org.hamcrest.Matchers.contains)16 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)16 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)16 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)16