use of jakarta.nosql.query.PutQuery in project jnosql-diana by eclipse.
the class PutProviderTest method shouldReturnParserQuery6.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "put {@name, @value, 10 millisecond}\n" })
public void shouldReturnParserQuery6(String query) {
PutQuery putQuery = provider.apply(query);
QueryValue<?> key = putQuery.getKey();
QueryValue<?> value = putQuery.getValue();
Optional<Duration> ttl = putQuery.getTtl();
assertTrue(key instanceof ParamQueryValue);
assertEquals("name", ParamQueryValue.class.cast(key).get());
assertTrue(value instanceof ParamQueryValue);
assertEquals("value", ParamQueryValue.class.cast(value).get());
assertTrue(ttl.isPresent());
assertEquals(Duration.ofMillis(10L), ttl.get());
}
use of jakarta.nosql.query.PutQuery in project jnosql-diana by eclipse.
the class PutProviderTest method shouldReturnParserQuery.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "put {\"Ada\", \"Hunt\"}\n" })
public void shouldReturnParserQuery(String query) {
PutQuery putQuery = provider.apply(query);
QueryValue<?> key = putQuery.getKey();
QueryValue<?> value = putQuery.getValue();
Optional<Duration> ttl = putQuery.getTtl();
assertTrue(key instanceof StringQueryValue);
assertEquals("Ada", StringQueryValue.class.cast(key).get());
assertFalse(ttl.isPresent());
assertTrue(value instanceof StringQueryValue);
assertEquals("Hunt", StringQueryValue.class.cast(value).get());
assertFalse(ttl.isPresent());
}
use of jakarta.nosql.query.PutQuery in project jnosql-diana by eclipse.
the class PutProviderTest method shouldReturnParserQuery5.
@ParameterizedTest(name = "Should parser the query {0}")
@ValueSource(strings = { "put {@name, @value, 10 second}\n" })
public void shouldReturnParserQuery5(String query) {
PutQuery putQuery = provider.apply(query);
QueryValue<?> key = putQuery.getKey();
QueryValue<?> value = putQuery.getValue();
Optional<Duration> ttl = putQuery.getTtl();
assertTrue(key instanceof ParamQueryValue);
assertEquals("name", ParamQueryValue.class.cast(key).get());
assertTrue(value instanceof ParamQueryValue);
assertEquals("value", ParamQueryValue.class.cast(value).get());
assertTrue(ttl.isPresent());
assertEquals(Duration.ofSeconds(10L), ttl.get());
}
use of jakarta.nosql.query.PutQuery in project jnosql-diana by eclipse.
the class PutQueryParser method query.
Stream<Value> query(String query, BucketManager manager) {
PutQuery putQuery = provider.apply(query);
Params params = Params.newParams();
Value key = Values.getValue(putQuery.getKey(), params);
Value value = Values.getValue(putQuery.getValue(), params);
Optional<Duration> ttl = putQuery.getTtl();
if (params.isNotEmpty()) {
throw new QueryException("To run a query with a parameter use a PrepareStatement instead.");
}
KeyValueEntity entity = KeyValueEntity.of(key.get(), value.get());
if (ttl.isPresent()) {
manager.put(entity, ttl.get());
} else {
manager.put(entity);
}
return Stream.empty();
}
use of jakarta.nosql.query.PutQuery in project jnosql-diana by eclipse.
the class PutQueryParser method prepare.
public KeyValuePreparedStatement prepare(String query, BucketManager manager) {
PutQuery putQuery = provider.apply(query);
Params params = Params.newParams();
Value key = Values.getValue(putQuery.getKey(), params);
Value value = Values.getValue(putQuery.getValue(), params);
Optional<Duration> ttl = putQuery.getTtl();
return DefaultKeyValuePreparedStatement.put(key, value, manager, params, ttl.orElse(null), query);
}
Aggregations