|
15 | 15 | */
|
16 | 16 | package example.springdata.jdbc.immutables;
|
17 | 17 |
|
18 |
| -import java.sql.ResultSet; |
19 |
| - |
20 | 18 | import org.springframework.boot.autoconfigure.SpringBootApplication;
|
21 | 19 | import org.springframework.context.annotation.Configuration;
|
22 | 20 | import org.springframework.context.annotation.Lazy;
|
23 | 21 | import org.springframework.core.io.ResourceLoader;
|
24 |
| -import org.springframework.data.jdbc.core.convert.BasicJdbcConverter; |
25 | 22 | import org.springframework.data.jdbc.core.convert.DefaultJdbcTypeFactory;
|
26 |
| -import org.springframework.data.jdbc.core.convert.Identifier; |
27 | 23 | import org.springframework.data.jdbc.core.convert.JdbcConverter;
|
28 | 24 | import org.springframework.data.jdbc.core.convert.JdbcCustomConversions;
|
| 25 | +import org.springframework.data.jdbc.core.convert.MappingJdbcConverter; |
29 | 26 | import org.springframework.data.jdbc.core.convert.RelationResolver;
|
30 | 27 | import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
|
31 | 28 | import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration;
|
32 |
| -import org.springframework.data.mapping.PersistentPropertyPath; |
33 |
| -import org.springframework.data.mapping.context.MappingContext; |
| 29 | +import org.springframework.data.relational.core.conversion.RowDocumentAccessor; |
34 | 30 | import org.springframework.data.relational.core.dialect.Dialect;
|
35 |
| -import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension; |
36 | 31 | import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
|
37 |
| -import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; |
| 32 | +import org.springframework.data.util.TypeInformation; |
38 | 33 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
39 | 34 | import org.springframework.util.ClassUtils;
|
40 | 35 |
|
@@ -78,27 +73,17 @@ public JdbcConverter jdbcConverter(JdbcMappingContext mappingContext, NamedParam
|
78 | 73 |
|
79 | 74 | var jdbcTypeFactory = new DefaultJdbcTypeFactory(operations.getJdbcOperations());
|
80 | 75 |
|
81 |
| - return new BasicJdbcConverter(mappingContext, relationResolver, conversions, jdbcTypeFactory, |
82 |
| - dialect.getIdentifierProcessing()) { |
83 |
| - |
84 |
| - @Override |
85 |
| - public <T> T mapRow(RelationalPersistentEntity<T> entity, ResultSet resultSet, Object key) { |
86 |
| - |
87 |
| - // rows will not be mapped to the entity interface, but to its implementation generated by Immutable |
88 |
| - RelationalPersistentEntity<T> implementationEntity = getImplementationEntity(mappingContext, entity); |
89 |
| - return super.mapRow(implementationEntity, resultSet, key); |
90 |
| - } |
| 76 | + return new MappingJdbcConverter(mappingContext, relationResolver, conversions, jdbcTypeFactory) { |
91 | 77 |
|
92 | 78 | @Override
|
93 |
| - public <T> T mapRow(PersistentPropertyPathExtension path, ResultSet resultSet, Identifier identifier, |
94 |
| - Object key) { |
| 79 | + @SuppressWarnings("all") |
| 80 | + protected <S> S readAggregate(ConversionContext context, RowDocumentAccessor documentAccessor, |
| 81 | + TypeInformation<? extends S> typeHint) { |
95 | 82 |
|
96 |
| - // rows will not be mapped to the entity interface, but to its implementation generated by Immutable |
97 | 83 | RelationalPersistentEntity<?> implementationEntity = getImplementationEntity(mappingContext,
|
98 |
| - path.getLeafEntity()); |
99 |
| - var propertyPath = new DelegatePersistentPropertyPathExtension(mappingContext, |
100 |
| - path.getRequiredPersistentPropertyPath(), implementationEntity); |
101 |
| - return super.mapRow(propertyPath, resultSet, identifier, key); |
| 84 | + mappingContext.getRequiredPersistentEntity(typeHint)); |
| 85 | + |
| 86 | + return (S) super.readAggregate(context, documentAccessor, implementationEntity.getTypeInformation()); |
102 | 87 | }
|
103 | 88 | };
|
104 | 89 | }
|
@@ -126,26 +111,4 @@ private <T> RelationalPersistentEntity<T> getImplementationEntity(JdbcMappingCon
|
126 | 111 | }
|
127 | 112 | }
|
128 | 113 |
|
129 |
| - /** |
130 |
| - * Redirect {@link #getLeafEntity()} to a different entity type. |
131 |
| - */ |
132 |
| - static class DelegatePersistentPropertyPathExtension extends PersistentPropertyPathExtension { |
133 |
| - |
134 |
| - private final RelationalPersistentEntity<?> leafEntity; |
135 |
| - |
136 |
| - public DelegatePersistentPropertyPathExtension( |
137 |
| - MappingContext<? extends RelationalPersistentEntity<?>, ? extends RelationalPersistentProperty> context, |
138 |
| - PersistentPropertyPath<? extends RelationalPersistentProperty> path, RelationalPersistentEntity<?> leafEntity) { |
139 |
| - |
140 |
| - super(context, path); |
141 |
| - |
142 |
| - this.leafEntity = leafEntity; |
143 |
| - } |
144 |
| - |
145 |
| - @Override |
146 |
| - public RelationalPersistentEntity<?> getLeafEntity() { |
147 |
| - return leafEntity; |
148 |
| - } |
149 |
| - } |
150 |
| - |
151 | 114 | }
|
0 commit comments