use of jakarta.nosql.mapping.Repository in project jnosql-diana by eclipse.
the class AbstractGraphRepositoryProxy method converter.
private Object converter(Method method, Class<?> typeClass, Supplier<Stream<?>> querySupplier, Object[] args) {
Supplier<Optional<?>> singleSupplier = DynamicReturn.toSingleResult(method).apply(querySupplier);
Function<Pagination, Page<?>> pageFunction = p -> {
throw new DynamicQueryException("Graph database repository does not support Page as return Type");
};
DynamicReturn<?> dynamicReturn = DynamicReturn.builder().withClassSource(typeClass).withMethodSource(method).withResult(querySupplier).withSingleResult(singleSupplier).withPagination(DynamicReturn.findPagination(args)).withStreamPagination(p -> querySupplier.get()).withSingleResultPagination(p -> singleSupplier.get()).withPage(pageFunction).build();
return dynamicReturn.execute();
}
use of jakarta.nosql.mapping.Repository in project jnosql-diana by eclipse.
the class RepositoryGraphBean method create.
@Override
public Repository create(CreationalContext<Repository> creationalContext) {
ClassMappings classMappings = getInstance(ClassMappings.class);
GraphTemplate repository = provider.isEmpty() ? getInstance(GraphTemplate.class) : getInstance(GraphTemplate.class, DatabaseQualifier.ofGraph(provider));
GraphConverter converter = getInstance(GraphConverter.class);
Graph graph = provider.isEmpty() ? getInstance(Graph.class) : getInstance(Graph.class, DatabaseQualifier.ofGraph(provider));
Converters converters = getInstance(Converters.class);
GraphRepositoryProxy handler = new GraphRepositoryProxy(repository, classMappings, type, graph, converter, converters);
return (Repository) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler);
}
use of jakarta.nosql.mapping.Repository in project jnosql-diana by eclipse.
the class RepositoryKeyValueBean method create.
@Override
public Repository create(CreationalContext<Repository> creationalContext) {
KeyValueTemplate repository = provider.isEmpty() ? getInstance(KeyValueTemplate.class) : getInstance(KeyValueTemplate.class, DatabaseQualifier.ofKeyValue(provider));
KeyValueRepositoryProxy handler = new KeyValueRepositoryProxy(type, repository);
return (Repository) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler);
}
use of jakarta.nosql.mapping.Repository in project jnosql-diana by eclipse.
the class RepositoryDocumentBean method create.
@Override
public Repository create(CreationalContext<Repository> context) {
ClassMappings classMappings = getInstance(ClassMappings.class);
DocumentTemplate template = provider.isEmpty() ? getInstance(DocumentTemplate.class) : getInstance(DocumentTemplate.class, DatabaseQualifier.ofDocument(provider));
Converters converters = getInstance(Converters.class);
DocumentRepositoryProxy handler = new DocumentRepositoryProxy(template, classMappings, type, converters);
return (Repository) Proxy.newProxyInstance(type.getClassLoader(), new Class[] { type }, handler);
}
use of jakarta.nosql.mapping.Repository in project jnosql-diana by eclipse.
the class AbstractKeyValueRepositoryProxy method invoke.
@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
RepositoryType type = RepositoryType.of(method);
switch(type) {
case DEFAULT:
return method.invoke(getRepository(), args);
case OBJECT_METHOD:
return method.invoke(this, args);
case JNOSQL_QUERY:
Class<?> typeClass = getEntityClass();
DynamicQueryMethodReturn methodReturn = DynamicQueryMethodReturn.builder().withArgs(args).withMethod(method).withTypeClass(typeClass).withPrepareConverter(q -> getTemplate().prepare(q, typeClass)).withQueryConverter(q -> getTemplate().query(q, typeClass)).build();
return methodReturn.execute();
default:
throw new DynamicQueryException("Key Value repository does not support query method");
}
}
Aggregations