Skip to content

Commit 0de9b3d

Browse files
committed
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
1 parent ff04613 commit 0de9b3d

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

src/main/java/org/springframework/data/repository/core/support/RepositoryFactoryBeanSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
261261
@SuppressWarnings("unchecked")
262262
public EntityInformation<S, ID> getEntityInformation() {
263263
return (EntityInformation<S, ID>) getRequiredFactory()
264-
.getEntityInformation(getRequiredRepositoryMetadata().getDomainType());
264+
.getEntityInformation(getRequiredRepositoryMetadata());
265265
}
266266

267267
@Override

src/main/java/org/springframework/data/repository/core/support/RepositoryFactorySupport.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,23 @@ protected ProjectionFactory getProjectionFactory() {
534534
* @param <ID> the id type
535535
* @param domainClass
536536
* @return
537+
* @deprecated since 4.0, use {@link #getEntityInformation(RepositoryMetadata)} instead.
537538
*/
538-
public abstract <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass);
539+
@Deprecated(since = "4.0")
540+
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
541+
throw new UnsupportedOperationException("getEntityInformation is not implemented");
542+
}
543+
544+
/**
545+
* Returns the {@link EntityInformation} for the given {@link RepositoryMetadata}.
546+
*
547+
* @param metadata must not be {@literal null}.
548+
* @return the {@link EntityInformation} to be used for {@link RepositoryMetadata}.
549+
* @since 4.0
550+
*/
551+
public EntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
552+
return getEntityInformation(metadata.getDomainType());
553+
}
539554

540555
/**
541556
* Create a repository instance as backing for the query proxy.

src/test/java/org/springframework/data/repository/core/support/DummyReactiveRepositoryFactory.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public DummyReactiveRepositoryFactory(Object repository) {
5454
}
5555

5656
@Override
57-
@SuppressWarnings("unchecked")
58-
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
57+
public EntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
5958
return mock(EntityInformation.class);
6059
}
6160

src/test/java/org/springframework/data/repository/core/support/DummyRepositoryFactory.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ public DummyRepositoryFactory(Object repository) {
7777
}
7878

7979
@Override
80-
@SuppressWarnings("unchecked")
81-
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
80+
public EntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
8281
return mock(EntityInformation.class);
8382
}
8483

src/test/java/org/springframework/data/repository/core/support/ReactiveDummyRepositoryFactory.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ public ReactiveDummyRepositoryFactory(Object repository) {
7777
}
7878

7979
@Override
80-
@SuppressWarnings("unchecked")
81-
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
80+
public EntityInformation<?, ?> getEntityInformation(RepositoryMetadata metadata) {
8281
return mock(EntityInformation.class);
8382
}
8483

0 commit comments

Comments
 (0)