Skip to content

Commit 96621b3

Browse files
mipo256mp911de
authored andcommitted
Added Lazy wrapper for ReturnType#isDto.
Closes #3160
1 parent dde5b37 commit 96621b3

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;
@@ -218,12 +219,14 @@ public List<String> getInputProperties() {
218219
* A {@link ReturnedType} that's backed by an actual class.
219220
*
220221
* @author Oliver Gierke
222+
* @author Mikhail Polivakha
221223
* @since 1.12
222224
*/
223225
private static final class ReturnedClass extends ReturnedType {
224226

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

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

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

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

@@ -293,13 +305,7 @@ private List<String> detectConstructorParameterNames(Class<?> type) {
293305
}
294306

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

305311
private boolean isDomainSubtype() {

0 commit comments

Comments
 (0)