/** * Returns a repository instance for the given interface. * * @param <T> * @param repositoryInterface * @return */ public <T> T getRepository(Class<T> repositoryInterface) { return getRepository(repositoryInterface, null); }
public void afterPropertiesSet() { this.factory = createRepositoryFactory(); this.factory.setQueryLookupStrategyKey(queryLookupStrategyKey); this.factory.setNamedQueries(namedQueries); this.factory.setEvaluationContextProvider( evaluationContextProvider.orElseGet(() -> QueryMethodEvaluationContextProvider.DEFAULT)); this.factory.setBeanClassLoader(classLoader); this.factory.setBeanFactory(beanFactory); if (publisher != null) { this.factory.addRepositoryProxyPostProcessor(new EventPublishingRepositoryProxyPostProcessor(publisher)); } repositoryBaseClass.ifPresent(this.factory::setRepositoryBaseClass); RepositoryFragments customImplementationFragment = customImplementation // .map(RepositoryFragments::just) // .orElseGet(RepositoryFragments::empty); RepositoryFragments repositoryFragmentsToUse = this.repositoryFragments // .orElseGet(RepositoryFragments::empty) // .append(customImplementationFragment); this.repositoryMetadata = this.factory.getRepositoryMetadata(repositoryInterface); // Make sure the aggregate root type is present in the MappingContext (e.g. for auditing) this.mappingContext.ifPresent(it -> it.getPersistentEntity(repositoryMetadata.getDomainType())); this.repository = Lazy.of(() -> this.factory.getRepository(repositoryInterface, repositoryFragmentsToUse)); if (!lazyInit) { this.repository.get(); } }
/** * Creates the actual repository instance. * * @param repositoryType will never be {@literal null}. * @param repositoryFragments will never be {@literal null}. * @return */ protected static <T> T create(RepositoryFactorySupport repositoryFactory, Class<T> repositoryType, RepositoryFragments repositoryFragments) { return repositoryFactory.getRepository(repositoryType, repositoryFragments); }
public T getObject() { return factory.getRepository(repositoryInterface, customImplementation); }
/** * Returns the previously initialized repository proxy or creates and returns the proxy if previously uninitialized. * * @return */ private T initAndReturn() { Assert.notNull(repositoryInterface, "Repository interface must not be null on initialization!"); if (this.repository == null) { this.repository = this.factory.getRepository(repositoryInterface, customImplementation); } return this.repository; }
public static void main(String[] args) { ApplicationContext context = new AnnotationConfigApplicationContext( CouchBaseBeansConfiguration.class); CouchbaseTemplate template = context.getBean("couchbaseTemplate", CouchbaseTemplate.class); RepositoryFactorySupport factory = new CouchbaseRepositoryFactory( template); CBsampleRepository repository = factory.getRepository(CBsampleRepository.class,new CBsampleRepositoryImpl()); CBsampleRepository repository = factory.getRepository(CBsampleRepository.class,custom); repository.addIndex(); }
/** * Returns a repository instance for the given interface. * * @param repositoryInterface must not be {@literal null}. * @return */ public <T> T getRepository(Class<T> repositoryInterface) { return getRepository(repositoryInterface, RepositoryFragments.empty()); }
/** * Returns a repository instance for the given interface backed by an instance providing implementation logic for * custom logic. * * @param repositoryInterface must not be {@literal null}. * @param customImplementation must not be {@literal null}. * @return * @deprecated since 2.0. Use {@link RepositoryFragments} with {@link #getRepository(Class, RepositoryFragments)} to * compose repositories backed by custom implementations. */ @Deprecated public <T> T getRepository(Class<T> repositoryInterface, Object customImplementation) { return getRepository(repositoryInterface, RepositoryFragments.just(customImplementation)); }
RepositoryFactorySupport factory = applicationContext.getBean(RepositoryCreator.class).getRepositoryFactorySupport(); for (Field f : toInitializeFields) { Object bean = factory.getRepository(f.getType()); f.set(currentObj, bean); f.setAccessible(false);