private static void assertReturnTypeAssignable(Method method, Set<Class<?>> types) { Assert.notNull(method, "Method must not be null!"); Assert.notEmpty(types, "Types must not be null or empty!"); TypeInformation<?> returnType = ClassTypeInformation.fromReturnTypeOf(method); returnType = QueryExecutionConverters.isSingleValue(returnType.getType()) // ? returnType.getRequiredComponentType() // : returnType; for (Class<?> type : types) { if (type.isAssignableFrom(returnType.getType())) { return; } } throw new IllegalStateException("Method has to have one of the following return types! " + types.toString()); } }
/** * Returns whether the finder will actually return a collection of entities or a single one. * * @return */ public boolean isCollectionQuery() { if (isPageQuery() || isSliceQuery()) { return false; } Class<?> returnType = method.getReturnType(); if (QueryExecutionConverters.supports(returnType) && !QueryExecutionConverters.isSingleValue(returnType)) { return true; } if (QueryExecutionConverters.supports(unwrappedReturnType)) { return !QueryExecutionConverters.isSingleValue(unwrappedReturnType); } return ClassTypeInformation.from(unwrappedReturnType).isCollectionLike(); }