Search in sources :

Example 71 with DocumentCondition

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

the class DefaultDeleteQueryBuilderTest method shouldDeleteNegate.

@Test
public void shouldDeleteNegate() {
    String columnFamily = "columnFamily";
    DocumentDeleteQuery query = delete().from(columnFamily).where("city").not().eq("Assis").and("name").not().eq("Lucas").build();
    DocumentCondition condition = query.getCondition().orElseThrow(RuntimeException::new);
    assertEquals(columnFamily, query.getDocumentCollection());
    Document column = condition.getDocument();
    List<DocumentCondition> conditions = column.get(new TypeReference<List<DocumentCondition>>() {
    });
    assertEquals(Condition.AND, condition.getCondition());
    assertThat(conditions, containsInAnyOrder(eq(Document.of("city", "Assis")).negate(), eq(Document.of("name", "Lucas")).negate()));
}
Also used : List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 72 with DocumentCondition

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameOr.

@Test
public void shouldSelectWhereNameOr() {
    String documentCollection = "documentCollection";
    String name = "Ada Lovelace";
    DocumentDeleteQuery query = delete().from(documentCollection).where("name").eq(name).or("age").gt(10).build();
    DocumentCondition condition = query.getCondition().get();
    Document document = condition.getDocument();
    List<DocumentCondition> conditions = document.get(new TypeReference<List<DocumentCondition>>() {
    });
    assertEquals(Condition.OR, condition.getCondition());
    assertThat(conditions, Matchers.containsInAnyOrder(eq(Document.of("name", name)), DocumentCondition.gt(Document.of("age", 10))));
}
Also used : List(java.util.List) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 73 with DocumentCondition

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

the class DefaultDocumentQueryParserTest method shouldExecutePrepareStatement.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God where age = @age" })
public void shouldExecutePrepareStatement(String query) {
    ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
    DocumentPreparedStatement prepare = parser.prepare(query, manager, DocumentObserverParser.EMPTY);
    prepare.bind("age", 12);
    prepare.getResult();
    Mockito.verify(manager).delete(captor.capture());
    DocumentDeleteQuery documentQuery = captor.getValue();
    DocumentCondition documentCondition = documentQuery.getCondition().get();
    Document document = documentCondition.getDocument();
    assertEquals(Condition.EQUALS, documentCondition.getCondition());
    assertEquals("age", document.getName());
    assertEquals(12, document.get());
}
Also used : DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 74 with DocumentCondition

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

the class DeleteQueryParser method getQuery.

private DocumentDeleteQuery getQuery(Params params, DocumentObserverParser observer, DeleteQuery deleteQuery) {
    String collection = observer.fireEntity(deleteQuery.getEntity());
    List<String> documents = deleteQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
    DocumentCondition condition = null;
    if (deleteQuery.getWhere().isPresent()) {
        condition = deleteQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, collection)).get();
    }
    return new DefaultDocumentDeleteQuery(collection, condition, documents);
}
Also used : DocumentCollectionManager(jakarta.nosql.document.DocumentCollectionManager) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) DocumentPreparedStatement(jakarta.nosql.document.DocumentPreparedStatement) DocumentDeleteQueryParams(jakarta.nosql.document.DocumentDeleteQueryParams) DocumentEntity(jakarta.nosql.document.DocumentEntity) Collectors(java.util.stream.Collectors) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) DeleteQueryConverter(jakarta.nosql.document.DeleteQueryConverter) DeleteQuery(jakarta.nosql.query.DeleteQuery) Objects(java.util.Objects) List(java.util.List) DeleteQueryProvider(jakarta.nosql.query.DeleteQuery.DeleteQueryProvider) Stream(java.util.stream.Stream) QueryException(jakarta.nosql.QueryException) DocumentObserverParser(jakarta.nosql.document.DocumentObserverParser) Params(jakarta.nosql.Params) DocumentCondition(jakarta.nosql.document.DocumentCondition)

Example 75 with DocumentCondition

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

the class DefaultDocumentConditionTest method shouldReturnBetween.

@Test
public void shouldReturnBetween() {
    Document document = Document.of("age", Arrays.asList(12, 13));
    DocumentCondition between = DocumentCondition.between(document);
    assertEquals(Condition.BETWEEN, between.getCondition());
    Iterable<Integer> integers = between.getDocument().get(new TypeReference<Iterable<Integer>>() {
    });
    assertThat(integers, contains(12, 13));
}
Also used : Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentCondition (jakarta.nosql.document.DocumentCondition)132 Test (org.junit.jupiter.api.Test)68 DocumentQuery (jakarta.nosql.document.DocumentQuery)64 Document (jakarta.nosql.document.Document)60 List (java.util.List)37 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)37 ValueSource (org.junit.jupiter.params.provider.ValueSource)37 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)33 Person (jakarta.nosql.tck.entities.Person)17 Pagination (jakarta.nosql.mapping.Pagination)13 DocumentPreparedStatement (jakarta.nosql.document.DocumentPreparedStatement)10 TypeReference (jakarta.nosql.TypeReference)7 Params (jakarta.nosql.Params)6 DocumentEntity (jakarta.nosql.document.DocumentEntity)6 DocumentObserverParser (jakarta.nosql.document.DocumentObserverParser)5 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)4 DocumentQueryParams (jakarta.nosql.document.DocumentQueryParams)4 SelectQueryConverter (jakarta.nosql.document.SelectQueryConverter)4