use of jakarta.nosql.Params in project jnosql-diana by eclipse.
the class ColumnParamsTest method shouldSetParameter.
@Test
public void shouldSetParameter() {
Params params = Params.newParams();
Value name = params.add("name");
Column column = Column.of("name", name);
params.bind("name", "Ada Lovelace");
assertEquals("Ada Lovelace", column.get());
params.bind("name", "Diana");
assertEquals("Diana", column.get());
}
use of jakarta.nosql.Params in project jnosql-diana by eclipse.
the class BaseColumnRepository method getDeleteQuery.
protected ColumnDeleteQuery getDeleteQuery(Method method, Object[] args) {
DeleteMethodProvider deleteMethodFactory = DeleteMethodProvider.get();
DeleteQuery deleteQuery = deleteMethodFactory.apply(method, getClassMapping().getName());
ColumnDeleteQueryParams queryParams = DELETE_CONVERTER.apply(deleteQuery, getParser());
ColumnDeleteQuery query = queryParams.getQuery();
Params params = queryParams.getParams();
getParamsBinder().bind(params, args, method);
return query;
}
use of jakarta.nosql.Params in project jnosql-diana by eclipse.
the class ParamsBinderTest method shouldConvert2.
@Test
public void shouldConvert2() {
Method method = Stream.of(PersonRepository.class.getMethods()).filter(m -> m.getName().equals("findByAgeAndName")).findFirst().get();
ClassMapping classMapping = mappings.get(Person.class);
RepositoryDocumentObserverParser parser = new RepositoryDocumentObserverParser(classMapping);
paramsBinder = new ParamsBinder(classMapping, converters);
SelectMethodProvider selectMethodFactory = SelectMethodProvider.get();
SelectQuery selectQuery = selectMethodFactory.apply(method, classMapping.getName());
SelectQueryConverter converter = ServiceLoaderProvider.get(SelectQueryConverter.class);
DocumentQueryParams queryParams = converter.apply(selectQuery, parser);
Params params = queryParams.getParams();
paramsBinder.bind(params, new Object[] { 10L, "Ada" }, method);
DocumentQuery query = queryParams.getQuery();
DocumentCondition columnCondition = query.getCondition().get();
List<DocumentCondition> conditions = columnCondition.getDocument().get(new TypeReference<List<DocumentCondition>>() {
});
List<Object> values = conditions.stream().map(DocumentCondition::getDocument).map(Document::getValue).map(Value::get).collect(Collectors.toList());
assertEquals(10, values.get(0));
assertEquals("Ada", values.get(1));
}
use of jakarta.nosql.Params in project jnosql-diana by eclipse.
the class DeleteQueryParser method getQuery.
private DocumentDeleteQuery getQuery(Params params, DocumentObserverParser observer, DeleteQuery deleteQuery) {
String collection = observer.fireEntity(deleteQuery.getEntity());
List<String> documents = deleteQuery.getFields().stream().map(f -> observer.fireField(collection, f)).collect(Collectors.toList());
DocumentCondition condition = null;
if (deleteQuery.getWhere().isPresent()) {
condition = deleteQuery.getWhere().map(c -> Conditions.getCondition(c, params, observer, collection)).get();
}
return new DefaultDocumentDeleteQuery(collection, condition, documents);
}
use of jakarta.nosql.Params in project jnosql-diana by eclipse.
the class DeleteQueryParser method prepare.
DocumentPreparedStatement prepare(String query, DocumentCollectionManager collectionManager, DocumentObserverParser observer) {
Params params = Params.newParams();
DocumentDeleteQuery documentQuery = getQuery(query, params, observer);
return DefaultDocumentPreparedStatement.delete(documentQuery, params, query, collectionManager);
}
Aggregations