43
43
* This class provides the base SPI for {@link SimpleJdbcCall}.
44
44
*
45
45
* @author Thomas Risberg
46
+ * @author Juergen Hoeller
46
47
* @since 2.5
47
48
*/
48
49
public abstract class AbstractJdbcCall {
@@ -63,17 +64,16 @@ public abstract class AbstractJdbcCall {
63
64
private final Map <String , RowMapper <?>> declaredRowMappers = new LinkedHashMap <String , RowMapper <?>>();
64
65
65
66
/**
66
- * Has this operation been compiled? Compilation means at
67
- * least checking that a DataSource and sql have been provided,
68
- * but subclasses may also implement their own custom validation.
67
+ * Has this operation been compiled? Compilation means at least checking
68
+ * that a DataSource or JdbcTemplate has been provided.
69
69
*/
70
70
private boolean compiled = false ;
71
71
72
72
/** The generated string used for call statement */
73
73
private String callString ;
74
74
75
75
/**
76
- * Object enabling us to create CallableStatementCreators
76
+ * A delegate enabling us to create CallableStatementCreators
77
77
* efficiently, based on this class's declared parameters.
78
78
*/
79
79
private CallableStatementCreatorFactory callableStatementFactory ;
@@ -92,6 +92,7 @@ protected AbstractJdbcCall(DataSource dataSource) {
92
92
* @param jdbcTemplate the JdbcTemplate to use
93
93
*/
94
94
protected AbstractJdbcCall (JdbcTemplate jdbcTemplate ) {
95
+ Assert .notNull (jdbcTemplate , "JdbcTemplate must not be null" );
95
96
this .jdbcTemplate = jdbcTemplate ;
96
97
}
97
98
@@ -161,6 +162,7 @@ public String getSchemaName() {
161
162
162
163
/**
163
164
* Specify whether this call is a function call.
165
+ * The default is {@code false}.
164
166
*/
165
167
public void setFunction (boolean function ) {
166
168
this .callMetaDataContext .setFunction (function );
@@ -174,7 +176,8 @@ public boolean isFunction() {
174
176
}
175
177
176
178
/**
177
- * Specify whether the call requires a rerurn value.
179
+ * Specify whether the call requires a return value.
180
+ * The default is {@code false}.
178
181
*/
179
182
public void setReturnValueRequired (boolean returnValueRequired ) {
180
183
this .callMetaDataContext .setReturnValueRequired (returnValueRequired );
@@ -188,7 +191,8 @@ public boolean isReturnValueRequired() {
188
191
}
189
192
190
193
/**
191
- * Specify whether the parameter metadata for the call should be used. The default is true.
194
+ * Specify whether the parameter metadata for the call should be used.
195
+ * The default is {@code true}.
192
196
*/
193
197
public void setAccessCallParameterMetaData (boolean accessCallParameterMetaData ) {
194
198
this .callMetaDataContext .setAccessCallParameterMetaData (accessCallParameterMetaData );
@@ -211,10 +215,10 @@ protected CallableStatementCreatorFactory getCallableStatementFactory() {
211
215
212
216
/**
213
217
* Add a declared parameter to the list of parameters for the call.
214
- * Only parameters declared as {@code SqlParameter} and {@code SqlInOutParameter}
215
- * will be used to provide input values. This is different from the {@code StoredProcedure} class
216
- * which for backwards compatibility reasons allows input values to be provided for parameters declared
217
- * as {@code SqlOutParameter}.
218
+ * <p> Only parameters declared as {@code SqlParameter} and {@code SqlInOutParameter} will
219
+ * be used to provide input values. This is different from the {@code StoredProcedure}
220
+ * class which - for backwards compatibility reasons - allows input values to be provided
221
+ * for parameters declared as {@code SqlOutParameter}.
218
222
* @param parameter the {@link SqlParameter} to add
219
223
*/
220
224
public void addDeclaredParameter (SqlParameter parameter ) {
@@ -247,9 +251,9 @@ public void addDeclaredRowMapper(String parameterName, RowMapper<?> rowMapper) {
247
251
//-------------------------------------------------------------------------
248
252
249
253
/**
250
- * Compile this JdbcCall using provided parameters and meta data plus other settings. This
251
- * finalizes the configuration for this object and subsequent attempts to compile are ignored.
252
- * This will be implicitly called the first time an un-compiled call is executed.
254
+ * Compile this JdbcCall using provided parameters and meta data plus other settings.
255
+ * <p>This finalizes the configuration for this object and subsequent attempts to compile are
256
+ * ignored. This will be implicitly called the first time an un-compiled call is executed.
253
257
* @throws org.springframework.dao.InvalidDataAccessApiUsageException if the object hasn't
254
258
* been correctly initialized, for example if no DataSource has been provided
255
259
*/
@@ -267,19 +271,21 @@ public synchronized final void compile() throws InvalidDataAccessApiUsageExcepti
267
271
compileInternal ();
268
272
this .compiled = true ;
269
273
if (logger .isDebugEnabled ()) {
270
- logger .debug ("SqlCall for " + (isFunction () ? "function" : "procedure" ) + " [" + getProcedureName () + "] compiled" );
274
+ logger .debug ("SqlCall for " + (isFunction () ? "function" : "procedure" ) +
275
+ " [" + getProcedureName () + "] compiled" );
271
276
}
272
277
}
273
278
}
274
279
275
280
/**
276
- * Method to perform the actual compilation. Subclasses can override this template method to perform
277
- * their own compilation. Invoked after this base class's compilation is complete.
281
+ * Delegate method to perform the actual compilation.
282
+ * <p>Subclasses can override this template method to perform their own compilation.
283
+ * Invoked after this base class's compilation is complete.
278
284
*/
279
285
protected void compileInternal () {
280
286
this .callMetaDataContext .initializeMetaData (getJdbcTemplate ().getDataSource ());
281
287
282
- // iterate over the declared RowMappers and register the corresponding SqlParameter
288
+ // Iterate over the declared RowMappers and register the corresponding SqlParameter
283
289
for (Map .Entry <String , RowMapper <?>> entry : this .declaredRowMappers .entrySet ()) {
284
290
SqlParameter resultSetParameter =
285
291
this .callMetaDataContext .createReturnResultSetParameter (entry .getKey (), entry .getValue ());
@@ -332,7 +338,7 @@ protected void checkCompiled() {
332
338
//-------------------------------------------------------------------------
333
339
334
340
/**
335
- * Method that provides execution of the call using the passed in {@link SqlParameterSource}
341
+ * Delegate method that executes the call using the passed- in {@link SqlParameterSource}.
336
342
* @param parameterSource parameter names and values to be used in call
337
343
* @return Map of out parameters
338
344
*/
@@ -343,18 +349,19 @@ protected Map<String, Object> doExecute(SqlParameterSource parameterSource) {
343
349
}
344
350
345
351
/**
346
- * Method that provides execution of the call using the passed in array of parameters
347
- * @param args array of parameter values; order must match the order declared for the stored procedure
352
+ * Delegate method that executes the call using the passed-in array of parameters.
353
+ * @param args array of parameter values. The order of values must match the order
354
+ * declared for the stored procedure.
348
355
* @return Map of out parameters
349
356
*/
350
- protected Map <String , Object > doExecute (Object [] args ) {
357
+ protected Map <String , Object > doExecute (Object ... args ) {
351
358
checkCompiled ();
352
359
Map <String , ?> params = matchInParameterValuesWithCallParameters (args );
353
360
return executeCallInternal (params );
354
361
}
355
362
356
363
/**
357
- * Method that provides execution of the call using the passed in Map of parameters
364
+ * Delegate method that executes the call using the passed- in Map of parameters.
358
365
* @param args Map of parameter name and values
359
366
* @return Map of out parameters
360
367
*/
@@ -365,7 +372,7 @@ protected Map<String, Object> doExecute(Map<String, ?> args) {
365
372
}
366
373
367
374
/**
368
- * Method to perform the actual call processing
375
+ * Delegate method to perform the actual call processing.
369
376
*/
370
377
private Map <String , Object > executeCallInternal (Map <String , ?> args ) {
371
378
CallableStatementCreator csc = getCallableStatementFactory ().newCallableStatementCreator (args );
@@ -391,8 +398,8 @@ protected String getScalarOutParameterName() {
391
398
}
392
399
393
400
/**
394
- * Get a List of all the call parameters to be used for call. This includes any parameters added
395
- * based on meta data processing.
401
+ * Get a List of all the call parameters to be used for call.
402
+ * This includes any parameters added based on meta data processing.
396
403
*/
397
404
protected List <SqlParameter > getCallParameters () {
398
405
return this .callMetaDataContext .getCallParameters ();
0 commit comments