Search in sources :

Example 1 with RepositoryFragments

use of org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments in project spring-data-mongodb by spring-projects.

the class MongoRepositoryFactory method getRepositoryFragments.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getRepositoryFragments(org.springframework.data.repository.core.RepositoryMetadata)
	 */
@Override
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) {
    RepositoryFragments fragments = RepositoryFragments.empty();
    boolean isQueryDslRepository = QUERY_DSL_PRESENT && QuerydslPredicateExecutor.class.isAssignableFrom(metadata.getRepositoryInterface());
    if (isQueryDslRepository) {
        if (metadata.isReactiveRepository()) {
            throw new InvalidDataAccessApiUsageException("Cannot combine Querydsl and reactive repository support in a single interface");
        }
        MongoEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType(), metadata);
        fragments = fragments.append(RepositoryFragment.implemented(getTargetRepositoryViaReflection(QuerydslMongoPredicateExecutor.class, entityInformation, operations)));
    }
    return fragments;
}
Also used : RepositoryFragments(org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments) Serializable(java.io.Serializable) QuerydslPredicateExecutor(org.springframework.data.querydsl.QuerydslPredicateExecutor) InvalidDataAccessApiUsageException(org.springframework.dao.InvalidDataAccessApiUsageException)

Example 2 with RepositoryFragments

use of org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments in project spring-data-commons by spring-projects.

the class RepositoryFactoryBeanSupport method afterPropertiesSet.

/*
	 * (non-Javadoc)
	 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
	 */
public void afterPropertiesSet() {
    this.factory = createRepositoryFactory();
    this.factory.setQueryLookupStrategyKey(queryLookupStrategyKey);
    this.factory.setNamedQueries(namedQueries);
    this.factory.setEvaluationContextProvider(evaluationContextProvider);
    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);
    this.repository = Lazy.of(() -> this.factory.getRepository(repositoryInterface, repositoryFragmentsToUse));
    if (!lazyInit) {
        this.repository.get();
    }
}
Also used : RepositoryFragments(org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments)

Example 3 with RepositoryFragments

use of org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments in project spring-data-commons by spring-projects.

the class CdiRepositoryBean method getRepositoryFragments.

private RepositoryFragments getRepositoryFragments(Class<T> repositoryType, CdiRepositoryConfiguration cdiRepositoryConfiguration) {
    Optional<Bean<?>> customImplementationBean = getCustomImplementationBean(repositoryType, cdiRepositoryConfiguration);
    Optional<Object> customImplementation = customImplementationBean.map(this::getDependencyInstance);
    List<RepositoryFragment<?>> repositoryFragments = findRepositoryFragments(repositoryType, cdiRepositoryConfiguration);
    RepositoryFragments customImplementationFragment = // 
    customImplementation.map(// 
    RepositoryFragments::just).orElseGet(RepositoryFragments::empty);
    return // 
    RepositoryFragments.from(repositoryFragments).append(customImplementationFragment);
}
Also used : RepositoryFragments(org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments) RepositoryFragment(org.springframework.data.repository.core.support.RepositoryFragment) Bean(javax.enterprise.inject.spi.Bean)

Example 4 with RepositoryFragments

use of org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments in project spring-data-mongodb by spring-projects.

the class ReactiveMongoRepositoryFactory method getRepositoryFragments.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getRepositoryFragments(org.springframework.data.repository.core.RepositoryMetadata)
	 */
@Override
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) {
    RepositoryFragments fragments = RepositoryFragments.empty();
    boolean isQueryDslRepository = QUERY_DSL_PRESENT && ReactiveQuerydslPredicateExecutor.class.isAssignableFrom(metadata.getRepositoryInterface());
    if (isQueryDslRepository) {
        MongoEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType(), metadata);
        fragments = fragments.append(RepositoryFragment.implemented(getTargetRepositoryViaReflection(ReactiveQuerydslMongoPredicateExecutor.class, entityInformation, operations)));
    }
    return fragments;
}
Also used : RepositoryFragments(org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments) ReactiveQuerydslPredicateExecutor(org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor) Serializable(java.io.Serializable)

Example 5 with RepositoryFragments

use of org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments in project spring-data-commons by spring-projects.

the class RepositoryFactorySupport method getRepositoryComposition.

/**
 * Returns the {@link RepositoryComposition} for the given {@link RepositoryMetadata} and extra
 * {@link RepositoryFragments}.
 *
 * @param metadata must not be {@literal null}.
 * @param fragments must not be {@literal null}.
 * @return will never be {@literal null}.
 */
private RepositoryComposition getRepositoryComposition(RepositoryMetadata metadata, RepositoryFragments fragments) {
    Assert.notNull(metadata, "RepositoryMetadata must not be null!");
    Assert.notNull(fragments, "RepositoryFragments must not be null!");
    RepositoryComposition composition = getRepositoryComposition(metadata);
    RepositoryFragments repositoryAspects = getRepositoryFragments(metadata);
    return composition.append(fragments).append(repositoryAspects);
}
Also used : RepositoryFragments(org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments)

Aggregations

RepositoryFragments (org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments)6 Serializable (java.io.Serializable)2 Bean (javax.enterprise.inject.spi.Bean)1 InvalidDataAccessApiUsageException (org.springframework.dao.InvalidDataAccessApiUsageException)1 QuerydslPredicateExecutor (org.springframework.data.querydsl.QuerydslPredicateExecutor)1 ReactiveQuerydslPredicateExecutor (org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor)1 RepositoryFactorySupport (org.springframework.data.repository.core.support.RepositoryFactorySupport)1 RepositoryFragment (org.springframework.data.repository.core.support.RepositoryFragment)1