18
18
import reactor .core .publisher .Flux ;
19
19
import reactor .core .publisher .Mono ;
20
20
21
- import java .util .Arrays ;
22
- import java .util .Map ;
23
- import java .util .Optional ;
24
-
25
- import org .springframework .core .ReactiveAdapter ;
26
- import org .springframework .core .ReactiveAdapterRegistry ;
27
- import org .springframework .core .ReactiveTypeDescriptor ;
28
- import org .springframework .data .util .ProxyUtils ;
29
- import org .springframework .data .util .ReflectionUtils ;
30
21
import org .springframework .util .Assert ;
31
- import org .springframework .util .ClassUtils ;
32
- import org .springframework .util .ConcurrentReferenceHashMap ;
33
22
34
23
/**
35
24
* Utility class to expose details about reactive wrapper types. This class exposes whether a reactive wrapper is
54
43
* @see io.smallrye.mutiny.Uni
55
44
* @see Mono
56
45
* @see Flux
46
+ * @deprecated since 3.0, use {@link org.springframework.data.util.ReactiveWrappers} instead as the utility was moved
47
+ * into the {@code org.springframework.data.util} package.
57
48
*/
49
+ @ Deprecated (since = "3.0" , forRemoval = true )
58
50
public abstract class ReactiveWrappers {
59
51
60
- private static final boolean PROJECT_REACTOR_PRESENT = ClassUtils .isPresent ("reactor.core.publisher.Flux" ,
61
- ReactiveWrappers .class .getClassLoader ());
62
-
63
- private static final boolean RXJAVA3_PRESENT = ClassUtils .isPresent ("io.reactivex.rxjava3.core.Flowable" ,
64
- ReactiveWrappers .class .getClassLoader ());
65
-
66
- private static final boolean KOTLIN_COROUTINES_PRESENT = ClassUtils .isPresent ("kotlinx.coroutines.reactor.MonoKt" ,
67
- ReactiveWrappers .class .getClassLoader ());
68
-
69
- private static final boolean MUTINY_PRESENT = ClassUtils .isPresent ("io.smallrye.mutiny.Multi" ,
70
- ReactiveWrappers .class .getClassLoader ());
71
-
72
- private static final Map <Class <?>, Boolean > IS_REACTIVE_TYPE = new ConcurrentReferenceHashMap <>();
73
-
74
- private static final boolean IS_REACTIVE_AVAILABLE = Arrays .stream (ReactiveLibrary .values ())
75
- .anyMatch (ReactiveWrappers ::isAvailable );
76
-
77
52
private ReactiveWrappers () {}
78
53
79
54
/**
80
55
* Enumeration of supported reactive libraries.
81
56
*
82
57
* @author Mark Paluch
58
+ * @deprecated use {@link org.springframework.data.util.ReactiveWrappers.ReactiveLibrary} instead.
83
59
*/
60
+ @ Deprecated (since = "3.0" , forRemoval = true )
84
61
public enum ReactiveLibrary {
85
62
86
63
PROJECT_REACTOR , RXJAVA3 , KOTLIN_COROUTINES , MUTINY ;
@@ -93,7 +70,7 @@ public enum ReactiveLibrary {
93
70
* @return {@literal true} if reactive support is available.
94
71
*/
95
72
public static boolean isAvailable () {
96
- return IS_REACTIVE_AVAILABLE ;
73
+ return org . springframework . data . util . ReactiveWrappers . isAvailable () ;
97
74
}
98
75
99
76
/**
@@ -108,13 +85,14 @@ public static boolean isAvailable(ReactiveLibrary reactiveLibrary) {
108
85
109
86
switch (reactiveLibrary ) {
110
87
case PROJECT_REACTOR :
111
- return PROJECT_REACTOR_PRESENT ;
88
+ return org . springframework . data . util . ReactiveWrappers . PROJECT_REACTOR_PRESENT ;
112
89
case RXJAVA3 :
113
- return RXJAVA3_PRESENT ;
90
+ return org . springframework . data . util . ReactiveWrappers . RXJAVA3_PRESENT ;
114
91
case KOTLIN_COROUTINES :
115
- return PROJECT_REACTOR_PRESENT && KOTLIN_COROUTINES_PRESENT ;
92
+ return org .springframework .data .util .ReactiveWrappers .PROJECT_REACTOR_PRESENT
93
+ && org .springframework .data .util .ReactiveWrappers .KOTLIN_COROUTINES_PRESENT ;
116
94
case MUTINY :
117
- return MUTINY_PRESENT ;
95
+ return org . springframework . data . util . ReactiveWrappers . MUTINY_PRESENT ;
118
96
default :
119
97
throw new IllegalArgumentException (String .format ("Reactive library %s not supported" , reactiveLibrary ));
120
98
}
@@ -127,7 +105,7 @@ public static boolean isAvailable(ReactiveLibrary reactiveLibrary) {
127
105
* @return {@literal true} if the {@code type} is a supported reactive wrapper type.
128
106
*/
129
107
public static boolean supports (Class <?> type ) {
130
- return isAvailable () && IS_REACTIVE_TYPE . computeIfAbsent ( type , key -> isWrapper ( ProxyUtils . getUserClass ( key )) );
108
+ return org . springframework . data . util . ReactiveWrappers . supports ( type );
131
109
}
132
110
133
111
/**
@@ -140,9 +118,7 @@ public static boolean usesReactiveType(Class<?> type) {
140
118
141
119
Assert .notNull (type , "Type must not be null" );
142
120
143
- return Arrays .stream (type .getMethods ())//
144
- .flatMap (ReflectionUtils ::returnTypeAndParameters )//
145
- .anyMatch (ReactiveWrappers ::supports );
121
+ return org .springframework .data .util .ReactiveWrappers .usesReactiveType (type );
146
122
}
147
123
148
124
/**
@@ -155,7 +131,7 @@ public static boolean isNoValueType(Class<?> type) {
155
131
156
132
Assert .notNull (type , "Candidate type must not be null" );
157
133
158
- return findDescriptor ( type ). map ( ReactiveTypeDescriptor :: isNoValue ). orElse ( false );
134
+ return org . springframework . data . util . ReactiveWrappers . isNoValueType ( type );
159
135
}
160
136
161
137
/**
@@ -168,7 +144,7 @@ public static boolean isSingleValueType(Class<?> type) {
168
144
169
145
Assert .notNull (type , "Candidate type must not be null" );
170
146
171
- return findDescriptor ( type ). map ( it -> ! it . isMultiValue () && ! it . isNoValue ()). orElse ( false );
147
+ return org . springframework . data . util . ReactiveWrappers . isSingleValueType ( type );
172
148
}
173
149
174
150
/**
@@ -183,46 +159,7 @@ public static boolean isMultiValueType(Class<?> type) {
183
159
184
160
Assert .notNull (type , "Candidate type must not be null" );
185
161
186
- // Prevent single-types with a multi-hierarchy supertype to be reported as multi type
187
- // See Mono implements Publisher
188
- return isSingleValueType (type ) ? false
189
- : findDescriptor (type ).map (ReactiveTypeDescriptor ::isMultiValue ).orElse (false );
162
+ return org .springframework .data .util .ReactiveWrappers .isMultiValueType (type );
190
163
}
191
164
192
- /**
193
- * Returns whether the given type is a reactive wrapper type.
194
- *
195
- * @param type must not be {@literal null}.
196
- * @return
197
- */
198
- private static boolean isWrapper (Class <?> type ) {
199
-
200
- Assert .notNull (type , "Candidate type must not be null" );
201
-
202
- return isNoValueType (type ) || isSingleValueType (type ) || isMultiValueType (type );
203
- }
204
-
205
- /**
206
- * Looks up a {@link ReactiveTypeDescriptor} for the given wrapper type.
207
- *
208
- * @param type must not be {@literal null}.
209
- * @return
210
- */
211
- private static Optional <ReactiveTypeDescriptor > findDescriptor (Class <?> type ) {
212
-
213
- Assert .notNull (type , "Wrapper type must not be null" );
214
-
215
- ReactiveAdapterRegistry adapterRegistry = ReactiveWrapperConverters .RegistryHolder .REACTIVE_ADAPTER_REGISTRY ;
216
-
217
- if (adapterRegistry == null ) {
218
- return Optional .empty ();
219
- }
220
-
221
- ReactiveAdapter adapter = adapterRegistry .getAdapter (type );
222
- if (adapter != null && adapter .getDescriptor ().isDeferred ()) {
223
- return Optional .of (adapter .getDescriptor ());
224
- }
225
-
226
- return Optional .empty ();
227
- }
228
165
}
0 commit comments