use of jakarta.nosql.Params in project jnosql-diana by eclipse.
the class InsertQueryParser method query.
Stream<DocumentEntity> query(String query, DocumentCollectionManager collectionManager, DocumentObserverParser observer) {
InsertQuery insertQuery = insertQueryProvider.apply(query);
String collection = insertQuery.getEntity();
Params params = Params.newParams();
DocumentEntity entity = getEntity(insertQuery, collection, params, observer);
Optional<Duration> ttl = insertQuery.getTtl();
if (params.isNotEmpty()) {
throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
}
if (ttl.isPresent()) {
return Stream.of(collectionManager.insert(entity, ttl.get()));
} else {
return Stream.of(collectionManager.insert(entity));
}
}
use of jakarta.nosql.Params 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.Params 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.Params in project jnosql-diana by eclipse.
the class GetQueryParser method query.
Stream<Value> query(String query, BucketManager manager) {
GetQuery getQuery = provider.apply(query);
Params params = Params.newParams();
List<Value> values = getQuery.getKeys().stream().map(k -> Values.getValue(k, params)).collect(toList());
if (params.isNotEmpty()) {
throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
}
return values.stream().map(Value::get).map(manager::get).filter(Optional::isPresent).map(Optional::get);
}
use of jakarta.nosql.Params in project jnosql-diana by eclipse.
the class GetQueryParser method prepare.
public KeyValuePreparedStatement prepare(String query, BucketManager manager) {
GetQuery getQuery = provider.apply(query);
Params params = Params.newParams();
List<Value> values = getQuery.getKeys().stream().map(k -> Values.getValue(k, params)).collect(toList());
return DefaultKeyValuePreparedStatement.get(values, manager, params, query);
}
Aggregations