Search in sources :

Example 46 with DocumentCondition

use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-diana by eclipse.

the class DefaultSelectQueryBuilderTest method shouldSelectWhereNameBetween.

@Test
public void shouldSelectWhereNameBetween() {
    String documentCollection = "documentCollection";
    Number valueA = 10;
    Number valueB = 20;
    DocumentQuery query = select().from(documentCollection).where("name").between(valueA, valueB).build();
    DocumentCondition condition = query.getCondition().get();
    Document document = condition.getDocument();
    assertTrue(query.getDocuments().isEmpty());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(Condition.BETWEEN, condition.getCondition());
    assertEquals("name", document.getName());
    assertThat(document.get(new TypeReference<List<Number>>() {
    }), Matchers.contains(10, 20));
}
Also used : DocumentQuery(org.jnosql.diana.api.document.DocumentQuery) TypeReference(org.jnosql.diana.api.TypeReference) Document(org.jnosql.diana.api.document.Document) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Example 47 with DocumentCondition

use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-diana by eclipse.

the class BaseQueryBuilder method betweenImpl.

protected void betweenImpl(Number valueA, Number valueB) {
    requireNonNull(valueA, "valueA is required");
    requireNonNull(valueB, "valueB is required");
    DocumentCondition newCondition = DocumentCondition.between(Document.of(name, asList(valueA, valueB)));
    appendCondition(newCondition);
}
Also used : DocumentCondition(org.jnosql.diana.api.document.DocumentCondition)

Example 48 with DocumentCondition

use of org.jnosql.diana.api.document.DocumentCondition in project jnosql-diana by eclipse.

the class BaseQueryBuilder method inImpl.

protected <T> void inImpl(Iterable<T> values) {
    requireNonNull(values, "values is required");
    DocumentCondition newCondition = DocumentCondition.in(Document.of(name, values));
    appendCondition(newCondition);
}
Also used : DocumentCondition(org.jnosql.diana.api.document.DocumentCondition)

Example 49 with DocumentCondition

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

the class DefaultDocumentTemplateTest method shouldDeleteEntity.

@Test
public void shouldDeleteEntity() {
    subject.delete(Person.class, "10");
    ArgumentCaptor<DocumentDeleteQuery> queryCaptor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    verify(managerMock).delete(queryCaptor.capture());
    DocumentDeleteQuery query = queryCaptor.getValue();
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(DocumentCondition.eq(Document.of("_id", 10L)), condition);
}
Also used : DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 50 with DocumentCondition

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

the class DocumentQueryDeleteParserTest method shouldDeleteByNameOrAge.

@Test
public void shouldDeleteByNameOrAge() {
    DocumentDeleteQuery query = parser.parse("deleteByNameOrAge", new Object[] { "name", 10 }, classRepresentation, converters);
    DocumentCondition condition = query.getCondition().get();
    assertEquals("Person", query.getDocumentCollection());
    assertEquals(Condition.OR, condition.getCondition());
    List<DocumentCondition> conditions = condition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
    });
    DocumentCondition condition1 = conditions.get(0);
    assertEquals(Condition.EQUALS, condition1.getCondition());
    assertEquals(Document.of("name", "name"), condition1.getDocument());
    DocumentCondition condition2 = conditions.get(1);
    assertEquals(Condition.EQUALS, condition2.getCondition());
    assertEquals(Document.of("age", 10), condition2.getDocument());
}
Also used : List(java.util.List) DocumentCondition(org.jnosql.diana.api.document.DocumentCondition) DocumentDeleteQuery(org.jnosql.diana.api.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentCondition (org.jnosql.diana.api.document.DocumentCondition)69 Test (org.junit.jupiter.api.Test)46 Document (org.jnosql.diana.api.document.Document)31 DocumentQuery (org.jnosql.diana.api.document.DocumentQuery)29 DocumentDeleteQuery (org.jnosql.diana.api.document.DocumentDeleteQuery)23 List (java.util.List)22 Person (org.jnosql.artemis.model.Person)13 Collections.singletonList (java.util.Collections.singletonList)7 Pagination (org.jnosql.artemis.Pagination)7 Sort (org.jnosql.diana.api.Sort)7 Proxy (java.lang.reflect.Proxy)6 Duration (java.time.Duration)6 Optional (java.util.Optional)6 Consumer (java.util.function.Consumer)6 Inject (javax.inject.Inject)6 CDIExtension (org.jnosql.artemis.CDIExtension)6 Converters (org.jnosql.artemis.Converters)6 DynamicQueryException (org.jnosql.artemis.DynamicQueryException)6 RepositoryAsync (org.jnosql.artemis.RepositoryAsync)6 DocumentTemplateAsync (org.jnosql.artemis.document.DocumentTemplateAsync)6