|
16 | 16 | package org.springframework.data.jdbc.repository.aot; |
17 | 17 |
|
18 | 18 | import java.io.IOException; |
| 19 | +import java.sql.SQLType; |
19 | 20 | import java.util.ArrayList; |
20 | 21 | import java.util.List; |
21 | 22 | import java.util.Objects; |
|
24 | 25 | import org.jspecify.annotations.Nullable; |
25 | 26 |
|
26 | 27 | import org.springframework.core.annotation.MergedAnnotation; |
| 28 | +import org.springframework.core.convert.ConversionService; |
27 | 29 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
| 30 | +import org.springframework.data.core.TypeInformation; |
28 | 31 | import org.springframework.data.domain.Sort; |
| 32 | +import org.springframework.data.jdbc.core.convert.Identifier; |
29 | 33 | import org.springframework.data.jdbc.core.convert.JdbcConverter; |
30 | 34 | import org.springframework.data.jdbc.core.convert.JdbcCustomConversions; |
31 | 35 | import org.springframework.data.jdbc.core.convert.JdbcTypeFactory; |
32 | 36 | import org.springframework.data.jdbc.core.convert.MappingJdbcConverter; |
33 | 37 | import org.springframework.data.jdbc.core.dialect.JdbcDialect; |
| 38 | +import org.springframework.data.jdbc.core.mapping.JdbcValue; |
34 | 39 | import org.springframework.data.jdbc.repository.config.JdbcRepositoryConfigExtension; |
35 | 40 | import org.springframework.data.jdbc.repository.query.JdbcCountQueryCreator; |
36 | 41 | import org.springframework.data.jdbc.repository.query.JdbcParameters; |
|
39 | 44 | import org.springframework.data.jdbc.repository.query.ParameterBinding; |
40 | 45 | import org.springframework.data.jdbc.repository.query.ParametrizedQuery; |
41 | 46 | import org.springframework.data.jdbc.repository.query.Query; |
| 47 | +import org.springframework.data.mapping.PersistentEntity; |
| 48 | +import org.springframework.data.mapping.PersistentPropertyPathAccessor; |
| 49 | +import org.springframework.data.mapping.model.EntityInstantiators; |
| 50 | +import org.springframework.data.projection.EntityProjection; |
42 | 51 | import org.springframework.data.relational.core.mapping.RelationalMappingContext; |
| 52 | +import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; |
| 53 | +import org.springframework.data.relational.domain.RowDocument; |
43 | 54 | import org.springframework.data.relational.repository.query.ParameterMetadataProvider; |
44 | 55 | import org.springframework.data.relational.repository.query.RelationalParameterAccessor; |
45 | 56 | import org.springframework.data.relational.repository.query.RelationalParameters; |
@@ -158,10 +169,14 @@ private AotQueries buildNamedQuery(String queryName, JdbcQueryMethod queryMethod |
158 | 169 | private AotQueries buildPartTreeQuery(RepositoryInformation repositoryInformation, ReturnedType returnedType, |
159 | 170 | JdbcQueryMethod queryMethod) { |
160 | 171 |
|
| 172 | + if (queryMethod.getName().equals("findByCreatedBetween")) { |
| 173 | + System.out.println(); |
| 174 | + } |
161 | 175 | PartTree partTree = new PartTree(queryMethod.getName(), repositoryInformation.getDomainType()); |
162 | 176 | RelationalParametersParameterAccessor accessor = getAccessor(queryMethod); |
163 | 177 |
|
164 | | - JdbcQueryCreator queryCreator = new JdbcQueryCreator(partTree, converter, dialect, queryMethod, accessor, |
| 178 | + JdbcQueryCreator queryCreator = new JdbcQueryCreator(partTree, new AotPassThruJdbcConverter(converter), dialect, |
| 179 | + queryMethod, accessor, |
165 | 180 | returnedType) { |
166 | 181 |
|
167 | 182 | @Override |
@@ -226,4 +241,95 @@ private List<ParameterBinding> getBindings(ValueExpressionQueryRewriter.ParsedQu |
226 | 241 | return bindings; |
227 | 242 | } |
228 | 243 |
|
| 244 | + /** |
| 245 | + * Pass-thru implementation for {@link JdbcValue} objects to allow capturing parameter placeholders without applying |
| 246 | + * conversion. |
| 247 | + * |
| 248 | + * @param delegate |
| 249 | + */ |
| 250 | + record AotPassThruJdbcConverter(JdbcConverter delegate) implements JdbcConverter { |
| 251 | + |
| 252 | + @Override |
| 253 | + public Class<?> getColumnType(RelationalPersistentProperty property) { |
| 254 | + return delegate.getColumnType(property); |
| 255 | + } |
| 256 | + |
| 257 | + @Override |
| 258 | + public SQLType getTargetSqlType(RelationalPersistentProperty property) { |
| 259 | + return delegate.getTargetSqlType(property); |
| 260 | + } |
| 261 | + |
| 262 | + @Override |
| 263 | + public RelationalMappingContext getMappingContext() { |
| 264 | + return delegate.getMappingContext(); |
| 265 | + } |
| 266 | + |
| 267 | + @Override |
| 268 | + public ConversionService getConversionService() { |
| 269 | + return delegate.getConversionService(); |
| 270 | + } |
| 271 | + |
| 272 | + @Override |
| 273 | + public EntityInstantiators getEntityInstantiators() { |
| 274 | + return delegate.getEntityInstantiators(); |
| 275 | + } |
| 276 | + |
| 277 | + @Override |
| 278 | + public <T> PersistentPropertyPathAccessor<T> getPropertyAccessor(PersistentEntity<T, ?> persistentEntity, |
| 279 | + T instance) { |
| 280 | + return delegate.getPropertyAccessor(persistentEntity, instance); |
| 281 | + } |
| 282 | + |
| 283 | + @Override |
| 284 | + public JdbcValue writeJdbcValue(@Nullable Object value, Class<?> type, SQLType sqlType) { |
| 285 | + return value instanceof JdbcValue jdbcValue ? jdbcValue : delegate.writeJdbcValue(value, type, sqlType); |
| 286 | + } |
| 287 | + |
| 288 | + @Override |
| 289 | + public JdbcValue writeJdbcValue(@Nullable Object value, TypeInformation<?> type, SQLType sqlType) { |
| 290 | + return value instanceof JdbcValue jdbcValue ? jdbcValue : delegate.writeJdbcValue(value, type, sqlType); |
| 291 | + } |
| 292 | + |
| 293 | + @Override |
| 294 | + public @Nullable Object writeValue(@Nullable Object value, TypeInformation<?> type) { |
| 295 | + return value; |
| 296 | + } |
| 297 | + |
| 298 | + @Override |
| 299 | + public <R> R readAndResolve(Class<R> type, RowDocument source) { |
| 300 | + throw new UnsupportedOperationException(); |
| 301 | + } |
| 302 | + |
| 303 | + @Override |
| 304 | + public <R> R readAndResolve(Class<R> type, RowDocument source, Identifier identifier) { |
| 305 | + throw new UnsupportedOperationException(); |
| 306 | + } |
| 307 | + |
| 308 | + @Override |
| 309 | + public <R> R readAndResolve(TypeInformation<R> type, RowDocument source, Identifier identifier) { |
| 310 | + throw new UnsupportedOperationException(); |
| 311 | + } |
| 312 | + |
| 313 | + @Override |
| 314 | + public <M, D> EntityProjection<M, D> introspectProjection(Class<M> resultType, Class<D> entityType) { |
| 315 | + throw new UnsupportedOperationException(); |
| 316 | + } |
| 317 | + |
| 318 | + @Override |
| 319 | + public <R> R project(EntityProjection<R, ?> descriptor, RowDocument document) { |
| 320 | + throw new UnsupportedOperationException(); |
| 321 | + } |
| 322 | + |
| 323 | + @Override |
| 324 | + public <R> R read(Class<R> type, RowDocument source) { |
| 325 | + throw new UnsupportedOperationException(); |
| 326 | + } |
| 327 | + |
| 328 | + @Override |
| 329 | + public @Nullable Object readValue(@Nullable Object value, TypeInformation<?> type) { |
| 330 | + throw new UnsupportedOperationException(); |
| 331 | + } |
| 332 | + |
| 333 | + } |
| 334 | + |
229 | 335 | } |
0 commit comments