15
15
*/
16
16
package org .springframework .data .jdbc .repository .query ;
17
17
18
- import static org .springframework .data .jdbc .repository .query .JdbcQueryExecution .* ;
18
+ import static org .springframework .data .jdbc .repository .query .JdbcQueryExecution .ResultProcessingConverter ;
19
19
20
20
import java .lang .reflect .Array ;
21
21
import java .lang .reflect .Constructor ;
32
32
import org .springframework .beans .BeanInstantiationException ;
33
33
import org .springframework .beans .BeanUtils ;
34
34
import org .springframework .beans .factory .BeanFactory ;
35
- import org .springframework .core .env .StandardEnvironment ;
36
35
import org .springframework .data .expression .ValueEvaluationContext ;
37
- import org .springframework .data .expression .ValueExpressionParser ;
38
36
import org .springframework .data .jdbc .core .convert .JdbcColumnTypes ;
39
37
import org .springframework .data .jdbc .core .convert .JdbcConverter ;
40
38
import org .springframework .data .jdbc .core .mapping .JdbcValue ;
41
39
import org .springframework .data .jdbc .support .JdbcUtil ;
42
- import org .springframework .data .relational .core .dialect .SqlTypeResolver ;
43
40
import org .springframework .data .relational .core .mapping .RelationalMappingContext ;
44
41
import org .springframework .data .relational .repository .query .RelationalParameterAccessor ;
45
42
import org .springframework .data .relational .repository .query .RelationalParametersParameterAccessor ;
46
- import org .springframework .data .repository .query .CachingValueExpressionDelegate ;
47
43
import org .springframework .data .repository .query .Parameter ;
48
44
import org .springframework .data .repository .query .Parameters ;
49
45
import org .springframework .data .repository .query .QueryMethodEvaluationContextProvider ;
50
- import org .springframework .data .repository .query .QueryMethodValueEvaluationContextAccessor ;
51
46
import org .springframework .data .repository .query .ResultProcessor ;
52
47
import org .springframework .data .repository .query .ValueExpressionDelegate ;
53
48
import org .springframework .data .repository .query .ValueExpressionQueryRewriter ;
@@ -92,15 +87,52 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery {
92
87
private final CachedResultSetExtractorFactory cachedResultSetExtractorFactory ;
93
88
private final ValueExpressionDelegate delegate ;
94
89
90
+ /**
91
+ * Creates a new {@link StringBasedJdbcQuery} for the given {@link JdbcQueryMethod}, {@link RelationalMappingContext}
92
+ * and {@link RowMapper}.
93
+ *
94
+ * @param queryMethod must not be {@literal null}.
95
+ * @param operations must not be {@literal null}.
96
+ * @param defaultRowMapper can be {@literal null} (only in case of a modifying query).
97
+ * @deprecated since 3.4, use the constructors accepting {@link ValueExpressionDelegate} instead.
98
+ */
99
+ @ Deprecated (since = "3.4" )
100
+ public StringBasedJdbcQuery (JdbcQueryMethod queryMethod , NamedParameterJdbcOperations operations ,
101
+ @ Nullable RowMapper <?> defaultRowMapper , JdbcConverter converter ,
102
+ QueryMethodEvaluationContextProvider evaluationContextProvider ) {
103
+ this (queryMethod .getRequiredQuery (), queryMethod , operations , result -> (RowMapper <Object >) defaultRowMapper ,
104
+ converter , evaluationContextProvider );
105
+ }
106
+
95
107
/**
96
108
* Creates a new {@link StringBasedJdbcQuery} for the given {@link JdbcQueryMethod}, {@link RelationalMappingContext}
97
109
* and {@link RowMapperFactory}.
98
110
*
99
- * @param queryMethod must not be {@literal null}.
100
- * @param operations must not be {@literal null}.
111
+ * @param queryMethod must not be {@literal null}.
112
+ * @param operations must not be {@literal null}.
113
+ * @param rowMapperFactory must not be {@literal null}.
114
+ * @param converter must not be {@literal null}.
115
+ * @param evaluationContextProvider must not be {@literal null}.
116
+ * @since 2.3
117
+ * @deprecated use alternative constructor
118
+ */
119
+ @ Deprecated (since = "3.4" )
120
+ public StringBasedJdbcQuery (JdbcQueryMethod queryMethod , NamedParameterJdbcOperations operations ,
121
+ RowMapperFactory rowMapperFactory , JdbcConverter converter ,
122
+ QueryMethodEvaluationContextProvider evaluationContextProvider ) {
123
+ this (queryMethod .getRequiredQuery (), queryMethod , operations , rowMapperFactory , converter ,
124
+ evaluationContextProvider );
125
+ }
126
+
127
+ /**
128
+ * Creates a new {@link StringBasedJdbcQuery} for the given {@link JdbcQueryMethod}, {@link RelationalMappingContext}
129
+ * and {@link RowMapperFactory}.
130
+ *
131
+ * @param queryMethod must not be {@literal null}.
132
+ * @param operations must not be {@literal null}.
101
133
* @param rowMapperFactory must not be {@literal null}.
102
- * @param converter must not be {@literal null}.
103
- * @param delegate must not be {@literal null}.
134
+ * @param converter must not be {@literal null}.
135
+ * @param delegate must not be {@literal null}.
104
136
* @since 3.4
105
137
*/
106
138
public StringBasedJdbcQuery (JdbcQueryMethod queryMethod , NamedParameterJdbcOperations operations ,
@@ -112,12 +144,12 @@ public StringBasedJdbcQuery(JdbcQueryMethod queryMethod, NamedParameterJdbcOpera
112
144
* Creates a new {@link StringBasedJdbcQuery} for the given {@link JdbcQueryMethod}, {@link RelationalMappingContext}
113
145
* and {@link RowMapperFactory}.
114
146
*
115
- * @param query must not be {@literal null} or empty.
116
- * @param queryMethod must not be {@literal null}.
117
- * @param operations must not be {@literal null}.
147
+ * @param query must not be {@literal null} or empty.
148
+ * @param queryMethod must not be {@literal null}.
149
+ * @param operations must not be {@literal null}.
118
150
* @param rowMapperFactory must not be {@literal null}.
119
- * @param converter must not be {@literal null}.
120
- * @param delegate must not be {@literal null}.
151
+ * @param converter must not be {@literal null}.
152
+ * @param delegate must not be {@literal null}.
121
153
* @since 3.4
122
154
*/
123
155
public StringBasedJdbcQuery (String query , JdbcQueryMethod queryMethod , NamedParameterJdbcOperations operations ,
@@ -161,6 +193,28 @@ public StringBasedJdbcQuery(String query, JdbcQueryMethod queryMethod, NamedPara
161
193
this .delegate = delegate ;
162
194
}
163
195
196
+ /**
197
+ * Creates a new {@link StringBasedJdbcQuery} for the given {@link JdbcQueryMethod}, {@link RelationalMappingContext}
198
+ * and {@link RowMapperFactory}.
199
+ *
200
+ * @param query must not be {@literal null} or empty.
201
+ * @param queryMethod must not be {@literal null}.
202
+ * @param operations must not be {@literal null}.
203
+ * @param rowMapperFactory must not be {@literal null}.
204
+ * @param converter must not be {@literal null}.
205
+ * @param evaluationContextProvider must not be {@literal null}.
206
+ * @since 3.4
207
+ * @deprecated since 3.4, use the constructors accepting {@link ValueExpressionDelegate} instead.
208
+ */
209
+ @ Deprecated (since = "3.4" )
210
+ public StringBasedJdbcQuery (String query , JdbcQueryMethod queryMethod , NamedParameterJdbcOperations operations ,
211
+ RowMapperFactory rowMapperFactory , JdbcConverter converter ,
212
+ QueryMethodEvaluationContextProvider evaluationContextProvider ) {
213
+ this (query , queryMethod , operations , rowMapperFactory , converter , new CachingValueExpressionDelegate (
214
+ new QueryMethodValueEvaluationContextAccessor (new StandardEnvironment (),
215
+ rootObject -> evaluationContextProvider .getEvaluationContext (queryMethod .getParameters (),
216
+ new Object [] { rootObject })), ValueExpressionParser .create ()));
217
+ }
164
218
165
219
@ Override
166
220
public Object execute (Object [] objects ) {
@@ -355,7 +409,8 @@ private static boolean isUnconfigured(@Nullable Class<?> configuredClass, Class<
355
409
}
356
410
357
411
@ Deprecated (since = "3.4" )
358
- public void setBeanFactory (BeanFactory beanFactory ) {}
412
+ public void setBeanFactory (BeanFactory beanFactory ) {
413
+ }
359
414
360
415
class CachedRowMapperFactory {
361
416
@@ -414,19 +469,20 @@ public CachedResultSetExtractorFactory(Supplier<RowMapper<?>> resultSetExtractor
414
469
String resultSetExtractorRef = getQueryMethod ().getResultSetExtractorRef ();
415
470
Class <? extends ResultSetExtractor > resultSetExtractorClass = getQueryMethod ().getResultSetExtractorClass ();
416
471
417
- if (!ObjectUtils .isEmpty (resultSetExtractorRef )
418
- && ! isUnconfigured ( resultSetExtractorClass , ResultSetExtractor .class )) {
472
+ if (!ObjectUtils .isEmpty (resultSetExtractorRef ) && ! isUnconfigured ( resultSetExtractorClass ,
473
+ ResultSetExtractor .class )) {
419
474
throw new IllegalArgumentException (
420
475
"Invalid ResultSetExtractor configuration. Configure either one but not both via @Query(resultSetExtractorRef = …, resultSetExtractorClass = …) for query method "
421
476
+ getQueryMethod ());
422
477
}
423
478
424
- this .configuredResultSetExtractor = !ObjectUtils .isEmpty (resultSetExtractorRef )
425
- || !isUnconfigured (resultSetExtractorClass , ResultSetExtractor .class );
479
+ this .configuredResultSetExtractor =
480
+ !ObjectUtils .isEmpty (resultSetExtractorRef ) || !isUnconfigured (resultSetExtractorClass ,
481
+ ResultSetExtractor .class );
426
482
427
- this .rowMapperConstructor = resultSetExtractorClass != null
428
- ? ClassUtils .getConstructorIfAvailable (resultSetExtractorClass , RowMapper .class )
429
- : null ;
483
+ this .rowMapperConstructor = resultSetExtractorClass != null ?
484
+ ClassUtils .getConstructorIfAvailable (resultSetExtractorClass , RowMapper .class ) :
485
+ null ;
430
486
this .constructor = resultSetExtractorClass != null ? findPrimaryConstructor (resultSetExtractorClass ) : null ;
431
487
this .resultSetExtractorFactory = rowMapper -> {
432
488
0 commit comments