Search in sources :

Example 1 with GetQuery

use of jakarta.nosql.query.GetQuery 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);
}
Also used : Value(jakarta.nosql.Value) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) QueryException(jakarta.nosql.QueryException) GetQueryProvider(jakarta.nosql.query.GetQuery.GetQueryProvider) Optional(java.util.Optional) BucketManager(jakarta.nosql.keyvalue.BucketManager) KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) GetQuery(jakarta.nosql.query.GetQuery) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) Params(jakarta.nosql.Params) QueryException(jakarta.nosql.QueryException) Optional(java.util.Optional) GetQuery(jakarta.nosql.query.GetQuery) Value(jakarta.nosql.Value) Params(jakarta.nosql.Params)

Example 2 with GetQuery

use of jakarta.nosql.query.GetQuery 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);
}
Also used : Value(jakarta.nosql.Value) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) QueryException(jakarta.nosql.QueryException) GetQueryProvider(jakarta.nosql.query.GetQuery.GetQueryProvider) Optional(java.util.Optional) BucketManager(jakarta.nosql.keyvalue.BucketManager) KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) GetQuery(jakarta.nosql.query.GetQuery) ServiceLoaderProvider(jakarta.nosql.ServiceLoaderProvider) Params(jakarta.nosql.Params) GetQuery(jakarta.nosql.query.GetQuery) Value(jakarta.nosql.Value) Params(jakarta.nosql.Params)

Example 3 with GetQuery

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

the class GetProviderTest method shouldReturnParserQuery5.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get {1,12}" })
public void shouldReturnParserQuery5(String query) {
    GetQuery getQuery = queryProvider.apply(query);
    List<QueryValue<?>> keys = getQuery.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 : GetQuery(jakarta.nosql.query.GetQuery) 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 4 with GetQuery

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

the class GetProviderTest method shouldReturnParserQuery2.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get 12.12" })
public void shouldReturnParserQuery2(String query) {
    GetQuery getQuery = queryProvider.apply(query);
    List<QueryValue<?>> keys = getQuery.getKeys();
    assertEquals(1, keys.size());
    QueryValue<?> key = keys.get(0);
    assertTrue(key instanceof NumberQueryValue);
    assertEquals(12.12, NumberQueryValue.class.cast(key).get());
}
Also used : NumberQueryValue(jakarta.nosql.query.NumberQueryValue) GetQuery(jakarta.nosql.query.GetQuery) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) QueryValue(jakarta.nosql.query.QueryValue) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) StringQueryValue(jakarta.nosql.query.StringQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with GetQuery

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

the class GetProviderTest method shouldReturnParserQuery1.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get 12" })
public void shouldReturnParserQuery1(String query) {
    GetQuery getQuery = queryProvider.apply(query);
    List<QueryValue<?>> keys = getQuery.getKeys();
    assertEquals(1, keys.size());
    QueryValue<?> key = keys.get(0);
    assertTrue(key instanceof NumberQueryValue);
    assertEquals(12L, NumberQueryValue.class.cast(key).get());
}
Also used : NumberQueryValue(jakarta.nosql.query.NumberQueryValue) GetQuery(jakarta.nosql.query.GetQuery) NumberQueryValue(jakarta.nosql.query.NumberQueryValue) QueryValue(jakarta.nosql.query.QueryValue) ArrayQueryValue(jakarta.nosql.query.ArrayQueryValue) StringQueryValue(jakarta.nosql.query.StringQueryValue) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

GetQuery (jakarta.nosql.query.GetQuery)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 GetQueryProvider (jakarta.nosql.query.GetQuery.GetQueryProvider)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors.toList (java.util.stream.Collectors.toList)2 Stream (java.util.stream.Stream)2