/** * Validates the given repository interface as well as the given custom implementation. * * @param repositoryInformation * @param customImplementation */ private void validate(RepositoryInformation repositoryInformation, Object customImplementation) { if (null == customImplementation && repositoryInformation.hasCustomMethod()) { throw new IllegalArgumentException(String.format( "You have custom methods in %s but not provided a custom implementation!", repositoryInformation.getRepositoryInterface())); } validate(repositoryInformation); }
/** * Validates the given repository interface as well as the given custom implementation. * * @param repositoryInformation * @param composition */ private void validate(RepositoryInformation repositoryInformation, RepositoryComposition composition) { if (repositoryInformation.hasCustomMethod()) { if (composition.isEmpty()) { throw new IllegalArgumentException( String.format("You have custom methods in %s but not provided a custom implementation!", repositoryInformation.getRepositoryInterface())); } composition.validateImplementation(); } validate(repositoryInformation); }
/** * Returns a repository instance for the given interface backed by an instance providing implementation logic for * custom logic. * * @param <T> * @param repositoryInterface * @param customImplementation * @return */ @SuppressWarnings({ "unchecked" }) public <T> T getRepository(Class<T> repositoryInterface, Object customImplementation) { RepositoryMetadata metadata = getRepositoryMetadata(repositoryInterface); Class<?> customImplementationClass = null == customImplementation ? null : customImplementation.getClass(); RepositoryInformation information = getRepositoryInformation(metadata, customImplementationClass); validate(information, customImplementation); Object target = getTargetRepository(information); // Create proxy ProxyFactory result = new ProxyFactory(); result.setTarget(target); result.setInterfaces(new Class[] { repositoryInterface, Repository.class }); for (RepositoryProxyPostProcessor processor : postProcessors) { processor.postProcess(result); } result.addAdvice(new QueryExecutorMethodInterceptor(information, customImplementation, target)); return (T) result.getProxy(); }
RepositoryInformation information = getRepositoryInformation(metadata, composition); validate(information, composition);