use of jakarta.nosql.document.DocumentObserverParser 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.DocumentObserverParser in project jnosql-diana by eclipse.
the class SelectQueryParser method getDocumentQuery.
private DocumentQuery getDocumentQuery(String query, DocumentObserverParser observer) {
SelectQuery selectQuery = selectQueryProvider.apply(query);
String collection = observer.fireEntity(selectQuery.getEntity());
long limit = selectQuery.getLimit();
long skip = selectQuery.getSkip();
List<String> documents = selectQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
List<Sort> sorts = selectQuery.getOrderBy().stream().map(s -> toSort(s, observer, collection)).collect(toList());
DocumentCondition condition = null;
Params params = Params.newParams();
if (selectQuery.getWhere().isPresent()) {
condition = selectQuery.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 DefaultDocumentQuery(limit, skip, collection, documents, sorts, condition);
}
use of jakarta.nosql.document.DocumentObserverParser in project jnosql-diana by eclipse.
the class SelectQueryParser method getDocumentQuery.
private DocumentQuery getDocumentQuery(Params params, SelectQuery selectQuery, DocumentObserverParser observer) {
String collection = observer.fireEntity(selectQuery.getEntity());
long limit = selectQuery.getLimit();
long skip = selectQuery.getSkip();
List<String> documents = selectQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
List<Sort> sorts = selectQuery.getOrderBy().stream().map(s -> toSort(s, observer, collection)).collect(toList());
DocumentCondition condition = null;
if (selectQuery.getWhere().isPresent()) {
condition = selectQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, collection)).get();
}
return new DefaultDocumentQuery(limit, skip, collection, documents, sorts, condition);
}
use of jakarta.nosql.document.DocumentObserverParser in project jnosql-diana by eclipse.
the class SelectQueryParserTest method shouldReturnParserQuery12.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God where stamina >= -10.23" })
public void shouldReturnParserQuery12(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();
checkBaseQuery(documentQuery, 0L, 0L);
assertTrue(documentQuery.getCondition().isPresent());
DocumentCondition condition = documentQuery.getCondition().get();
assertEquals(Condition.GREATER_EQUALS_THAN, condition.getCondition());
assertEquals(Document.of("stamina", -10.23), condition.getDocument());
}
use of jakarta.nosql.document.DocumentObserverParser in project jnosql-diana by eclipse.
the class SelectQueryParserTest method shouldReturnParserQuery8.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "select * from God limit 12" })
public void shouldReturnParserQuery8(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();
checkBaseQuery(documentQuery, 12L, 0L);
assertFalse(documentQuery.getCondition().isPresent());
}
Aggregations