Search in sources :

Example 6 with RepositoryType

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

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

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

Example 9 with RepositoryType

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

the class ReactiveRepositoryTypeTest method shouldReturnFindById.

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

Example 10 with RepositoryType

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

the class ReactiveRepositoryTypeTest method shouldReturnDeleteById.

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

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