Search in sources :

Example 11 with QueryException

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

the class UpdateQueryParser method query.

Stream<ColumnEntity> query(String query, ColumnFamilyManager manager, ColumnObserverParser observer) {
    UpdateQuery updateQuery = updateQueryProvider.apply(query);
    Params params = Params.newParams();
    ColumnEntity 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(manager.update(entity));
}
Also used : QueryException(jakarta.nosql.QueryException) ColumnEntity(jakarta.nosql.column.ColumnEntity) UpdateQuery(jakarta.nosql.query.UpdateQuery) Params(jakarta.nosql.Params)

Example 12 with QueryException

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

the class InsertQueryParser method query.

Stream<ColumnEntity> query(String query, ColumnFamilyManager manager, ColumnObserverParser observer) {
    InsertQuery insertQuery = insertQueryProvider.apply(query);
    String columnFamily = insertQuery.getEntity();
    Params params = Params.newParams();
    ColumnEntity entity = getEntity(insertQuery, columnFamily, 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(manager.insert(entity, ttl.get()));
    } else {
        return Stream.of(manager.insert(entity));
    }
}
Also used : InsertQuery(jakarta.nosql.query.InsertQuery) QueryException(jakarta.nosql.QueryException) ColumnEntity(jakarta.nosql.column.ColumnEntity) Params(jakarta.nosql.Params) Duration(java.time.Duration)

Example 13 with QueryException

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

the class ConditionQueryParser method getEntity.

protected ColumnEntity getEntity(ConditionQuerySupplier query, String columnFamily, Params params, ColumnObserverParser observer) {
    ColumnEntity entity = ColumnEntity.of(columnFamily);
    if (query.useJSONCondition()) {
        JSONQueryValue jsonValue = query.getValue().orElseThrow(() -> new QueryException("It is an invalid state of" + " either Update or Insert."));
        List<Column> columns = JsonObjects.getColumns(jsonValue.get());
        entity.addAll(columns);
        return entity;
    }
    query.getConditions().stream().map(c -> Conditions.getCondition(c, params, observer, columnFamily)).map(ColumnCondition::getColumn).forEach(entity::add);
    return entity;
}
Also used : QueryException(jakarta.nosql.QueryException) ColumnEntity(jakarta.nosql.column.ColumnEntity) Column(jakarta.nosql.column.Column) JSONQueryValue(jakarta.nosql.query.JSONQueryValue)

Example 14 with QueryException

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

the class DelQueryParser method query.

Stream<Value> query(String query, BucketManager manager) {
    DelQuery delQuery = provider.apply(query);
    Params params = Params.newParams();
    List<Value> values = delQuery.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.");
    }
    List<Object> keys = values.stream().map(Value::get).collect(toList());
    manager.delete(keys);
    return Stream.empty();
}
Also used : Value(jakarta.nosql.Value) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) DelQuery(jakarta.nosql.query.DelQuery) QueryException(jakarta.nosql.QueryException) BucketManager(jakarta.nosql.keyvalue.BucketManager) KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) DelQueryProvider(jakarta.nosql.query.DelQuery.DelQueryProvider) Params(jakarta.nosql.Params) DelQuery(jakarta.nosql.query.DelQuery) QueryException(jakarta.nosql.QueryException) Value(jakarta.nosql.Value) Params(jakarta.nosql.Params)

Example 15 with QueryException

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

the class PutQueryParser method query.

Stream<Value> query(String query, BucketManager manager) {
    PutQuery putQuery = provider.apply(query);
    Params params = Params.newParams();
    Value key = Values.getValue(putQuery.getKey(), params);
    Value value = Values.getValue(putQuery.getValue(), params);
    Optional<Duration> ttl = putQuery.getTtl();
    if (params.isNotEmpty()) {
        throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
    }
    KeyValueEntity entity = KeyValueEntity.of(key.get(), value.get());
    if (ttl.isPresent()) {
        manager.put(entity, ttl.get());
    } else {
        manager.put(entity);
    }
    return Stream.empty();
}
Also used : QueryException(jakarta.nosql.QueryException) Value(jakarta.nosql.Value) Params(jakarta.nosql.Params) Duration(java.time.Duration) PutQuery(jakarta.nosql.query.PutQuery) KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity)

Aggregations

QueryException (jakarta.nosql.QueryException)17 Params (jakarta.nosql.Params)14 Stream (java.util.stream.Stream)9 Collectors.toList (java.util.stream.Collectors.toList)7 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)6 List (java.util.List)6 ColumnEntity (jakarta.nosql.column.ColumnEntity)5 DocumentEntity (jakarta.nosql.document.DocumentEntity)5 Value (jakarta.nosql.Value)4 Function (jakarta.nosql.query.Function)4 JSONQueryValue (jakarta.nosql.query.JSONQueryValue)4 Collectors (java.util.stream.Collectors)4 ArrayQueryValue (jakarta.nosql.query.ArrayQueryValue)3 Objects (java.util.Objects)3 Sort (jakarta.nosql.Sort)2 ColumnCondition (jakarta.nosql.column.ColumnCondition)2 ColumnFamilyManager (jakarta.nosql.column.ColumnFamilyManager)2 ColumnObserverParser (jakarta.nosql.column.ColumnObserverParser)2 ColumnPreparedStatement (jakarta.nosql.column.ColumnPreparedStatement)2 DocumentCollectionManager (jakarta.nosql.document.DocumentCollectionManager)2