Skip to content

Commit 15afbff

Browse files
mipo256mp911de
authored andcommitted
Added Lazy wrapper for ReturnType#isDto.
Closes #3160
1 parent 7ff224b commit 15afbff

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/main/java/org/springframework/data/repository/query/ReturnedType.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.data.mapping.model.PreferredConstructorDiscoverer;
3030
import org.springframework.data.projection.ProjectionFactory;
3131
import org.springframework.data.projection.ProjectionInformation;
32+
import org.springframework.data.util.Lazy;
3233
import org.springframework.lang.NonNull;
3334
import org.springframework.lang.Nullable;
3435
import org.springframework.util.Assert;
@@ -219,12 +220,14 @@ public List<String> getInputProperties() {
219220
* A {@link ReturnedType} that's backed by an actual class.
220221
*
221222
* @author Oliver Gierke
223+
* @author Mikhail Polivakha
222224
* @since 1.12
223225
*/
224226
private static final class ReturnedClass extends ReturnedType {
225227

226228
private static final Set<Class<?>> VOID_TYPES = new HashSet<>(Arrays.asList(Void.class, void.class));
227229

230+
private final Lazy<Boolean> isDto;
228231
private final Class<?> type;
229232
private final List<String> inputProperties;
230233

@@ -243,6 +246,15 @@ public ReturnedClass(Class<?> returnedType, Class<?> domainType) {
243246
Assert.isTrue(!returnedType.isInterface(), "Returned type must not be an interface");
244247

245248
this.type = returnedType;
249+
this.isDto = Lazy.of(() ->
250+
!Object.class.equals(type) && //
251+
!type.isEnum() && //
252+
!isDomainSubtype() && //
253+
!isPrimitiveOrWrapper() && //
254+
!Number.class.isAssignableFrom(type) && //
255+
!VOID_TYPES.contains(type) && //
256+
!type.getPackage().getName().startsWith("java.")
257+
);
246258
this.inputProperties = detectConstructorParameterNames(returnedType);
247259
}
248260

@@ -294,13 +306,7 @@ private List<String> detectConstructorParameterNames(Class<?> type) {
294306
}
295307

296308
private boolean isDto() {
297-
return !Object.class.equals(type) && //
298-
!type.isEnum() && //
299-
!isDomainSubtype() && //
300-
!isPrimitiveOrWrapper() && //
301-
!Number.class.isAssignableFrom(type) && //
302-
!VOID_TYPES.contains(type) && //
303-
!type.getPackage().getName().startsWith("java.");
309+
return isDto.get();
304310
}
305311

306312
private boolean isDomainSubtype() {

0 commit comments

Comments
 (0)