use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.
the class DefaultDeleteQueryBuilderTest method shouldDeleteDocuments.
@Test
public void shouldDeleteDocuments() {
String documentCollection = "documentCollection";
DocumentDeleteQuery query = delete("document", "document2").from(documentCollection).build();
assertThat(query.getDocuments(), containsInAnyOrder("document", "document2"));
assertFalse(query.getCondition().isPresent());
assertEquals(documentCollection, query.getDocumentCollection());
}
use of jakarta.nosql.document.DocumentDeleteQuery 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))));
}
use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.
the class DefaultDocumentQueryParserTest method shouldReturnParserQuery1.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "delete from God" })
public void shouldReturnParserQuery1(String query) {
ArgumentCaptor<DocumentDeleteQuery> captor = ArgumentCaptor.forClass(DocumentDeleteQuery.class);
parser.query(query, manager, DocumentObserverParser.EMPTY);
Mockito.verify(manager).delete(captor.capture());
DocumentDeleteQuery documentQuery = captor.getValue();
assertTrue(documentQuery.getDocuments().isEmpty());
assertEquals("God", documentQuery.getDocumentCollection());
assertFalse(documentQuery.getCondition().isPresent());
}
use of jakarta.nosql.document.DocumentDeleteQuery 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());
}
use of jakarta.nosql.document.DocumentDeleteQuery in project jnosql-diana by eclipse.
the class DeleteQueryParser method query.
Stream<DocumentEntity> query(String query, DocumentCollectionManager collectionManager, DocumentObserverParser observer) {
DocumentDeleteQuery documentQuery = cache.get(query, observer);
collectionManager.delete(documentQuery);
return Stream.empty();
}
Aggregations