Search in sources :

Example 6 with DelQuery

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

the class RemoveProviderTest method shouldReturnParserQuery5.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "del {1,12}" })
public void shouldReturnParserQuery5(String query) {
    DelQuery delQuery = provider.apply(query);
    List<QueryValue<?>> keys = delQuery.getKeys();
    assertEquals(1, keys.size());
    QueryValue<?> key = keys.get(0);
    assertTrue(key instanceof ArrayQueryValue);
    QueryValue<?>[] values = ArrayQueryValue.class.cast(key).get();
    MatcherAssert.assertThat(Arrays.stream(values).map(QueryValue::get).collect(Collectors.toList()), Matchers.contains(1L, 12L));
}
Also used : DelQuery(jakarta.nosql.query.DelQuery) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) QueryValue(jakarta.nosql.query.QueryValue) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) StringQueryValue(jakarta.nosql.query.StringQueryValue) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with DelQuery

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

the class DelQueryParser method prepare.

public KeyValuePreparedStatement prepare(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());
    return DefaultKeyValuePreparedStatement.del(values, manager, params, query);
}
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) Value(jakarta.nosql.Value) Params(jakarta.nosql.Params)

Example 8 with DelQuery

use of jakarta.nosql.query.DelQuery 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)

Aggregations

DelQuery (jakarta.nosql.query.DelQuery)8 ArrayQueryValue (jakarta.nosql.query.ArrayQueryValue)6 NumberQueryValue (jakarta.nosql.query.NumberQueryValue)6 QueryValue (jakarta.nosql.query.QueryValue)6 StringQueryValue (jakarta.nosql.query.StringQueryValue)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ValueSource (org.junit.jupiter.params.provider.ValueSource)6 Params (jakarta.nosql.Params)2 QueryException (jakarta.nosql.QueryException)2 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)2 Value (jakarta.nosql.Value)2 BucketManager (jakarta.nosql.keyvalue.BucketManager)2 KeyValuePreparedStatement (jakarta.nosql.keyvalue.KeyValuePreparedStatement)2 DelQueryProvider (jakarta.nosql.query.DelQuery.DelQueryProvider)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 Stream (java.util.stream.Stream)2