From 368fe71e482a5e0511d4d7b1b343deae9f4f98ac Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 13 May 2025 12:19:28 +0200 Subject: [PATCH] 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 --- .../support/RepositoryFactoryBeanSupport.java | 2 +- .../core/support/RepositoryFactorySupport.java | 17 ++++++++++++++++- .../support/DummyReactiveRepositoryFactory.java | 3 +-- .../core/support/DummyRepositoryFactory.java | 3 +-- .../support/ReactiveDummyRepositoryFactory.java | 3 +-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java index 4ccaba6c5..b63d82ce4 100644 --- a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java +++ b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java @@ -261,7 +261,7 @@ public abstract class RepositoryFactoryBeanSupport, @SuppressWarnings("unchecked") public EntityInformation getEntityInformation() { return (EntityInformation) getRequiredFactory() - .getEntityInformation(getRequiredRepositoryMetadata().getDomainType()); + .getEntityInformation(getRequiredRepositoryMetadata()); } @Override diff --git a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java index 88b4f11d8..23446fe95 100644 --- a/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java +++ b/src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java @@ -534,8 +534,23 @@ public abstract class RepositoryFactorySupport * @param the id type * @param domainClass * @return + * @deprecated since 4.0, use {@link #getEntityInformation(RepositoryMetadata)} instead. */ - public abstract EntityInformation getEntityInformation(Class domainClass); + @Deprecated(since = "4.0") + public EntityInformation getEntityInformation(Class 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. diff --git a/src/test/java/org/springframework/data/repository/core/support/DummyReactiveRepositoryFactory.java b/src/test/java/org/springframework/data/repository/core/support/DummyReactiveRepositoryFactory.java index 459914446..c0beceb49 100644 --- a/src/test/java/org/springframework/data/repository/core/support/DummyReactiveRepositoryFactory.java +++ b/src/test/java/org/springframework/data/repository/core/support/DummyReactiveRepositoryFactory.java @@ -54,8 +54,7 @@ public class DummyReactiveRepositoryFactory extends ReactiveRepositoryFactorySup } @Override - @SuppressWarnings("unchecked") - public EntityInformation getEntityInformation(Class domainClass) { + public EntityInformation getEntityInformation(RepositoryMetadata metadata) { return mock(EntityInformation.class); } diff --git a/src/test/java/org/springframework/data/repository/core/support/DummyRepositoryFactory.java b/src/test/java/org/springframework/data/repository/core/support/DummyRepositoryFactory.java index f27e2aa76..dd7a51886 100644 --- a/src/test/java/org/springframework/data/repository/core/support/DummyRepositoryFactory.java +++ b/src/test/java/org/springframework/data/repository/core/support/DummyRepositoryFactory.java @@ -77,8 +77,7 @@ public class DummyRepositoryFactory extends RepositoryFactorySupport { } @Override - @SuppressWarnings("unchecked") - public EntityInformation getEntityInformation(Class domainClass) { + public EntityInformation getEntityInformation(RepositoryMetadata metadata) { return mock(EntityInformation.class); } diff --git a/src/test/java/org/springframework/data/repository/core/support/ReactiveDummyRepositoryFactory.java b/src/test/java/org/springframework/data/repository/core/support/ReactiveDummyRepositoryFactory.java index 02ca50c64..56d5773da 100644 --- a/src/test/java/org/springframework/data/repository/core/support/ReactiveDummyRepositoryFactory.java +++ b/src/test/java/org/springframework/data/repository/core/support/ReactiveDummyRepositoryFactory.java @@ -77,8 +77,7 @@ public class ReactiveDummyRepositoryFactory extends ReactiveRepositoryFactorySup } @Override - @SuppressWarnings("unchecked") - public EntityInformation getEntityInformation(Class domainClass) { + public EntityInformation getEntityInformation(RepositoryMetadata metadata) { return mock(EntityInformation.class); }