public ReactiveElasticsearchQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory, MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) { super(method, metadata, factory, mappingContext); this.method = method; if (hasParameterOfType(method, Pageable.class)) { TypeInformation<?> returnType = ClassTypeInformation.fromReturnTypeOf(method); boolean multiWrapper = ReactiveWrappers.isMultiValueType(returnType.getType()); boolean singleWrapperWithWrappedPageableResult = ReactiveWrappers.isSingleValueType(returnType.getType()) && (PAGE_TYPE.isAssignableFrom(returnType.getRequiredComponentType()) || SLICE_TYPE.isAssignableFrom(returnType.getRequiredComponentType())); if (singleWrapperWithWrappedPageableResult) { throw new InvalidDataAccessApiUsageException( String.format("'%s.%s' must not use sliced or paged execution. Please use Flux.buffer(size, skip).", ClassUtils.getShortName(method.getDeclaringClass()), method.getName())); } if (!multiWrapper) { throw new IllegalStateException(String.format( "Method has to use a either multi-item reactive wrapper return type or a wrapped Page/Slice type. Offending method: %s", method.toString())); } if (hasParameterOfType(method, Sort.class)) { throw new IllegalStateException(String.format("Method must not have Pageable *and* Sort parameter. " + "Use sorting capabilities on Pageble instead! Offending method: %s", method.toString())); } } }
public boolean hasCustomMethod() { Class<?> repositoryInterface = getRepositoryInterface(); // No detection required if no typing interface was configured if (isGenericRepositoryInterface(repositoryInterface)) { return false; } for (Method method : repositoryInterface.getMethods()) { if (isCustomMethod(method) && !isBaseClassMethod(method)) { return true; } } return false; }
if (getNumberOfOccurences(method, type) > 1) { throw new IllegalStateException(String.format("Method must only one argument of type %s! Offending method: %s", type.getSimpleName(), method.toString())); if (hasParameterOfType(method, Pageable.class)) { assertReturnTypeAssignable(method, Page.class, List.class); if (hasParameterOfType(method, Sort.class)) { throw new IllegalStateException(String.format("Method must not have Pageable *and* Sort parameter. " + "Use sorting capabilities on Pageble instead! Offending method: %s", method.toString()));
.filter(type -> getNumberOfOccurences(method, type) > 1)// .findFirst().ifPresent(type -> { throw new IllegalStateException( this.metadata = metadata; if (hasParameterOfType(method, Pageable.class)) { if (hasParameterOfType(method, Sort.class)) { throw new IllegalStateException(String.format("Method must not have Pageable *and* Sort parameter. " + "Use sorting capabilities on Pageable instead! Offending method: %s", method.toString()));
/** * Executes the given method on the given target. Correctly unwraps exceptions not caused by the reflection magic. * * @param target * @param method * @param parameters * @return * @throws Throwable */ private Object executeMethodOn(Object target, Method method, Object[] parameters) throws Throwable { try { return method.invoke(target, parameters); } catch (Exception e) { ClassUtils.unwrapReflectionException(e); } throw new IllegalStateException("Should not occur!"); }
/** * Asserts the given {@link Method}'s return type to be one of the given types. Will unwrap known wrapper types before * the assignment check (see {@link QueryExecutionConverters}). * * @param method must not be {@literal null}. * @param types must not be {@literal null} or empty. */ public static void assertReturnTypeAssignable(Method method, Class<?>... types) { Assert.notNull(method, "Method must not be null!"); Assert.notEmpty(types, "Types must not be null or empty!"); TypeInformation<?> returnType = getEffectivelyReturnedTypeFrom(method); Arrays.stream(types)// .filter(it -> it.isAssignableFrom(returnType.getType()))// .findAny().orElseThrow(() -> new IllegalStateException( "Method has to have one of the following return types! " + Arrays.toString(types))); }
@Override public boolean hasCustomMethod() { Class<?> repositoryInterface = getRepositoryInterface(); // No detection required if no typing interface was configured if (isGenericRepositoryInterface(repositoryInterface)) { return false; } for (Method method : repositoryInterface.getMethods()) { if (isCustomMethod(method) && !isBaseClassMethod(method)) { return true; } } return false; }
@Nullable @Override public Object invoke(@SuppressWarnings("null") MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); Object[] arguments = invocation.getArguments(); try { return composition.invoke(method, arguments); } catch (Exception e) { ClassUtils.unwrapReflectionException(e); } throw new IllegalStateException("Should not occur!"); } }
@Override public boolean hasCustomMethod() { Class<?> repositoryInterface = getRepositoryInterface(); // No detection required if no typing interface was configured if (isGenericRepositoryInterface(repositoryInterface)) { return false; } for (Method method : repositoryInterface.getMethods()) { if (isCustomMethod(method) && !isBaseClassMethod(method)) { return true; } } return false; }
if (hasParameterOfType(method, Pageable.class)) { if (hasParameterOfType(method, Sort.class)) { throw new IllegalStateException(String.format("Method must not have Pageable *and* Sort parameter. " + "Use sorting capabilities on Pageble instead! Offending method: %s", method.toString()));
@Override public boolean hasCustomMethod() { Class<?> repositoryInterface = getRepositoryInterface(); // No detection required if no typing interface was configured if (isGenericRepositoryInterface(repositoryInterface)) { return false; } for (Method method : repositoryInterface.getMethods()) { if (isCustomMethod(method) && !isBaseClassMethod(method)) { return true; } } return false; }
if (hasParameterOfType(method, Pageable.class)) { if (hasParameterOfType(method, Sort.class)) { throw new IllegalStateException(String.format("Method must not have Pageable *and* Sort parameter. " + "Use sorting capabilities on Pageble instead! Offending method: %s", method.toString()));
@Override public boolean hasCustomMethod() { Class<?> repositoryInterface = getRepositoryInterface(); // No detection required if no typing interface was configured if (isGenericRepositoryInterface(repositoryInterface)) { return false; } for (Method method : repositoryInterface.getMethods()) { if (isCustomMethod(method) && !isBaseClassMethod(method)) { return true; } } return false; }
if (hasParameterOfType(method, Pageable.class)) { if (hasParameterOfType(method, Sort.class)) { throw new IllegalStateException(String.format("Method must not have Pageable *and* Sort parameter. " + "Use sorting capabilities on Pageble instead! Offending method: %s", method.toString()));
@Override public boolean hasCustomMethod() { Class<?> repositoryInterface = getRepositoryInterface(); // No detection required if no typing interface was configured if (isGenericRepositoryInterface(repositoryInterface)) { return false; } for (Method method : repositoryInterface.getMethods()) { if (isCustomMethod(method) && !isBaseClassMethod(method)) { return true; } } return false; }
if (hasParameterOfType(method, Pageable.class)) { if (hasParameterOfType(method, Sort.class)) { throw new IllegalStateException(String.format("Method must not have Pageable *and* Sort parameter. " + "Use sorting capabilities on Pageble instead! Offending method: %s", method.toString()));
@Override public boolean hasCustomMethod() { Class<?> repositoryInterface = getRepositoryInterface(); // No detection required if no typing interface was configured if (isGenericRepositoryInterface(repositoryInterface)) { return false; } for (Method method : repositoryInterface.getMethods()) { if (isCustomMethod(method) && !isBaseClassMethod(method)) { return true; } } return false; }
@Override protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { boolean isNonRepositoryInterface = !ClassUtils.isGenericRepositoryInterface(beanDefinition.getBeanClassName()); boolean isTopLevelType = !beanDefinition.getMetadata().hasEnclosingClass(); return isNonRepositoryInterface && isTopLevelType; }
@Override protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { boolean isNonRepositoryInterface = !ClassUtils.isGenericRepositoryInterface(beanDefinition.getBeanClassName()); boolean isTopLevelType = !beanDefinition.getMetadata().hasEnclosingClass(); boolean isConsiderNestedRepositories = isConsiderNestedRepositoryInterfaces(); return isNonRepositoryInterface && (isTopLevelType || isConsiderNestedRepositories); }