Search in sources :

Example 1 with Repository

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();
}
Also used : RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) GraphConverter(org.eclipse.jnosql.mapping.graph.GraphConverter) ClassMapping(org.eclipse.jnosql.mapping.reflection.ClassMapping) DynamicReturn(org.eclipse.jnosql.mapping.repository.DynamicReturn) Graph(org.apache.tinkerpop.gremlin.structure.Graph) Converters(jakarta.nosql.mapping.Converters) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Repository(jakarta.nosql.mapping.Repository) List(java.util.List) Stream(java.util.stream.Stream) GraphTemplate(org.eclipse.jnosql.mapping.graph.GraphTemplate) Optional(java.util.Optional) DynamicQueryException(jakarta.nosql.mapping.DynamicQueryException) DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) InvocationHandler(java.lang.reflect.InvocationHandler) Pagination(jakarta.nosql.mapping.Pagination) Method(java.lang.reflect.Method) Page(jakarta.nosql.mapping.Page) Pagination(jakarta.nosql.mapping.Pagination) Optional(java.util.Optional) DynamicQueryException(jakarta.nosql.mapping.DynamicQueryException) Page(jakarta.nosql.mapping.Page)

Example 2 with Repository

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);
}
Also used : Repository(jakarta.nosql.mapping.Repository) Graph(org.apache.tinkerpop.gremlin.structure.Graph) GraphTemplate(org.eclipse.jnosql.mapping.graph.GraphTemplate) Converters(jakarta.nosql.mapping.Converters) GraphConverter(org.eclipse.jnosql.mapping.graph.GraphConverter) ClassMappings(org.eclipse.jnosql.mapping.reflection.ClassMappings)

Example 3 with Repository

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);
}
Also used : Repository(jakarta.nosql.mapping.Repository) KeyValueTemplate(jakarta.nosql.mapping.keyvalue.KeyValueTemplate)

Example 4 with Repository

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);
}
Also used : Repository(jakarta.nosql.mapping.Repository) Converters(jakarta.nosql.mapping.Converters) DocumentTemplate(jakarta.nosql.mapping.document.DocumentTemplate) ClassMappings(org.eclipse.jnosql.mapping.reflection.ClassMappings)

Example 5 with Repository

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");
    }
}
Also used : DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) Repository(jakarta.nosql.mapping.Repository) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) KeyValueTemplate(jakarta.nosql.mapping.keyvalue.KeyValueTemplate) DynamicQueryException(jakarta.nosql.mapping.DynamicQueryException) DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) InvocationHandler(java.lang.reflect.InvocationHandler) Method(java.lang.reflect.Method) DynamicQueryException(jakarta.nosql.mapping.DynamicQueryException) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType)

Aggregations

Repository (jakarta.nosql.mapping.Repository)6 Converters (jakarta.nosql.mapping.Converters)4 ClassMappings (org.eclipse.jnosql.mapping.reflection.ClassMappings)3 DynamicQueryException (jakarta.nosql.mapping.DynamicQueryException)2 KeyValueTemplate (jakarta.nosql.mapping.keyvalue.KeyValueTemplate)2 InvocationHandler (java.lang.reflect.InvocationHandler)2 Method (java.lang.reflect.Method)2 Graph (org.apache.tinkerpop.gremlin.structure.Graph)2 GraphConverter (org.eclipse.jnosql.mapping.graph.GraphConverter)2 GraphTemplate (org.eclipse.jnosql.mapping.graph.GraphTemplate)2 RepositoryType (org.eclipse.jnosql.mapping.query.RepositoryType)2 DynamicQueryMethodReturn (org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn)2 Page (jakarta.nosql.mapping.Page)1 Pagination (jakarta.nosql.mapping.Pagination)1 ColumnTemplate (jakarta.nosql.mapping.column.ColumnTemplate)1 DocumentTemplate (jakarta.nosql.mapping.document.DocumentTemplate)1 List (java.util.List)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1