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;
}
}
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;
}
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);
}
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);
}
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;
}
}
Aggregations