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