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.
This commit is contained in:
Oliver Drotbohm
2022-06-20 17:05:54 +02:00
parent 09558d77d8
commit 75387bb8ae
2 changed files with 19 additions and 1 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.data.repository.config;
import java.util.Collection;
import java.util.Locale;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -31,6 +32,19 @@ import org.springframework.core.io.ResourceLoader;
*/
public interface RepositoryConfigurationExtension {
/**
* A {@link String} uniquely identifying the module within all Spring Data modules. Must not contain any spaces.
*
* @return will never be {@literal null}.
* @since 3.0
*/
default String getModuleIdentifier() {
return getModuleName()
.toLowerCase(Locale.ENGLISH)
.replace(' ', '-');
}
/**
* Returns the descriptive name of the module.
*

View File

@@ -103,7 +103,7 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit
}
public String getDefaultNamedQueryLocation() {
return String.format("classpath*:META-INF/%s-named-queries.properties", getModulePrefix());
return String.format("classpath*:META-INF/%s-named-queries.properties", getModuleIdentifier());
}
public void registerBeansForRoot(BeanDefinitionRegistry registry,
@@ -113,7 +113,11 @@ public abstract class RepositoryConfigurationExtensionSupport implements Reposit
* Returns the prefix of the module to be used to create the default location for Spring Data named queries.
*
* @return must not be {@literal null}.
* @deprecated since 3.0, refer to {@link #getModuleIdentifier()} instead and implement either
* {@link #getModuleName()} directly or both methods if the default translation from name to identifier as
* defined in {@link RepositoryConfigurationExtension#getModuleIdentifier()} doesn't suit you.
*/
@Deprecated
protected abstract String getModulePrefix();
public void postProcess(BeanDefinitionBuilder builder, RepositoryConfigurationSource source) {}