Search in sources :

Example 6 with DocumentObserverParser

use of jakarta.nosql.document.DocumentObserverParser 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 7 with DocumentObserverParser

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

the class SelectQueryParserTest method shouldReturnParserQuery4.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God order by name asc" })
public void shouldReturnParserQuery4(String query) {
    ArgumentCaptor<DocumentQuery> captor = ArgumentCaptor.forClass(DocumentQuery.class);
    DocumentObserverParser observer = new DocumentObserverParser() {
    };
    parser.query(query, documentCollection, observer);
    Mockito.verify(documentCollection).select(captor.capture());
    DocumentQuery documentQuery = captor.getValue();
    assertTrue(documentQuery.getDocuments().isEmpty());
    assertThat(documentQuery.getSorts(), contains(Sort.of("name", SortType.ASC)));
    assertEquals(0L, documentQuery.getLimit());
    assertEquals(0L, documentQuery.getSkip());
    assertEquals("God", documentQuery.getDocumentCollection());
    assertFalse(documentQuery.getCondition().isPresent());
}
Also used : DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentObserverParser(jakarta.nosql.document.DocumentObserverParser) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

DocumentObserverParser (jakarta.nosql.document.DocumentObserverParser)7 DocumentCondition (jakarta.nosql.document.DocumentCondition)5 DocumentQuery (jakarta.nosql.document.DocumentQuery)5 Params (jakarta.nosql.Params)4 QueryException (jakarta.nosql.QueryException)4 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)4 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)4 DocumentEntity (jakarta.nosql.document.DocumentEntity)4 DocumentPreparedStatement (jakarta.nosql.document.DocumentPreparedStatement)4 List (java.util.List)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 Sort (jakarta.nosql.Sort)2 DeleteQueryConverter (jakarta.nosql.document.DeleteQueryConverter)2 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)2 DocumentDeleteQueryParams (jakarta.nosql.document.DocumentDeleteQueryParams)2 DocumentQueryParams (jakarta.nosql.document.DocumentQueryParams)2