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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations