Search in sources :

Example 1 with KeyValuePreparedStatement

use of jakarta.nosql.keyvalue.KeyValuePreparedStatement 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 2 with KeyValuePreparedStatement

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

the class GetQueryParserTest method shouldExecutePrepareStatement2.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get @id, @id2" })
public void shouldExecutePrepareStatement2(String query) {
    ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(List.class);
    KeyValuePreparedStatement prepare = parser.prepare(query, manager);
    prepare.bind("id", 10);
    prepare.bind("id2", 11);
    final Stream<Value> stream = prepare.getResult();
    stream.collect(Collectors.toList());
    verify(manager, Mockito.times(2)).get(captor.capture());
    List<Object> value = captor.getAllValues();
    assertEquals(2, value.size());
    MatcherAssert.assertThat(value, Matchers.contains(10, 11));
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) Value(jakarta.nosql.Value) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with KeyValuePreparedStatement

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

the class GetQueryParserTest method shouldReturnErrorWhenDontBindParameters.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get @id" })
public void shouldReturnErrorWhenDontBindParameters(String query) {
    KeyValuePreparedStatement prepare = parser.prepare(query, manager);
    assertThrows(QueryException.class, prepare::getResult);
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with KeyValuePreparedStatement

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

the class PutQueryParserTest method shouldReturnErrorWhenDontBindParameters.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "put {\"Diana\", @value}" })
public void shouldReturnErrorWhenDontBindParameters(String query) {
    KeyValuePreparedStatement prepare = parser.prepare(query, manager);
    assertThrows(QueryException.class, prepare::getResult);
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with KeyValuePreparedStatement

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

the class DelQueryParserTest method shouldExecutePrepareStatement.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "del @id" })
public void shouldExecutePrepareStatement(String query) {
    ArgumentCaptor<List<Object>> captor = ArgumentCaptor.forClass(List.class);
    KeyValuePreparedStatement prepare = parser.prepare(query, manager);
    prepare.bind("id", 10);
    prepare.getResult();
    Mockito.verify(manager).delete(captor.capture());
    List<Object> value = captor.getValue();
    assertEquals(1, value.size());
    MatcherAssert.assertThat(value, Matchers.contains(10));
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) List(java.util.List) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

KeyValuePreparedStatement (jakarta.nosql.keyvalue.KeyValuePreparedStatement)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 ValueSource (org.junit.jupiter.params.provider.ValueSource)14 Value (jakarta.nosql.Value)5 List (java.util.List)5 KeyValueEntity (jakarta.nosql.keyvalue.KeyValueEntity)3 Params (jakarta.nosql.Params)2 QueryException (jakarta.nosql.QueryException)2 ServiceLoaderProvider (jakarta.nosql.ServiceLoaderProvider)2 BucketManager (jakarta.nosql.keyvalue.BucketManager)2 Collectors.toList (java.util.stream.Collectors.toList)2 Stream (java.util.stream.Stream)2 PreparedStatement (jakarta.nosql.mapping.PreparedStatement)1 DelQuery (jakarta.nosql.query.DelQuery)1 DelQueryProvider (jakarta.nosql.query.DelQuery.DelQueryProvider)1 GetQuery (jakarta.nosql.query.GetQuery)1 GetQueryProvider (jakarta.nosql.query.GetQuery.GetQueryProvider)1 Duration (java.time.Duration)1 Optional (java.util.Optional)1 Test (org.junit.jupiter.api.Test)1