public boolean isQueryMethod(Method method) { return getQueryMethods().contains(method); }
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; }
public Method getTargetClassMethod(Method method) { if (methodCache.containsKey(method)) { return methodCache.get(method); } Method result = getTargetClassMethod(method, customImplementationClass); if (!result.equals(method)) { methodCache.put(method, result); return result; } result = getTargetClassMethod(method, repositoryBaseClass); methodCache.put(method, result); return result; }
/** * Checks whether the given method is a query method candidate. * * @param method * @return */ private boolean isQueryMethodCandidate(Method method) { return !method.isBridge() && !method.isDefault() // && !Modifier.isStatic(method.getModifiers()) // && (isQueryAnnotationPresentOn(method) || !isCustomMethod(method) && !isBaseClassMethod(method)); }
@Override public Streamable<Method> getQueryMethods() { Set<Method> result = new HashSet<>(); for (Method method : getRepositoryInterface().getMethods()) { method = ClassUtils.getMostSpecificMethod(method, getRepositoryInterface()); if (isQueryMethodCandidate(method)) { result.add(method); } } return Streamable.of(Collections.unmodifiableSet(result)); }
/** * Returns the {@link RepositoryInformation} for the given repository interface. * * @param repositoryInterface * @param customImplementationClass * @return */ protected RepositoryInformation getRepositoryInformation(RepositoryMetadata metadata, Class<?> customImplementationClass) { return new DefaultRepositoryInformation(metadata, getRepositoryBaseClass(metadata), customImplementationClass); }
/** * Checks whether the given parameter type matches the generic type of the given parameter. Thus when {@literal PK} is * declared, the method ensures that given method parameter is the primary key type declared in the given repository * interface e.g. * * @param name * @param parameterType * @return */ private boolean matchesGenericType(TypeVariable<?> variable, Class<?> parameterType) { Class<?> entityType = getDomainType(); Class<?> idClass = getIdType(); if (ID_TYPE_NAME.equals(variable.getName()) && parameterType.isAssignableFrom(idClass)) { return true; } Type boundType = variable.getBounds()[0]; String referenceName = boundType instanceof TypeVariable ? boundType.toString() : variable.toString(); if (DOMAIN_TYPE_NAME.equals(referenceName) && parameterType.isAssignableFrom(entityType)) { return true; } return false; } }
@Override public Method getTargetClassMethod(Method method) { if (methodCache.containsKey(method)) { return methodCache.get(method); } Method result = composition.findMethod(method).orElse(method); if (!result.equals(method)) { return cacheAndReturn(method, result); } return cacheAndReturn(method, baseComposition.findMethod(method).orElse(method)); }
/** * Returns the {@link RepositoryInformation} for the given repository interface. * * @param metadata * @param composition * @return */ private RepositoryInformation getRepositoryInformation(RepositoryMetadata metadata, RepositoryComposition composition) { RepositoryInformationCacheKey cacheKey = new RepositoryInformationCacheKey(metadata, composition); return repositoryInformationCache.computeIfAbsent(cacheKey, key -> { Class<?> baseClass = repositoryBaseClass.orElse(getRepositoryBaseClass(metadata)); return new DefaultRepositoryInformation(metadata, baseClass, composition); }); }
public Set<Method> getQueryMethods() { Set<Method> result = new HashSet<Method>(); for (Method method : getRepositoryInterface().getMethods()) { method = ClassUtils.getMostSpecificMethod(method, getRepositoryInterface()); if (!isCustomMethod(method) && !isBaseClassMethod(method)) { result.add(method); } } return Collections.unmodifiableSet(result); }
@Override public boolean isQueryMethod(Method method) { return getQueryMethods().stream().anyMatch(it -> it.equals(method)); }
/** * Returns whether the given method is considered to be a repository base class method. * * @param method * @return */ private boolean isTargetClassMethod(Method method, Class<?> targetType) { Assert.notNull(method); if (targetType == null) { return false; } if (method.getDeclaringClass().isAssignableFrom(targetType)) { return true; } return !method.equals(getTargetClassMethod(method, targetType)); }
@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; }