Search in sources :

Example 1 with RepositoryType

use of org.eclipse.jnosql.mapping.query.RepositoryType 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 RepositoryType

use of org.eclipse.jnosql.mapping.query.RepositoryType in project jnosql-diana by eclipse.

the class ReactiveRepositoryType method of.

/**
 * Returns a operation type from the {@link Method}
 *
 * @param method the method
 * @return a repository type
 */
public static RepositoryType of(Method method) {
    Objects.requireNonNull(method, "method is required");
    Class<?> declaringClass = method.getDeclaringClass();
    if (IS_REPOSITORY_METHOD.test(declaringClass)) {
        return RepositoryType.DEFAULT;
    }
    final RepositoryType type = RepositoryType.of(method);
    if (RepositoryType.DEFAULT.equals(type)) {
        return RepositoryType.UNKNOWN;
    }
    return type;
}
Also used : RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType)

Example 3 with RepositoryType

use of org.eclipse.jnosql.mapping.query.RepositoryType in project jnosql-diana by eclipse.

the class ReactiveRepositoryTypeTest method shouldReturnFindAll.

@Test
public void shouldReturnFindAll() {
    final Method method = Stream.of(MockReactiveRepository.class.getDeclaredMethods()).filter(m -> "findAll".equals(m.getName())).findFirst().get();
    final RepositoryType type = ReactiveRepositoryType.of(method);
    Assertions.assertEquals(RepositoryType.FIND_ALL, type);
}
Also used : RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 4 with RepositoryType

use of org.eclipse.jnosql.mapping.query.RepositoryType in project jnosql-diana by eclipse.

the class ReactiveRepositoryTypeTest method shouldReturnJNoSQLQuery.

@Test
public void shouldReturnJNoSQLQuery() {
    final Method method = Stream.of(MockReactiveRepository.class.getDeclaredMethods()).filter(m -> "query".equals(m.getName())).findFirst().get();
    final RepositoryType type = ReactiveRepositoryType.of(method);
    Assertions.assertEquals(RepositoryType.JNOSQL_QUERY, type);
}
Also used : RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 5 with RepositoryType

use of org.eclipse.jnosql.mapping.query.RepositoryType 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)

Aggregations

RepositoryType (org.eclipse.jnosql.mapping.query.RepositoryType)13 Method (java.lang.reflect.Method)12 InvocationHandler (java.lang.reflect.InvocationHandler)7 DynamicQueryMethodReturn (org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn)7 Test (org.junit.jupiter.api.Test)5 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