Browse Source
Associate Repository Bean Definition with RepositoryConfiguration and RepositoryConfigurationExtension attributes to capture configuration details such as the module name or the configuration source. Introduce RepositoryFragmentsContributor to provide an abstraction for structural fragment implementation allowing to describe the implementation type instead of requiring the implementation object. Obtain repository fragments from a RepositoryFragmentsContributor (either the configured one or one from a RepositoryFactoryBean). Closes: #3279 Original Pull Request: #3282pull/3304/head
36 changed files with 913 additions and 356 deletions
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
/* |
||||
* Copyright 2025 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.data.repository.core.support; |
||||
|
||||
import org.springframework.data.repository.core.RepositoryMetadata; |
||||
import org.springframework.data.repository.core.support.RepositoryComposition.RepositoryFragments; |
||||
|
||||
/** |
||||
* Strategy interface support allowing to contribute a {@link RepositoryFragments} based on {@link RepositoryMetadata}. |
||||
* <p> |
||||
* Fragments contributors enhance repository functionality based on a repository declaration and activate additional |
||||
* fragments if a repository defines them, such as extending a built-in fragment interface (e.g. |
||||
* {@code QuerydslPredicateExecutor}, {@code QueryByExampleExecutor}). |
||||
* <p> |
||||
* This interface is a base-interface serving as a contract for repository fragment introspection. The actual |
||||
* implementation and methods to contribute fragments to be used within the repository instance are store-specific and |
||||
* require typically access to infrastructure such as a database connection hence those methods must be defined within |
||||
* the particular store module. |
||||
* |
||||
* @author Mark Paluch |
||||
* @since 4.0 |
||||
*/ |
||||
public interface RepositoryFragmentsContributor { |
||||
|
||||
/** |
||||
* Empty {@code RepositoryFragmentsContributor} that does not contribute any fragments. |
||||
* |
||||
* @return empty {@code RepositoryFragmentsContributor} that does not contribute any fragments. |
||||
*/ |
||||
public static RepositoryFragmentsContributor empty() { |
||||
return metadata -> RepositoryFragments.empty(); |
||||
} |
||||
|
||||
/** |
||||
* Describe fragments that are contributed by {@link RepositoryMetadata}. Fragment description reports typically |
||||
* structural fragments that are not suitable for invocation but can be used to introspect the repository structure. |
||||
* |
||||
* @param metadata the repository metadata describing the repository interface. |
||||
* @return fragments to be (structurally) contributed to the repository. |
||||
*/ |
||||
RepositoryFragments describe(RepositoryMetadata metadata); |
||||
|
||||
} |
||||
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
/* |
||||
* Copyright 2022-2025 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.data.repository.config; |
||||
|
||||
import java.lang.annotation.Annotation; |
||||
|
||||
import org.springframework.core.io.DefaultResourceLoader; |
||||
|
||||
/** |
||||
* @author Mark Paluch |
||||
*/ |
||||
class DummyRegistrarWithContributor extends RepositoryBeanDefinitionRegistrarSupport { |
||||
|
||||
DummyRegistrarWithContributor() { |
||||
setResourceLoader(new DefaultResourceLoader()); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<? extends Annotation> getAnnotation() { |
||||
return EnableRepositoriesWithContributor.class; |
||||
} |
||||
|
||||
@Override |
||||
protected RepositoryConfigurationExtension getExtension() { |
||||
return new DummyConfigurationExtension(); |
||||
} |
||||
} |
||||
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
/* |
||||
* Copyright 2012-2025 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.data.repository.config; |
||||
|
||||
import java.lang.annotation.Inherited; |
||||
import java.lang.annotation.Retention; |
||||
import java.lang.annotation.RetentionPolicy; |
||||
|
||||
import org.springframework.beans.factory.support.BeanNameGenerator; |
||||
import org.springframework.context.annotation.ComponentScan.Filter; |
||||
import org.springframework.context.annotation.Import; |
||||
import org.springframework.data.repository.PagingAndSortingRepository; |
||||
import org.springframework.data.repository.core.support.DummyRepositoryFactoryBean; |
||||
import org.springframework.data.repository.core.support.RepositoryFragmentsContributor; |
||||
|
||||
@Retention(RetentionPolicy.RUNTIME) |
||||
@Import(DummyRegistrarWithContributor.class) |
||||
@Inherited |
||||
public @interface EnableRepositoriesWithContributor { |
||||
|
||||
String[] value() default {}; |
||||
|
||||
String[] basePackages() default {}; |
||||
|
||||
Class<?>[] basePackageClasses() default {}; |
||||
|
||||
Filter[] includeFilters() default {}; |
||||
|
||||
Filter[] excludeFilters() default {}; |
||||
|
||||
Class<?> repositoryFactoryBeanClass() default DummyRepositoryFactoryBean.class; |
||||
|
||||
Class<? extends RepositoryFragmentsContributor> fragmentsContributor() default SampleRepositoryFragmentsContributor.class; |
||||
|
||||
Class<?> repositoryBaseClass() default PagingAndSortingRepository.class; |
||||
|
||||
Class<? extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class; |
||||
|
||||
String namedQueriesLocation() default ""; |
||||
|
||||
String repositoryImplementationPostfix() default "Impl"; |
||||
|
||||
boolean considerNestedRepositories() default false; |
||||
|
||||
boolean limitImplementationBasePackages() default true; |
||||
|
||||
BootstrapMode bootstrapMode() default BootstrapMode.DEFAULT; |
||||
} |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
/* |
||||
* Copyright 2025 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.data.repository.config; |
||||
|
||||
import org.springframework.data.repository.core.RepositoryMetadata; |
||||
import org.springframework.data.repository.core.support.RepositoryComposition; |
||||
import org.springframework.data.repository.core.support.RepositoryFragment; |
||||
import org.springframework.data.repository.core.support.RepositoryFragmentsContributor; |
||||
|
||||
/** |
||||
* @author Mark Paluch |
||||
*/ |
||||
public class SampleRepositoryFragmentsContributor implements RepositoryFragmentsContributor { |
||||
|
||||
@Override |
||||
public RepositoryComposition.RepositoryFragments describe(RepositoryMetadata metadata) { |
||||
return RepositoryComposition.RepositoryFragments |
||||
.of(RepositoryFragment.structural(SampleRepositoryFragmentsContributor.class)); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue