Skip to content

Commit 33750a6

Browse files
mp911deodrotbohm
authored andcommitted
DATACMNS-836 - Provide wrapper conversion, ReactiveWrappers and RxJava 2 type conversion.
1 parent adcf28a commit 33750a6

16 files changed

+1361
-531
lines changed

pom.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
<properties>
1919
<scala>2.11.7</scala>
20-
<reactor>2.5.0.M4</reactor>
2120
<xmlbeam>1.4.8</xmlbeam>
21+
<spring>5.0.0.BUILD-SNAPSHOT</spring>
2222
</properties>
2323

2424
<dependencies>
@@ -114,6 +114,20 @@
114114
<optional>true</optional>
115115
</dependency>
116116

117+
<dependency>
118+
<groupId>io.reactivex</groupId>
119+
<artifactId>rxjava-reactive-streams</artifactId>
120+
<version>${rxjava-reactive-streams}</version>
121+
<optional>true</optional>
122+
</dependency>
123+
124+
<dependency>
125+
<groupId>io.reactivex.rxjava2</groupId>
126+
<artifactId>rxjava</artifactId>
127+
<version>${rxjava2}</version>
128+
<optional>true</optional>
129+
</dependency>
130+
117131
<!-- Querydsl -->
118132

119133
<dependency>

src/main/java/org/springframework/data/repository/config/RepositoryConfigurationExtensionSupport.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* {@link #getModulePrefix()}). Stubs out the post-processing methods as they might not be needed by default.
4444
*
4545
* @author Oliver Gierke
46+
* @author Mark Paluch
4647
*/
4748
public abstract class RepositoryConfigurationExtensionSupport implements RepositoryConfigurationExtension {
4849

@@ -293,7 +294,7 @@ protected boolean isStrictRepositoryCandidate(Class<?> repositoryInterface) {
293294
* @param loader must not be {@literal null}.
294295
* @return the repository interface or {@literal null} if it can't be loaded.
295296
*/
296-
private Class<?> loadRepositoryInterface(RepositoryConfiguration<?> configuration, ResourceLoader loader) {
297+
protected Class<?> loadRepositoryInterface(RepositoryConfiguration<?> configuration, ResourceLoader loader) {
297298

298299
String repositoryInterface = configuration.getRepositoryInterface();
299300
ClassLoader classLoader = loader.getClassLoader();

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* converted for invocation of implementation methods.
3434
*
3535
* @author Mark Paluch
36+
* @since 2.0
3637
*/
3738
public class ReactiveRepositoryInformation extends DefaultRepositoryInformation {
3839

@@ -75,7 +76,7 @@ Method getTargetClassMethod(Method method, Class<?> baseClass) {
7576
boolean wantsWrappers = wantsMethodUsingReactiveWrapperParameters(method);
7677

7778
if (wantsWrappers) {
78-
Method candidate = getMethodCandidate(method, baseClass, new ExactWrapperMatch(method));
79+
Method candidate = getMethodCandidate(method, baseClass, new AssignableWrapperMatch(method));
7980

8081
if (candidate != null) {
8182
return candidate;
@@ -171,6 +172,11 @@ static boolean isNonunwrappingWrapper(Class<?> parameterType) {
171172
&& !QueryExecutionConverters.supportsUnwrapping(parameterType);
172173
}
173174

175+
/**
176+
* {@link BiPredicate} to check whether a method parameter is a {@link #isNonunwrappingWrapper(Class)} and can be
177+
* converted into a different wrapper. Usually {@link rx.Observable} to {@link org.reactivestreams.Publisher}
178+
* conversion.
179+
*/
174180
static class WrapperConversionMatch implements BiPredicate<Class<?>, Integer> {
175181

176182
final Method declaredMethod;
@@ -187,7 +193,6 @@ public WrapperConversionMatch(Method declaredMethod, ConversionService conversio
187193
@Override
188194
public boolean test(Class<?> candidateParameterType, Integer index) {
189195

190-
// TODO: should check for component type
191196
if (isNonunwrappingWrapper(candidateParameterType) && isNonunwrappingWrapper(declaredParameterTypes[index])) {
192197

193198
if (conversionService.canConvert(declaredParameterTypes[index], candidateParameterType)) {
@@ -197,15 +202,19 @@ public boolean test(Class<?> candidateParameterType, Integer index) {
197202

198203
return false;
199204
}
200-
201205
}
202206

203-
static class ExactWrapperMatch implements BiPredicate<Class<?>, Integer> {
207+
/**
208+
* {@link BiPredicate} to check parameter assignability between a {@link #isNonunwrappingWrapper(Class)} parameter and
209+
* a declared parameter. Usually {@link reactor.core.publisher.Flux} vs. {@link org.reactivestreams.Publisher}
210+
* conversion.
211+
*/
212+
static class AssignableWrapperMatch implements BiPredicate<Class<?>, Integer> {
204213

205214
final Method declaredMethod;
206215
final Class<?>[] declaredParameterTypes;
207216

208-
public ExactWrapperMatch(Method declaredMethod) {
217+
public AssignableWrapperMatch(Method declaredMethod) {
209218

210219
this.declaredMethod = declaredMethod;
211220
this.declaredParameterTypes = declaredMethod.getParameterTypes();
@@ -214,7 +223,6 @@ public ExactWrapperMatch(Method declaredMethod) {
214223
@Override
215224
public boolean test(Class<?> candidateParameterType, Integer index) {
216225

217-
// TODO: should check for component type
218226
if (isNonunwrappingWrapper(candidateParameterType) && isNonunwrappingWrapper(declaredParameterTypes[index])) {
219227

220228
if (declaredParameterTypes[index].isAssignableFrom(candidateParameterType)) {
@@ -224,9 +232,14 @@ public boolean test(Class<?> candidateParameterType, Integer index) {
224232

225233
return false;
226234
}
227-
228235
}
229236

237+
/**
238+
* {@link BiPredicate} to check parameter assignability between a parameters in which the declared parameter may be
239+
* wrapped but supports unwrapping. Usually types like {@link java.util.Optional} or {@link java.util.stream.Stream}.
240+
*
241+
* @see QueryExecutionConverters
242+
*/
230243
static class MatchParameterOrComponentType implements BiPredicate<Class<?>, Integer> {
231244

232245
final Method declaredMethod;
@@ -253,7 +266,5 @@ public boolean test(Class<?> candidateParameterType, Integer index) {
253266

254267
return true;
255268
}
256-
257269
}
258-
259270
}

0 commit comments

Comments
 (0)