Search in sources :

Example 1 with DocumentDeleteQuery

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

the class DeleteQueryParser method getQuery.

private DocumentDeleteQuery getQuery(String query, DocumentObserverParser observer) {
    DeleteQuery deleteQuery = deleteQueryProvider.apply(query);
    String collection = observer.fireEntity(deleteQuery.getEntity());
    List<String> documents = deleteQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
    DocumentCondition condition = null;
    Params params = Params.newParams();
    if (deleteQuery.getWhere().isPresent()) {
        condition = deleteQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, collection)).get();
    }
    if (params.isNotEmpty()) {
        throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
    }
    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) QueryException(jakarta.nosql.QueryException) DocumentDeleteQueryParams(jakarta.nosql.document.DocumentDeleteQueryParams) Params(jakarta.nosql.Params) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) DeleteQuery(jakarta.nosql.query.DeleteQuery) DocumentCondition(jakarta.nosql.document.DocumentCondition)

Example 2 with DocumentDeleteQuery

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

the class DeleteQueryParser method apply.

@Override
public DocumentDeleteQueryParams apply(DeleteQuery deleteQuery, DocumentObserverParser observer) {
    Objects.requireNonNull(deleteQuery, "deleteQuery is required");
    Objects.requireNonNull(observer, "observer is required");
    Params params = Params.newParams();
    DocumentDeleteQuery query = getQuery(params, observer, deleteQuery);
    return new DefaultDocumentDeleteQueryParams(query, params);
}
Also used : DocumentDeleteQueryParams(jakarta.nosql.document.DocumentDeleteQueryParams) Params(jakarta.nosql.Params) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery)

Example 3 with DocumentDeleteQuery

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

the class DefaultDeleteQueryBuilderTest method shouldDelete.

@Test
public void shouldDelete() {
    String documentCollection = "documentCollection";
    DocumentDeleteQuery query = delete().from(documentCollection).build();
    assertTrue(query.getDocuments().isEmpty());
    assertFalse(query.getCondition().isPresent());
    assertEquals(documentCollection, query.getDocumentCollection());
}
Also used : DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 4 with DocumentDeleteQuery

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameNot.

@Test
public void shouldSelectWhereNameNot() {
    String documentCollection = "documentCollection";
    String name = "Ada Lovelace";
    DocumentDeleteQuery query = delete().from(documentCollection).where("name").not().eq(name).build();
    DocumentCondition condition = query.getCondition().get();
    Document column = condition.getDocument();
    DocumentCondition negate = column.get(DocumentCondition.class);
    assertTrue(query.getDocuments().isEmpty());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(Condition.NOT, condition.getCondition());
    assertEquals(Condition.EQUALS, negate.getCondition());
    assertEquals("name", negate.getDocument().getName());
    assertEquals(name, negate.getDocument().get());
}
Also used : Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Example 5 with DocumentDeleteQuery

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

the class DefaultDeleteQueryBuilderTest method shouldSelectWhereNameGte.

@Test
public void shouldSelectWhereNameGte() {
    String documentCollection = "documentCollection";
    Number value = 10;
    DocumentDeleteQuery query = delete().from(documentCollection).where("name").gte(value).build();
    DocumentCondition condition = query.getCondition().get();
    Document document = condition.getDocument();
    assertTrue(query.getDocuments().isEmpty());
    assertEquals(documentCollection, query.getDocumentCollection());
    assertEquals(Condition.GREATER_EQUALS_THAN, condition.getCondition());
    assertEquals("name", document.getName());
    assertEquals(value, document.get());
}
Also used : Document(jakarta.nosql.document.Document) DocumentCondition(jakarta.nosql.document.DocumentCondition) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) Test(org.junit.jupiter.api.Test)

Aggregations

DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)114 Test (org.junit.jupiter.api.Test)79 DocumentEntity (jakarta.nosql.document.DocumentEntity)45 DocumentQuery (jakarta.nosql.document.DocumentQuery)43 Document (jakarta.nosql.document.Document)37 DocumentCondition (jakarta.nosql.document.DocumentCondition)33 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ValueSource (org.junit.jupiter.params.provider.ValueSource)20 List (java.util.List)15 Person (jakarta.nosql.tck.entities.Person)12 Collectors (java.util.stream.Collectors)7 Params (jakarta.nosql.Params)5 DocumentDeleteQueryParams (jakarta.nosql.document.DocumentDeleteQueryParams)5 Duration (java.time.Duration)5 HashMap (java.util.HashMap)5 Optional (java.util.Optional)5 StreamSupport (java.util.stream.StreamSupport)5 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)4 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)4 Map (java.util.Map)4