Skip to content

Commit 1d4b8db

Browse files
committed
Added Lazy wrapper for ReturnType#isDto
1 parent f305308 commit 1d4b8db

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;
@@ -198,12 +199,14 @@ public List<String> getInputProperties() {
198199
* A {@link ReturnedType} that's backed by an actual class.
199200
*
200201
* @author Oliver Gierke
202+
* @author Mikhail Polivakha
201203
* @since 1.12
202204
*/
203205
private static final class ReturnedClass extends ReturnedType {
204206

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

209+
private final Lazy<Boolean> isDto;
207210
private final Class<?> type;
208211
private final List<String> inputProperties;
209212

@@ -222,6 +225,15 @@ public ReturnedClass(Class<?> returnedType, Class<?> domainType) {
222225
Assert.isTrue(!returnedType.isInterface(), "Returned type must not be an interface");
223226

224227
this.type = returnedType;
228+
this.isDto = Lazy.of(() ->
229+
!Object.class.equals(type) && //
230+
!type.isEnum() && //
231+
!isDomainSubtype() && //
232+
!isPrimitiveOrWrapper() && //
233+
!Number.class.isAssignableFrom(type) && //
234+
!VOID_TYPES.contains(type) && //
235+
!type.getPackage().getName().startsWith("java.")
236+
);
225237
this.inputProperties = detectConstructorParameterNames(returnedType);
226238
}
227239

@@ -271,13 +283,7 @@ private List<String> detectConstructorParameterNames(Class<?> type) {
271283
}
272284

273285
private boolean isDto() {
274-
return !Object.class.equals(type) && //
275-
!type.isEnum() && //
276-
!isDomainSubtype() && //
277-
!isPrimitiveOrWrapper() && //
278-
!Number.class.isAssignableFrom(type) && //
279-
!VOID_TYPES.contains(type) && //
280-
!type.getPackage().getName().startsWith("java.");
286+
return isDto.get();
281287
}
282288

283289
private boolean isDomainSubtype() {

0 commit comments

Comments
 (0)