Skip to content

Commit 49368b2

Browse files
odrotbohmmp911de
authored andcommitted
DATAMONGO-1444 - Moved to new base class for reactive repository factories.
1 parent 960a259 commit 49368b2

File tree

1 file changed

+2
-55
lines changed

1 file changed

+2
-55
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/ReactiveMongoRepositoryFactory.java

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020

2121
import java.io.Serializable;
2222
import java.lang.reflect.Method;
23-
import java.util.Arrays;
2423

25-
import org.reactivestreams.Publisher;
26-
import org.springframework.dao.InvalidDataAccessApiUsageException;
2724
import org.springframework.data.mapping.context.MappingContext;
2825
import org.springframework.data.mapping.model.MappingException;
2926
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
@@ -38,16 +35,13 @@
3835
import org.springframework.data.repository.core.NamedQueries;
3936
import org.springframework.data.repository.core.RepositoryInformation;
4037
import org.springframework.data.repository.core.RepositoryMetadata;
41-
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
38+
import org.springframework.data.repository.core.support.ReactiveRepositoryFactorySupport;
4239
import org.springframework.data.repository.query.EvaluationContextProvider;
4340
import org.springframework.data.repository.query.QueryLookupStrategy;
4441
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
4542
import org.springframework.data.repository.query.RepositoryQuery;
46-
import org.springframework.data.repository.util.ReactiveWrapperConverters;
47-
import org.springframework.data.repository.util.ReactiveWrappers;
4843
import org.springframework.expression.spel.standard.SpelExpressionParser;
4944
import org.springframework.util.Assert;
50-
import org.springframework.util.ClassUtils;
5145

5246
/**
5347
* Factory to create {@link org.springframework.data.mongodb.repository.ReactiveMongoRepository} instances.
@@ -57,7 +51,7 @@
5751
* @author Oliver Gierke
5852
* @since 2.0
5953
*/
60-
public class ReactiveMongoRepositoryFactory extends RepositoryFactorySupport {
54+
public class ReactiveMongoRepositoryFactory extends ReactiveRepositoryFactorySupport {
6155

6256
private static final SpelExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
6357

@@ -115,53 +109,6 @@ public <T, ID extends Serializable> MongoEntityInformation<T, ID> getEntityInfor
115109
return getEntityInformation(domainClass, null);
116110
}
117111

118-
/*
119-
* (non-Javadoc)
120-
* @see org.springframework.data.repository.core.support.RepositoryFactorySupport#validate(org.springframework.data.repository.core.RepositoryMetadata)
121-
*/
122-
@Override
123-
protected void validate(RepositoryMetadata repositoryMetadata) {
124-
125-
if (!ReactiveWrappers.isAvailable()) {
126-
throw new InvalidDataAccessApiUsageException(
127-
String.format("Cannot implement repository %s without reactive library support.",
128-
repositoryMetadata.getRepositoryInterface().getName()));
129-
}
130-
131-
Arrays.stream(repositoryMetadata.getRepositoryInterface().getMethods())
132-
.forEach(ReactiveMongoRepositoryFactory::validate);
133-
}
134-
135-
/**
136-
* Reactive MongoDB support requires reactive wrapper support. If return type/parameters are reactive wrapper types,
137-
* then it's required to be able to convert these into Publisher.
138-
*
139-
* @param method the method to validate.
140-
*/
141-
private static void validate(Method method) {
142-
143-
if (ReactiveWrappers.supports(method.getReturnType())
144-
&& !ClassUtils.isAssignable(Publisher.class, method.getReturnType())) {
145-
146-
if (!ReactiveWrapperConverters.supports(method.getReturnType())) {
147-
148-
throw new InvalidDataAccessApiUsageException(
149-
String.format("No reactive type converter found for type %s used in %s, method %s.",
150-
method.getReturnType().getName(), method.getDeclaringClass().getName(), method));
151-
}
152-
}
153-
154-
Arrays.stream(method.getParameterTypes()) //
155-
.filter(ReactiveWrappers::supports) //
156-
.filter(parameterType -> !ClassUtils.isAssignable(Publisher.class, parameterType)) //
157-
.filter(parameterType -> !ReactiveWrapperConverters.supports(parameterType)) //
158-
.forEach(parameterType -> {
159-
throw new InvalidDataAccessApiUsageException(
160-
String.format("No reactive type converter found for type %s used in %s, method %s.",
161-
parameterType.getName(), method.getDeclaringClass().getName(), method));
162-
});
163-
}
164-
165112
@SuppressWarnings("unchecked")
166113
private <T, ID extends Serializable> MongoEntityInformation<T, ID> getEntityInformation(Class<T> domainClass,
167114
RepositoryInformation information) {

0 commit comments

Comments
 (0)