@@ -73,29 +73,27 @@ abstract class JdbcQueryLookupStrategy extends RelationalQueryLookupStrategy {
7373 private final JdbcConverter converter ;
7474 private final QueryMappingConfiguration queryMappingConfiguration ;
7575 private final NamedParameterJdbcOperations operations ;
76- @ Nullable private final BeanFactory beanfactory ;
7776 protected final QueryMethodEvaluationContextProvider evaluationContextProvider ;
7877
7978 JdbcQueryLookupStrategy (ApplicationEventPublisher publisher , @ Nullable EntityCallbacks callbacks ,
8079 RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
8180 QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
82- @ Nullable BeanFactory beanfactory , QueryMethodEvaluationContextProvider evaluationContextProvider ) {
81+ QueryMethodEvaluationContextProvider evaluationContextProvider ) {
8382
8483 super (context , dialect );
8584
8685 Assert .notNull (publisher , "ApplicationEventPublisher must not be null" );
8786 Assert .notNull (converter , "JdbcConverter must not be null" );
8887 Assert .notNull (queryMappingConfiguration , "QueryMappingConfiguration must not be null" );
8988 Assert .notNull (operations , "NamedParameterJdbcOperations must not be null" );
90- Assert .notNull (evaluationContextProvider , "QueryMethodEvaluationContextProvier must not be null" );
89+ Assert .notNull (evaluationContextProvider , "QueryMethodEvaluationContextProvider must not be null" );
9190
9291 this .context = context ;
9392 this .publisher = publisher ;
9493 this .callbacks = callbacks ;
9594 this .converter = converter ;
9695 this .queryMappingConfiguration = queryMappingConfiguration ;
9796 this .operations = operations ;
98- this .beanfactory = beanfactory ;
9997 this .evaluationContextProvider = evaluationContextProvider ;
10098 }
10199
@@ -114,9 +112,9 @@ static class CreateQueryLookupStrategy extends JdbcQueryLookupStrategy {
114112 CreateQueryLookupStrategy (ApplicationEventPublisher publisher , @ Nullable EntityCallbacks callbacks ,
115113 RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
116114 QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
117- @ Nullable BeanFactory beanfactory , QueryMethodEvaluationContextProvider evaluationContextProvider ) {
115+ QueryMethodEvaluationContextProvider evaluationContextProvider ) {
118116
119- super (publisher , callbacks , context , converter , dialect , queryMappingConfiguration , operations , beanfactory ,
117+ super (publisher , callbacks , context , converter , dialect , queryMappingConfiguration , operations ,
120118 evaluationContextProvider );
121119 }
122120
@@ -140,12 +138,16 @@ public RepositoryQuery resolveQuery(Method method, RepositoryMetadata repository
140138 */
141139 static class DeclaredQueryLookupStrategy extends JdbcQueryLookupStrategy {
142140
141+ private final AbstractJdbcQuery .RowMapperFactory rowMapperFactory ;
142+
143143 DeclaredQueryLookupStrategy (ApplicationEventPublisher publisher , @ Nullable EntityCallbacks callbacks ,
144144 RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
145145 QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
146146 @ Nullable BeanFactory beanfactory , QueryMethodEvaluationContextProvider evaluationContextProvider ) {
147- super (publisher , callbacks , context , converter , dialect , queryMappingConfiguration , operations , beanfactory ,
147+ super (publisher , callbacks , context , converter , dialect , queryMappingConfiguration , operations ,
148148 evaluationContextProvider );
149+
150+ this .rowMapperFactory = new BeanFactoryRowMapperFactory (beanfactory );
149151 }
150152
151153 @ Override
@@ -163,36 +165,51 @@ public RepositoryQuery resolveQuery(Method method, RepositoryMetadata repository
163165
164166 String queryString = evaluateTableExpressions (repositoryMetadata , queryMethod .getRequiredQuery ());
165167
166- return new StringBasedJdbcQuery (queryString , queryMethod , getOperations (),
167- new BeanFactoryRowMapperFactory ( getBeanFactory ()), getConverter (), evaluationContextProvider );
168+ return new StringBasedJdbcQuery (queryString , queryMethod , getOperations (), rowMapperFactory , getConverter (),
169+ evaluationContextProvider );
168170 }
169171
170172 throw new IllegalStateException (
171173 String .format ("Did neither find a NamedQuery nor an annotated query for method %s" , method ));
172174 }
173175
176+ @ SuppressWarnings ("unchecked" )
174177 private class BeanFactoryRowMapperFactory implements AbstractJdbcQuery .RowMapperFactory {
175178
176- private final BeanFactory beanFactory ;
179+ private final @ Nullable BeanFactory beanFactory ;
177180
178- BeanFactoryRowMapperFactory (BeanFactory beanFactory ) {
181+ BeanFactoryRowMapperFactory (@ Nullable BeanFactory beanFactory ) {
179182 this .beanFactory = beanFactory ;
180183 }
184+
181185 @ Override
182186 public RowMapper <Object > create (Class <?> result ) {
183187 return createMapper (result );
184188 }
185189
186190 @ Override
187- public RowMapper <Object > rowMapperByReference (String reference ) {
191+ public RowMapper <Object > getRowMapper (String reference ) {
192+
193+ if (beanFactory == null ) {
194+ throw new IllegalStateException (
195+ "Cannot resolve RowMapper bean reference '" + reference + "'; BeanFactory is not configured." );
196+ }
197+
188198 return beanFactory .getBean (reference , RowMapper .class );
189199 }
190200
191201 @ Override
192- public ResultSetExtractor <Object > resultSetExtractorByReference (String reference ) {
202+ public ResultSetExtractor <Object > getResultSetExtractor (String reference ) {
203+
204+ if (beanFactory == null ) {
205+ throw new IllegalStateException (
206+ "Cannot resolve ResultSetExtractor bean reference '" + reference + "'; BeanFactory is not configured." );
207+ }
208+
193209 return beanFactory .getBean (reference , ResultSetExtractor .class );
194210 }
195211 }
212+
196213 }
197214
198215 /**
@@ -217,10 +234,10 @@ static class CreateIfNotFoundQueryLookupStrategy extends JdbcQueryLookupStrategy
217234 CreateIfNotFoundQueryLookupStrategy (ApplicationEventPublisher publisher , @ Nullable EntityCallbacks callbacks ,
218235 RelationalMappingContext context , JdbcConverter converter , Dialect dialect ,
219236 QueryMappingConfiguration queryMappingConfiguration , NamedParameterJdbcOperations operations ,
220- @ Nullable BeanFactory beanfactory , CreateQueryLookupStrategy createStrategy ,
237+ CreateQueryLookupStrategy createStrategy ,
221238 DeclaredQueryLookupStrategy lookupStrategy , QueryMethodEvaluationContextProvider evaluationContextProvider ) {
222239
223- super (publisher , callbacks , context , converter , dialect , queryMappingConfiguration , operations , beanfactory ,
240+ super (publisher , callbacks , context , converter , dialect , queryMappingConfiguration , operations ,
224241 evaluationContextProvider );
225242
226243 Assert .notNull (createStrategy , "CreateQueryLookupStrategy must not be null" );
@@ -277,23 +294,23 @@ public static QueryLookupStrategy create(@Nullable Key key, ApplicationEventPubl
277294 Assert .notNull (operations , "NamedParameterJdbcOperations must not be null" );
278295
279296 CreateQueryLookupStrategy createQueryLookupStrategy = new CreateQueryLookupStrategy (publisher , callbacks , context ,
280- converter , dialect , queryMappingConfiguration , operations , beanFactory , evaluationContextProvider );
297+ converter , dialect , queryMappingConfiguration , operations , evaluationContextProvider );
281298
282299 DeclaredQueryLookupStrategy declaredQueryLookupStrategy = new DeclaredQueryLookupStrategy (publisher , callbacks ,
283300 context , converter , dialect , queryMappingConfiguration , operations , beanFactory , evaluationContextProvider );
284301
285- Key cleanedKey = key != null ? key : Key .CREATE_IF_NOT_FOUND ;
302+ Key keyToUse = key != null ? key : Key .CREATE_IF_NOT_FOUND ;
286303
287- LOG .debug (String .format ("Using the queryLookupStrategy %s" , cleanedKey ));
304+ LOG .debug (String .format ("Using the queryLookupStrategy %s" , keyToUse ));
288305
289- switch (cleanedKey ) {
306+ switch (keyToUse ) {
290307 case CREATE :
291308 return createQueryLookupStrategy ;
292309 case USE_DECLARED_QUERY :
293310 return declaredQueryLookupStrategy ;
294311 case CREATE_IF_NOT_FOUND :
295312 return new CreateIfNotFoundQueryLookupStrategy (publisher , callbacks , context , converter , dialect ,
296- queryMappingConfiguration , operations , beanFactory , createQueryLookupStrategy , declaredQueryLookupStrategy ,
313+ queryMappingConfiguration , operations , createQueryLookupStrategy , declaredQueryLookupStrategy ,
297314 evaluationContextProvider );
298315 default :
299316 throw new IllegalArgumentException (String .format ("Unsupported query lookup strategy %s" , key ));
@@ -308,11 +325,6 @@ NamedParameterJdbcOperations getOperations() {
308325 return operations ;
309326 }
310327
311- @ Nullable
312- BeanFactory getBeanFactory () {
313- return beanfactory ;
314- }
315-
316328 @ SuppressWarnings ("unchecked" )
317329 RowMapper <Object > createMapper (Class <?> returnedObjectType ) {
318330
0 commit comments