|
23 | 23 | import jakarta.persistence.TupleElement;
|
24 | 24 | import jakarta.persistence.TypedQuery;
|
25 | 25 |
|
| 26 | +import java.lang.reflect.InvocationTargetException; |
| 27 | +import java.util.ArrayList; |
26 | 28 | import java.util.Arrays;
|
27 | 29 | import java.util.Collection;
|
28 | 30 | import java.util.HashMap;
|
|
51 | 53 | import org.springframework.jdbc.support.JdbcUtils;
|
52 | 54 | import org.springframework.lang.Nullable;
|
53 | 55 | import org.springframework.util.Assert;
|
| 56 | +import org.springframework.util.ClassUtils; |
54 | 57 |
|
55 | 58 | /**
|
56 | 59 | * Abstract base class to implement {@link RepositoryQuery}s.
|
@@ -353,6 +356,24 @@ public Object convert(Object source) {
|
353 | 356 | }
|
354 | 357 | }
|
355 | 358 |
|
| 359 | + if(type.isProjecting() && !type.getReturnedType().isInterface() && !type.getInputProperties().isEmpty()) { |
| 360 | + List<Object> ctorArgs = new ArrayList<>(type.getInputProperties().size()); |
| 361 | + type.getInputProperties().forEach(it -> { |
| 362 | + ctorArgs.add(tuple.get(it)); |
| 363 | + }); |
| 364 | + try { |
| 365 | + return type.getReturnedType().getConstructor(ctorArgs.stream().map(Object::getClass).toArray(Class<?>[]::new)).newInstance(ctorArgs.toArray()); |
| 366 | + } catch (InstantiationException e) { |
| 367 | + throw new RuntimeException(e); |
| 368 | + } catch (IllegalAccessException e) { |
| 369 | + throw new RuntimeException(e); |
| 370 | + } catch (InvocationTargetException e) { |
| 371 | + throw new RuntimeException(e); |
| 372 | + } catch (NoSuchMethodException e) { |
| 373 | + throw new RuntimeException(e); |
| 374 | + } |
| 375 | + } |
| 376 | + |
356 | 377 | return new TupleBackedMap(tupleWrapper.apply(tuple));
|
357 | 378 | }
|
358 | 379 |
|
|
0 commit comments