|
18 | 18 | import java.io.Serializable;
|
19 | 19 | import java.lang.reflect.Method;
|
20 | 20 | import java.util.Arrays;
|
21 |
| -import java.util.List; |
22 | 21 |
|
| 22 | +import org.reactivestreams.Publisher; |
23 | 23 | import org.springframework.core.convert.ConversionService;
|
24 | 24 | import org.springframework.core.convert.support.DefaultConversionService;
|
25 |
| -import org.springframework.data.geo.GeoResult; |
| 25 | +import org.springframework.dao.InvalidDataAccessApiUsageException; |
26 | 26 | import org.springframework.data.mapping.context.MappingContext;
|
27 | 27 | import org.springframework.data.mapping.model.MappingException;
|
28 | 28 | import org.springframework.data.mongodb.core.ReactiveMongoOperations;
|
|
44 | 44 | import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
45 | 45 | import org.springframework.data.repository.query.RepositoryQuery;
|
46 | 46 | import org.springframework.data.repository.util.QueryExecutionConverters;
|
| 47 | +import org.springframework.data.repository.util.ReactiveWrapperConverters; |
| 48 | +import org.springframework.data.repository.util.ReactiveWrappers; |
47 | 49 | import org.springframework.expression.spel.standard.SpelExpressionParser;
|
48 | 50 | import org.springframework.util.Assert;
|
| 51 | +import org.springframework.util.ClassUtils; |
49 | 52 |
|
50 | 53 | /**
|
51 | 54 | * Factory to create {@link org.springframework.data.mongodb.repository.ReactiveMongoRepository} instances.
|
@@ -117,6 +120,53 @@ public <T, ID extends Serializable> MongoEntityInformation<T, ID> getEntityInfor
|
117 | 120 | return getEntityInformation(domainClass, null);
|
118 | 121 | }
|
119 | 122 |
|
| 123 | + /* |
| 124 | + * (non-Javadoc) |
| 125 | + * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#validate(org.springframework.data.repository.core.RepositoryMetadata) |
| 126 | + */ |
| 127 | + @Override |
| 128 | + protected void validate(RepositoryMetadata repositoryMetadata) { |
| 129 | + |
| 130 | + if (!ReactiveWrappers.isAvailable()) { |
| 131 | + throw new InvalidDataAccessApiUsageException( |
| 132 | + String.format("Cannot implement Repository %s without reactive library support.", |
| 133 | + repositoryMetadata.getRepositoryInterface().getName())); |
| 134 | + } |
| 135 | + |
| 136 | + Arrays.stream(repositoryMetadata.getRepositoryInterface().getMethods()) |
| 137 | + .forEach(ReactiveMongoRepositoryFactory::validate); |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Reactive MongoDB support requires reactive wrapper support. If return type/parameters are reactive wrapper types, |
| 142 | + * then it's required to be able to convert these into Publisher. |
| 143 | + * |
| 144 | + * @param method the method to validate. |
| 145 | + */ |
| 146 | + private static void validate(Method method) { |
| 147 | + |
| 148 | + if (ReactiveWrappers.supports(method.getReturnType()) |
| 149 | + && !ClassUtils.isAssignable(Publisher.class, method.getReturnType())) { |
| 150 | + |
| 151 | + if (!ReactiveWrapperConverters.supports(method.getReturnType())) { |
| 152 | + |
| 153 | + throw new InvalidDataAccessApiUsageException( |
| 154 | + String.format("No reactive type converter found for type %s used in %s, method %s.", |
| 155 | + method.getReturnType().getName(), method.getDeclaringClass().getName(), method)); |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + Arrays.stream(method.getParameterTypes()) // |
| 160 | + .filter(ReactiveWrappers::supports) // |
| 161 | + .filter(parameterType -> !ClassUtils.isAssignable(Publisher.class, parameterType)) // |
| 162 | + .filter(parameterType -> !ReactiveWrapperConverters.supports(parameterType)) // |
| 163 | + .forEach(parameterType -> { |
| 164 | + throw new InvalidDataAccessApiUsageException( |
| 165 | + String.format("No reactive type converter found for type %s used in %s, method %s.", |
| 166 | + parameterType.getName(), method.getDeclaringClass().getName(), method)); |
| 167 | + }); |
| 168 | + } |
| 169 | + |
120 | 170 | @SuppressWarnings("unchecked")
|
121 | 171 | private <T, ID extends Serializable> MongoEntityInformation<T, ID> getEntityInformation(Class<T> domainClass,
|
122 | 172 | RepositoryInformation information) {
|
|
0 commit comments