use of jakarta.nosql.QueryException in project jnosql-diana by eclipse.
the class Values method get.
static Object get(QueryValue<?> value, Params parameters) {
ValueType type = value.getType();
switch(type) {
case NUMBER:
case STRING:
return value.get();
case PARAMETER:
return parameters.add(ParamQueryValue.class.cast(value).get());
case ARRAY:
return Stream.of(ArrayQueryValue.class.cast(value).get()).map(v -> get(v, parameters)).collect(toList());
case FUNCTION:
Function function = FunctionQueryValue.class.cast(value).get();
String name = function.getName();
Object[] params = function.getParams();
if ("convert".equals(name)) {
return jakarta.nosql.Value.of(get(QueryValue.class.cast(params[0]), parameters)).get((Class<?>) params[1]);
}
String message = String.format("There is not support to the function: %s with parameters %s", name, Arrays.toString(params));
throw new QueryException(message);
case JSON:
return JsonObjects.getColumns(JSONQueryValue.class.cast(value).get());
case CONDITION:
default:
throw new QueryException("There is not support to the value: " + type);
}
}
use of jakarta.nosql.QueryException in project jnosql-diana by eclipse.
the class DeleteQueryParser method getQuery.
private ColumnDeleteQuery getQuery(String query, ColumnObserverParser observer) {
DeleteQuery deleteQuery = deleteQueryProvider.apply(query);
String columnFamily = observer.fireEntity(deleteQuery.getEntity());
List<String> columns = deleteQuery.getFields().stream().map(f -> observer.fireField(columnFamily, f)).collect(Collectors.toList());
ColumnCondition condition = null;
Params params = Params.newParams();
if (deleteQuery.getWhere().isPresent()) {
condition = deleteQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, columnFamily)).get();
}
if (params.isNotEmpty()) {
throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
}
return new DefaultColumnDeleteQuery(columnFamily, condition, columns);
}
use of jakarta.nosql.QueryException in project jnosql-diana by eclipse.
the class SelectQueryParser method getColumnQuery.
private ColumnQuery getColumnQuery(String query, ColumnObserverParser observer) {
SelectQuery selectQuery = selectQueryProvider.apply(query);
String columnFamily = observer.fireEntity(selectQuery.getEntity());
long limit = selectQuery.getLimit();
long skip = selectQuery.getSkip();
List<String> columns = selectQuery.getFields().stream().map(f -> observer.fireField(columnFamily, f)).collect(Collectors.toList());
List<Sort> sorts = selectQuery.getOrderBy().stream().map(s -> toSort(s, observer, columnFamily)).collect(toList());
ColumnCondition condition = null;
Params params = Params.newParams();
if (selectQuery.getWhere().isPresent()) {
condition = selectQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, columnFamily)).get();
}
if (params.isNotEmpty()) {
throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
}
return new DefaultColumnQuery(limit, skip, columnFamily, columns, sorts, condition);
}
use of jakarta.nosql.QueryException 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.QueryException in project jnosql-diana by eclipse.
the class UpdateQueryParser method query.
Stream<DocumentEntity> query(String query, DocumentCollectionManager collectionManager, DocumentObserverParser observer) {
UpdateQuery updateQuery = supplier.apply(query);
Params params = Params.newParams();
DocumentEntity entity = getEntity(params, updateQuery, observer);
if (params.isNotEmpty()) {
throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
}
return Stream.of(collectionManager.update(entity));
}
Aggregations