Browse Source

Explore extension point via spring.factories for 3rd party library authors that wish to customize repository factories.

issue/3353
Mark Paluch 5 months ago
parent
commit
da0c8cb76a
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 18
      src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java

18
src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java

@ -34,6 +34,7 @@ import org.springframework.context.ApplicationEventPublisherAware; @@ -34,6 +34,7 @@ import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.aot.AbstractAotProcessor;
import org.springframework.core.env.Environment;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.projection.ProjectionFactory;
@ -260,8 +261,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>, @@ -260,8 +261,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
@Override
@SuppressWarnings("unchecked")
public EntityInformation<S, ID> getEntityInformation() {
return (EntityInformation<S, ID>) getRequiredFactory()
.getEntityInformation(getRequiredRepositoryMetadata());
return (EntityInformation<S, ID>) getRequiredFactory().getEntityInformation(getRequiredRepositoryMetadata());
}
@Override
@ -341,6 +341,14 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>, @@ -341,6 +341,14 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
this.factory.setRepositoryBaseClass(repositoryBaseClass);
}
SpringFactoriesLoader.loadFactories(RepositoryFactoryCustomizer.class, classLoader).forEach(customizer -> {
if (!(customizer instanceof ConditionalRepositoryFactoryCustomizer conditional)
|| conditional.canCustomize(this.factory, this.repositoryInterface)) {
customizer.customize(this.factory);
}
});
if (beanFactory != null) {
beanFactory.getBeanProvider(TypedRepositoryFactoryCustomizer.class).orderedStream().forEachOrdered(customizer -> {
@ -401,8 +409,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>, @@ -401,8 +409,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
RepositoryFragments fragments = RepositoryFragments.empty();
for (RepositoryFragmentsFunction function : functions) {
fragments = fragments.append(function.getRepositoryFragments(this.beanFactory,
creationContext));
fragments = fragments.append(function.getRepositoryFragments(this.beanFactory, creationContext));
}
return fragments;
@ -426,8 +433,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>, @@ -426,8 +433,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
* @param context the creation context.
* @return the repository fragments to use.
*/
RepositoryFragments getRepositoryFragments(@Nullable BeanFactory beanFactory,
FragmentCreationContext context);
RepositoryFragments getRepositoryFragments(@Nullable BeanFactory beanFactory, FragmentCreationContext context);
/**
* Factory method to create {@link RepositoryFragmentsFunction} for a resolved {@link RepositoryFragments} object.

Loading…
Cancel
Save