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);
}
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));
}
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);
}
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);
}
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));
}
Aggregations