1515 */
1616package org .springframework .data .jdbc .repository .query ;
1717
18- import static org .springframework .data .jdbc .repository .query .JdbcQueryExecution .* ;
18+ import static org .springframework .data .jdbc .repository .query .JdbcQueryExecution .ResultProcessingConverter ;
1919
2020import java .lang .reflect .Array ;
2121import java .lang .reflect .Constructor ;
3232import org .springframework .beans .BeanInstantiationException ;
3333import org .springframework .beans .BeanUtils ;
3434import org .springframework .beans .factory .BeanFactory ;
35- import org .springframework .core .env .StandardEnvironment ;
3635import org .springframework .data .expression .ValueEvaluationContext ;
37- import org .springframework .data .expression .ValueExpressionParser ;
3836import org .springframework .data .jdbc .core .convert .JdbcColumnTypes ;
3937import org .springframework .data .jdbc .core .convert .JdbcConverter ;
4038import org .springframework .data .jdbc .core .mapping .JdbcValue ;
4139import org .springframework .data .jdbc .support .JdbcUtil ;
42- import org .springframework .data .relational .core .dialect .SqlTypeResolver ;
4340import org .springframework .data .relational .core .mapping .RelationalMappingContext ;
4441import org .springframework .data .relational .repository .query .RelationalParameterAccessor ;
4542import org .springframework .data .relational .repository .query .RelationalParametersParameterAccessor ;
46- import org .springframework .data .repository .query .CachingValueExpressionDelegate ;
4743import org .springframework .data .repository .query .Parameter ;
4844import org .springframework .data .repository .query .Parameters ;
4945import org .springframework .data .repository .query .QueryMethodEvaluationContextProvider ;
50- import org .springframework .data .repository .query .QueryMethodValueEvaluationContextAccessor ;
5146import org .springframework .data .repository .query .ResultProcessor ;
5247import org .springframework .data .repository .query .ValueExpressionDelegate ;
5348import org .springframework .data .repository .query .ValueExpressionQueryRewriter ;
@@ -92,15 +87,52 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery {
9287 private final CachedResultSetExtractorFactory cachedResultSetExtractorFactory ;
9388 private final ValueExpressionDelegate delegate ;
9489
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+ 95107 /**
96108 * Creates a new {@link StringBasedJdbcQuery} for the given {@link JdbcQueryMethod}, {@link RelationalMappingContext}
97109 * and {@link RowMapperFactory}.
98110 *
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}.
101133 * @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}.
104136 * @since 3.4
105137 */
106138 public StringBasedJdbcQuery (JdbcQueryMethod queryMethod , NamedParameterJdbcOperations operations ,
@@ -112,12 +144,12 @@ public StringBasedJdbcQuery(JdbcQueryMethod queryMethod, NamedParameterJdbcOpera
112144 * Creates a new {@link StringBasedJdbcQuery} for the given {@link JdbcQueryMethod}, {@link RelationalMappingContext}
113145 * and {@link RowMapperFactory}.
114146 *
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}.
118150 * @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}.
121153 * @since 3.4
122154 */
123155 public StringBasedJdbcQuery (String query , JdbcQueryMethod queryMethod , NamedParameterJdbcOperations operations ,
@@ -161,6 +193,28 @@ public StringBasedJdbcQuery(String query, JdbcQueryMethod queryMethod, NamedPara
161193 this .delegate = delegate ;
162194 }
163195
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+ }
164218
165219 @ Override
166220 public Object execute (Object [] objects ) {
@@ -355,7 +409,8 @@ private static boolean isUnconfigured(@Nullable Class<?> configuredClass, Class<
355409 }
356410
357411 @ Deprecated (since = "3.4" )
358- public void setBeanFactory (BeanFactory beanFactory ) {}
412+ public void setBeanFactory (BeanFactory beanFactory ) {
413+ }
359414
360415 class CachedRowMapperFactory {
361416
@@ -414,19 +469,20 @@ public CachedResultSetExtractorFactory(Supplier<RowMapper<?>> resultSetExtractor
414469 String resultSetExtractorRef = getQueryMethod ().getResultSetExtractorRef ();
415470 Class <? extends ResultSetExtractor > resultSetExtractorClass = getQueryMethod ().getResultSetExtractorClass ();
416471
417- if (!ObjectUtils .isEmpty (resultSetExtractorRef )
418- && ! isUnconfigured ( resultSetExtractorClass , ResultSetExtractor .class )) {
472+ if (!ObjectUtils .isEmpty (resultSetExtractorRef ) && ! isUnconfigured ( resultSetExtractorClass ,
473+ ResultSetExtractor .class )) {
419474 throw new IllegalArgumentException (
420475 "Invalid ResultSetExtractor configuration. Configure either one but not both via @Query(resultSetExtractorRef = ..., resultSetExtractorClass = ...) for query method "
421476 + getQueryMethod ());
422477 }
423478
424- this .configuredResultSetExtractor = !ObjectUtils .isEmpty (resultSetExtractorRef )
425- || !isUnconfigured (resultSetExtractorClass , ResultSetExtractor .class );
479+ this .configuredResultSetExtractor =
480+ !ObjectUtils .isEmpty (resultSetExtractorRef ) || !isUnconfigured (resultSetExtractorClass ,
481+ ResultSetExtractor .class );
426482
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 ;
430486 this .constructor = resultSetExtractorClass != null ? findPrimaryConstructor (resultSetExtractorClass ) : null ;
431487 this .resultSetExtractorFactory = rowMapper -> {
432488
0 commit comments