Search in sources :

Example 6 with DynamicQueryMethodReturn

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

Example 7 with DynamicQueryMethodReturn

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

the class AbstractColumnRepositoryProxy 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:
            ColumnQuery query = getQuery(method, args);
            return executeQuery(method, args, typeClass, query);
        case FIND_ALL:
            ColumnQuery queryFindAll = ColumnQuery.select().from(getClassMapping().getName()).build();
            return executeQuery(method, args, typeClass, getQuerySorts(args, queryFindAll));
        case DELETE_BY:
            ColumnDeleteQuery deleteQuery = getDeleteQuery(method, args);
            getTemplate().delete(deleteQuery);
            return Void.class;
        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) ColumnDeleteQuery(jakarta.nosql.column.ColumnDeleteQuery) Converters(jakarta.nosql.mapping.Converters) ColumnQuery(jakarta.nosql.column.ColumnQuery) DynamicQueryMethodReturn(org.eclipse.jnosql.mapping.repository.DynamicQueryMethodReturn) InvocationHandler(java.lang.reflect.InvocationHandler) Method(java.lang.reflect.Method) ColumnQuery(jakarta.nosql.column.ColumnQuery) RepositoryType(org.eclipse.jnosql.mapping.query.RepositoryType) 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