Skip to content

Commit 75387bb

Browse files
committed
Add RepositoryConfiurationExtension.getModuleIdentifier().
We're now unifying the lookup of a unique identifier for a Spring Data module in the RepositoryConfigurationExtension interface. Previous users of getModulePrefix() in subclasses of RCE should rather call getModuleIdentifier(). Implementations of RCE that previously implemented getModulePrefix() directly should rather switch to implementing getModuleName() and additionally getModuleIdentifier() in case the default implementations derivation of the identifier from the name doesn't produce the results intended. RepositoryConfigurationExtensionSupport.getDefaultNamedQueryLocation() was changed to rather use the identifier to calculate the name of the named query location instead of the prefix. Fixes #2644.
1 parent 09558d7 commit 75387bb

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtension.java

+14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.data.repository.config;
1717

1818
import java.util.Collection;
19+
import java.util.Locale;
1920

2021
import org.springframework.beans.factory.config.BeanDefinition;
2122
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -31,6 +32,19 @@
3132
*/
3233
public interface RepositoryConfigurationExtension {
3334

35+
/**
36+
* A {@link String} uniquely identifying the module within all Spring Data modules. Must not contain any spaces.
37+
*
38+
* @return will never be {@literal null}.
39+
* @since 3.0
40+
*/
41+
default String getModuleIdentifier() {
42+
43+
return getModuleName()
44+
.toLowerCase(Locale.ENGLISH)
45+
.replace(' ', '-');
46+
}
47+
3448
/**
3549
* Returns the descriptive name of the module.
3650
*

src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupport.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public <T extends RepositoryConfigurationSource> Collection<RepositoryConfigurat
103103
}
104104

105105
public String getDefaultNamedQueryLocation() {
106-
return String.format("classpath*:META-INF/%s-named-queries.properties", getModulePrefix());
106+
return String.format("classpath*:META-INF/%s-named-queries.properties", getModuleIdentifier());
107107
}
108108

109109
public void registerBeansForRoot(BeanDefinitionRegistry registry,
@@ -113,7 +113,11 @@ public void registerBeansForRoot(BeanDefinitionRegistry registry,
113113
* Returns the prefix of the module to be used to create the default location for Spring Data named queries.
114114
*
115115
* @return must not be {@literal null}.
116+
* @deprecated since 3.0, refer to {@link #getModuleIdentifier()} instead and implement either
117+
* {@link #getModuleName()} directly or both methods if the default translation from name to identifier as
118+
* defined in {@link RepositoryConfigurationExtension#getModuleIdentifier()} doesn't suit you.
116119
*/
120+
@Deprecated
117121
protected abstract String getModulePrefix();
118122

119123
public void postProcess(BeanDefinitionBuilder builder, RepositoryConfigurationSource source) {}

0 commit comments

Comments
 (0)