Search in sources :

Example 1 with DynamicQueryMethodReturn

use of org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn in project jnosql-diana by eclipse.

the class AbstractGraphRepositoryProxy method invoke.

@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
    RepositoryType type = RepositoryType.of(method);
    Class<?> typeClass = getClassMapping().getClassInstance();
    switch(type) {
        case DEFAULT:
            return method.invoke(getRepository(), args);
        case FIND_BY:
            return findBy(method, args, typeClass);
        case FIND_ALL:
            return findAll(method, typeClass, args);
        case DELETE_BY:
            return executeDeleteMethod(method, args);
        case OBJECT_METHOD:
            return method.invoke(this, args);
        case UNKNOWN:
        case JNOSQL_QUERY:
            DynamicQueryMethodReturn methodReturn = DynamicQueryMethodReturn.builder().withArgs(args).withMethod(method).withTypeClass(typeClass).withPrepareConverter(q -> getTemplate().prepare(q)).withQueryConverter(q -> getTemplate().query(q)).build();
            return methodReturn.execute();
        default:
            return Void.class;
    }
}
Also used : DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) 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) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType)

Example 2 with DynamicQueryMethodReturn

use of org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn in project jnosql-diana by eclipse.

the class AbstractReactiveDocumentRepositoryProxy method invoke.

@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
    RepositoryType type = ReactiveRepositoryType.of(method);
    Class<?> typeClass = getClassMapping().getClassInstance();
    switch(type) {
        case DEFAULT:
            return method.invoke(getRepository(), args);
        case FIND_BY:
            DocumentQuery query = getQuery(method, args);
            return executeQuery(method, args, typeClass, query);
        case FIND_ALL:
            DocumentQuery queryFindAll = select().from(getClassMapping().getName()).build();
            return executeQuery(method, args, typeClass, getQuerySorts(args, queryFindAll));
        case DELETE_BY:
            DocumentDeleteQuery documentDeleteQuery = getDeleteQuery(method, args);
            Iterable<Void> iterable = () -> {
                getTemplate().delete(documentDeleteQuery);
                return Collections.emptyIterator();
            };
            return ReactiveStreams.fromIterable(iterable).buildRs();
        case OBJECT_METHOD:
            return method.invoke(this, args);
        case JNOSQL_QUERY:
            DynamicQueryMethodReturn methodReturn = DynamicQueryMethodReturn.builder().withArgs(args).withMethod(method).withTypeClass(typeClass).withPrepareConverter(q -> getTemplate().prepare(q)).withQueryConverter(q -> getTemplate().query(q)).build();
            return methodReturn.execute();
        default:
            return Void.class;
    }
}
Also used : DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) ReactiveRepositoryType(org.eclipse.jnosql.mapping.reactive.ReactiveRepositoryType) DocumentQuery.select(jakarta.nosql.document.DocumentQuery.select) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) DocumentTemplate(jakarta.nosql.mapping.document.DocumentTemplate) ReactiveRepository(org.eclipse.jnosql.mapping.reactive.ReactiveRepository) DocumentQuery(jakarta.nosql.document.DocumentQuery) BaseDocumentRepository(org.eclipse.jnosql.mapping.document.query.BaseDocumentRepository) DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) InvocationHandler(java.lang.reflect.InvocationHandler) ReactiveStreams(org.eclipse.microprofile.reactive.streams.operators.ReactiveStreams) Method(java.lang.reflect.Method) Collections(java.util.Collections) DocumentQuery(jakarta.nosql.document.DocumentQuery) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) ReactiveRepositoryType(org.eclipse.jnosql.mapping.reactive.ReactiveRepositoryType) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery)

Example 3 with DynamicQueryMethodReturn

use of org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn 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 4 with DynamicQueryMethodReturn

use of org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn in project jnosql-diana by eclipse.

the class AbstractDocumentRepositoryProxy method invoke.

@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
    RepositoryType type = RepositoryType.of(method);
    Class<?> typeClass = getClassMapping().getClassInstance();
    switch(type) {
        case DEFAULT:
            return method.invoke(getRepository(), args);
        case FIND_BY:
            DocumentQuery query = getQuery(method, args);
            return executeQuery(method, args, typeClass, query);
        case FIND_ALL:
            DocumentQuery queryFindAll = select().from(getClassMapping().getName()).build();
            return executeQuery(method, args, typeClass, getQuerySorts(args, queryFindAll));
        case DELETE_BY:
            DocumentDeleteQuery documentDeleteQuery = getDeleteQuery(method, args);
            getTemplate().delete(documentDeleteQuery);
            return null;
        case OBJECT_METHOD:
            return method.invoke(this, args);
        case JNOSQL_QUERY:
            DynamicQueryMethodReturn methodReturn = DynamicQueryMethodReturn.builder().withArgs(args).withMethod(method).withTypeClass(typeClass).withPrepareConverter(q -> getTemplate().prepare(q)).withQueryConverter(q -> getTemplate().query(q)).build();
            return methodReturn.execute();
        default:
            return Void.class;
    }
}
Also used : DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) Repository(jakarta.nosql.mapping.Repository) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) DocumentQuery(jakarta.nosql.document.DocumentQuery) DocumentQuery.select(jakarta.nosql.document.DocumentQuery.select) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery) DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) InvocationHandler(java.lang.reflect.InvocationHandler) Method(java.lang.reflect.Method) DocumentQuery(jakarta.nosql.document.DocumentQuery) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) DocumentDeleteQuery(jakarta.nosql.document.DocumentDeleteQuery)

Example 5 with DynamicQueryMethodReturn

use of org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn in project jnosql-diana by eclipse.

the class AbstractReactiveColumnRepositoryProxy method invoke.

@Override
public Object invoke(Object instance, Method method, Object[] args) throws Throwable {
    RepositoryType type = ReactiveRepositoryType.of(method);
    Class<?> typeClass = getClassMapping().getClassInstance();
    switch(type) {
        case DEFAULT:
            return method.invoke(getRepository(), args);
        case FIND_BY:
            ColumnQuery query = getQuery(method, args);
            return executeQuery(method, args, typeClass, query);
        case FIND_ALL:
            ColumnQuery queryFindAll = select().from(getClassMapping().getName()).build();
            return executeQuery(method, args, typeClass, getQuerySorts(args, queryFindAll));
        case DELETE_BY:
            ColumnDeleteQuery columnDeleteQuery = getDeleteQuery(method, args);
            Iterable<Void> iterable = () -> {
                getTemplate().delete(columnDeleteQuery);
                return Collections.emptyIterator();
            };
            return ReactiveStreams.fromIterable(iterable).buildRs();
        case OBJECT_METHOD:
            return method.invoke(this, args);
        case JNOSQL_QUERY:
            DynamicQueryMethodReturn methodReturn = DynamicQueryMethodReturn.builder().withArgs(args).withMethod(method).withTypeClass(typeClass).withPrepareConverter(q -> getTemplate().prepare(q)).withQueryConverter(q -> getTemplate().query(q)).build();
            return methodReturn.execute();
        default:
            return Void.class;
    }
}
Also used : DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) BaseColumnRepository(org.eclipse.jnosql.mapping.column.query.BaseColumnRepository) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) ReactiveRepositoryType(org.eclipse.jnosql.mapping.reactive.ReactiveRepositoryType) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) ColumnTemplate(jakarta.nosql.mapping.column.ColumnTemplate) ColumnQuery.select(jakarta.nosql.column.ColumnQuery.select) ReactiveRepository(org.eclipse.jnosql.mapping.reactive.ReactiveRepository) ColumnQuery(jakarta.nosql.column.ColumnQuery) DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) InvocationHandler(java.lang.reflect.InvocationHandler) ReactiveStreams(org.eclipse.microprofile.reactive.streams.operators.ReactiveStreams) Method(java.lang.reflect.Method) Collections(java.util.Collections) ColumnQuery(jakarta.nosql.column.ColumnQuery) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) ReactiveRepositoryType(org.eclipse.jnosql.mapping.reactive.ReactiveRepositoryType) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery)

Aggregations

InvocationHandler (java.lang.reflect.InvocationHandler)7 Method (java.lang.reflect.Method)7 RepositoryType (org.eclipse.jnosql.mapping.query.RepositoryType)7 DynamicQueryMethodReturn (org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn)7 Repository (jakarta.nosql.mapping.Repository)4 DynamicQueryException (jakarta.nosql.mapping.DynamicQueryException)3 ReactiveRepository (org.eclipse.jnosql.mapping.reactive.ReactiveRepository)3 ReactiveRepositoryType (org.eclipse.jnosql.mapping.reactive.ReactiveRepositoryType)3 ColumnDeleteQuery (jakarta.nosql.column.ColumnDeleteQuery)2 ColumnQuery (jakarta.nosql.column.ColumnQuery)2 DocumentDeleteQuery (jakarta.nosql.document.DocumentDeleteQuery)2 DocumentQuery (jakarta.nosql.document.DocumentQuery)2 DocumentQuery.select (jakarta.nosql.document.DocumentQuery.select)2 Converters (jakarta.nosql.mapping.Converters)2 KeyValueTemplate (jakarta.nosql.mapping.keyvalue.KeyValueTemplate)2 Collections (java.util.Collections)2 ReactiveStreams (org.eclipse.microprofile.reactive.streams.operators.ReactiveStreams)2 ColumnQuery.select (jakarta.nosql.column.ColumnQuery.select)1 Page (jakarta.nosql.mapping.Page)1 Pagination (jakarta.nosql.mapping.Pagination)1