Refine customization of EntityInformation.

We now provide a getEntityInformation(RepositoryMetadata) customization hook for EntityInformation creation as several modules require access to RepositoryMetadata details (such as the Id type).

Closes #3288
This commit is contained in:
Mark Paluch
2025-05-13 12:19:28 +02:00
parent 732e1c5516
commit 368fe71e48
5 changed files with 20 additions and 8 deletions

View File

@@ -261,7 +261,7 @@ public abstract class RepositoryFactoryBeanSupport<T extends Repository<S, ID>,
@SuppressWarnings("unchecked")
public EntityInformation<S, ID> getEntityInformation() {
return (EntityInformation<S, ID>) getRequiredFactory()
.getEntityInformation(getRequiredRepositoryMetadata().getDomainType());
.getEntityInformation(getRequiredRepositoryMetadata());
}
@Override

View File

@@ -534,8 +534,23 @@ public abstract class RepositoryFactorySupport
* @param <ID> the id type
* @param domainClass
* @return
* @deprecated since 4.0, use {@link #getEntityInformation(RepositoryMetadata)} instead.
*/
public abstract <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass);
@Deprecated(since = "4.0")
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
throw new UnsupportedOperationException("getEntityInformation is not implemented");
}
/**
* Returns the {@link EntityInformation} for the given {@link RepositoryMetadata}.
*
* @param metadata must not be {@literal null}.
* @return the {@link EntityInformation} to be used for {@link RepositoryMetadata}.
* @since 4.0
*/
public EntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
return getEntityInformation(metadata.getDomainType());
}
/**
* Create a repository instance as backing for the query proxy.

View File

@@ -54,8 +54,7 @@ public class DummyReactiveRepositoryFactory extends ReactiveRepositoryFactorySup
}
@Override
@SuppressWarnings("unchecked")
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
public EntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
return mock(EntityInformation.class);
}

View File

@@ -77,8 +77,7 @@ public class DummyRepositoryFactory extends RepositoryFactorySupport {
}
@Override
@SuppressWarnings("unchecked")
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
public EntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
return mock(EntityInformation.class);
}

View File

@@ -77,8 +77,7 @@ public class ReactiveDummyRepositoryFactory extends ReactiveRepositoryFactorySup
}
@Override
@SuppressWarnings("unchecked")
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
public EntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
return mock(EntityInformation.class);
}