Search in sources :

Example 6 with KeyValuePreparedStatement

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

the class DelQueryParserTest method shouldReturnErrorWhenDontBindParameters.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "del @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 7 with KeyValuePreparedStatement

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

the class DelQueryParserTest method shouldExecutePrepareStatement2.

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

Example 8 with KeyValuePreparedStatement

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

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

the class DefaultKeyValueQueryParserTest method shouldExecutePrepareStatement2.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "put {\"Diana\", @value, 10 second}" })
public void shouldExecutePrepareStatement2(String query) {
    KeyValuePreparedStatement prepare = parser.prepare(query, manager);
    prepare.bind("value", "Hunt");
    prepare.getResult();
    ArgumentCaptor<KeyValueEntity> captor = ArgumentCaptor.forClass(KeyValueEntity.class);
    ArgumentCaptor<Duration> durationCaptor = ArgumentCaptor.forClass(Duration.class);
    Mockito.verify(manager).put(captor.capture(), durationCaptor.capture());
    KeyValueEntity entity = captor.getValue();
    final Duration duration = durationCaptor.getValue();
    assertEquals("Diana", entity.getKey());
    assertEquals("Hunt", entity.getValue());
    assertEquals(Duration.ofSeconds(10L), duration);
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) Duration(java.time.Duration) KeyValueEntity(jakarta.nosql.keyvalue.KeyValueEntity) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with KeyValuePreparedStatement

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

the class DefaultKeyValueQueryParserTest method shouldReturnSingleResult.

@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "get @id" })
public void shouldReturnSingleResult(String query) {
    Mockito.when(manager.get(10)).thenReturn(Optional.of(Value.of(10L)));
    ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(List.class);
    KeyValuePreparedStatement prepare = parser.prepare(query, manager);
    prepare.bind("id", 10);
    final Optional<Value> result = prepare.getSingleResult();
    Mockito.verify(manager).get(captor.capture());
    List<Object> value = captor.getAllValues();
    assertEquals(1, value.size());
    MatcherAssert.assertThat(value, Matchers.contains(10));
    assertEquals(10L, result.get().get());
}
Also used : KeyValuePreparedStatement(jakarta.nosql.keyvalue.KeyValuePreparedStatement) Value(jakarta.nosql.Value) 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