Search in sources :

Example 1 with DynamicQueryException

use of jakarta.nosql.mapping.DynamicQueryException 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 DynamicQueryException

use of jakarta.nosql.mapping.DynamicQueryException in project jnosql-diana by eclipse.

the class AbstractReactiveKeyValueRepositoryProxy method invoke.

@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
    RepositoryType type = ReactiveRepositoryType.of(method);
    switch(type) {
        case DEFAULT:
            return method.invoke(getReactiveRepository(), 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) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) ReactiveRepositoryType(org.eclipse.jnosql.mapping.reactive.ReactiveRepositoryType) ReactiveRepository(org.eclipse.jnosql.mapping.reactive.ReactiveRepository) 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) ReactiveRepositoryType(org.eclipse.jnosql.mapping.reactive.ReactiveRepositoryType)

Example 3 with DynamicQueryException

use of jakarta.nosql.mapping.DynamicQueryException 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

DynamicQueryException (jakarta.nosql.mapping.DynamicQueryException)3 InvocationHandler (java.lang.reflect.InvocationHandler)3 Method (java.lang.reflect.Method)3 RepositoryType (org.eclipse.jnosql.mapping.query.RepositoryType)3 DynamicQueryMethodReturn (org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn)3 Repository (jakarta.nosql.mapping.Repository)2 KeyValueTemplate (jakarta.nosql.mapping.keyvalue.KeyValueTemplate)2 Converters (jakarta.nosql.mapping.Converters)1 Page (jakarta.nosql.mapping.Page)1 Pagination (jakarta.nosql.mapping.Pagination)1 List (java.util.List)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 Stream (java.util.stream.Stream)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1 Graph (org.apache.tinkerpop.gremlin.structure.Graph)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1 GraphConverter (org.eclipse.jnosql.mapping.graph.GraphConverter)1 GraphTemplate (org.eclipse.jnosql.mapping.graph.GraphTemplate)1