1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2013 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -88,6 +88,21 @@ <T> T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallb
88
88
<T > T execute (String sql , Map <String , ?> paramMap , PreparedStatementCallback <T > action )
89
89
throws DataAccessException ;
90
90
91
+ /**
92
+ * Execute a JDBC data access operation, implemented as callback action
93
+ * working on a JDBC PreparedStatement. This allows for implementing arbitrary
94
+ * data access operations on a single Statement, within Spring's managed
95
+ * JDBC environment: that is, participating in Spring-managed transactions
96
+ * and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.
97
+ * <p>The callback action can return a result object, for example a
98
+ * domain object or a collection of domain objects.
99
+ * @param sql SQL to execute
100
+ * @param action callback object that specifies the action
101
+ * @return a result object returned by the action, or {@code null}
102
+ * @throws DataAccessException if there is any problem
103
+ */
104
+ <T > T execute (String sql , PreparedStatementCallback <T > action ) throws DataAccessException ;
105
+
91
106
/**
92
107
* Query given SQL to create a prepared statement from SQL and a list
93
108
* of arguments to bind to the query, reading the ResultSet with a
@@ -115,6 +130,19 @@ <T> T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rs
115
130
<T > T query (String sql , Map <String , ?> paramMap , ResultSetExtractor <T > rse )
116
131
throws DataAccessException ;
117
132
133
+ /**
134
+ * Query given SQL to create a prepared statement from SQL,
135
+ * reading the ResultSet with a ResultSetExtractor.
136
+ * <p>Note: In contrast to the JdbcOperations method with the same signature,
137
+ * this query variant always uses a PreparedStatement. It is effectively
138
+ * equivalent to a query call with an empty parameter Map.
139
+ * @param sql SQL query to execute
140
+ * @param rse object that will extract results
141
+ * @return an arbitrary result object, as returned by the ResultSetExtractor
142
+ * @throws org.springframework.dao.DataAccessException if the query fails
143
+ */
144
+ <T > T query (String sql , ResultSetExtractor <T > rse ) throws DataAccessException ;
145
+
118
146
/**
119
147
* Query given SQL to create a prepared statement from SQL and a list of
120
148
* arguments to bind to the query, reading the ResultSet on a per-row basis
@@ -139,6 +167,18 @@ void query(String sql, SqlParameterSource paramSource, RowCallbackHandler rch)
139
167
*/
140
168
void query (String sql , Map <String , ?> paramMap , RowCallbackHandler rch ) throws DataAccessException ;
141
169
170
+ /**
171
+ * Query given SQL to create a prepared statement from SQL,
172
+ * reading the ResultSet on a per-row basis with a RowCallbackHandler.
173
+ * <p>Note: In contrast to the JdbcOperations method with the same signature,
174
+ * this query variant always uses a PreparedStatement. It is effectively
175
+ * equivalent to a query call with an empty parameter Map.
176
+ * @param sql SQL query to execute
177
+ * @param rch object that will extract results, one row at a time
178
+ * @throws org.springframework.dao.DataAccessException if the query fails
179
+ */
180
+ void query (String sql , RowCallbackHandler rch ) throws DataAccessException ;
181
+
142
182
/**
143
183
* Query given SQL to create a prepared statement from SQL and a list
144
184
* of arguments to bind to the query, mapping each row to a Java object
@@ -166,6 +206,19 @@ <T> List<T> query(String sql, SqlParameterSource paramSource, RowMapper<T> rowMa
166
206
<T > List <T > query (String sql , Map <String , ?> paramMap , RowMapper <T > rowMapper )
167
207
throws DataAccessException ;
168
208
209
+ /**
210
+ * Query given SQL to create a prepared statement from SQL,
211
+ * mapping each row to a Java object via a RowMapper.
212
+ * <p>Note: In contrast to the JdbcOperations method with the same signature,
213
+ * this query variant always uses a PreparedStatement. It is effectively
214
+ * equivalent to a query call with an empty parameter Map.
215
+ * @param sql SQL query to execute
216
+ * @param rowMapper object that will map one object per row
217
+ * @return the result List, containing mapped objects
218
+ * @throws org.springframework.dao.DataAccessException if the query fails
219
+ */
220
+ <T > List <T > query (String sql , RowMapper <T > rowMapper ) throws DataAccessException ;
221
+
169
222
/**
170
223
* Query given SQL to create a prepared statement from SQL and a list
171
224
* of arguments to bind to the query, mapping a single result row to a
@@ -245,8 +298,7 @@ <T> T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
245
298
* @param paramSource container of arguments to bind to the query
246
299
* @return the result Map (one entry for each column, using the column name as the key)
247
300
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
248
- * if the query does not return exactly one row, or does not return exactly
249
- * one column in that row
301
+ * if the query does not return exactly one row
250
302
* @throws org.springframework.dao.DataAccessException if the query fails
251
303
* @see org.springframework.jdbc.core.JdbcTemplate#queryForMap(String)
252
304
* @see org.springframework.jdbc.core.ColumnMapRowMapper
@@ -266,8 +318,7 @@ <T> T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
266
318
* (leaving it to the PreparedStatement to guess the corresponding SQL type)
267
319
* @return the result Map (one entry for each column, using the column name as the key)
268
320
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
269
- * if the query does not return exactly one row, or does not return exactly
270
- * one column in that row
321
+ * if the query does not return exactly one row
271
322
* @throws org.springframework.dao.DataAccessException if the query fails
272
323
* @see org.springframework.jdbc.core.JdbcTemplate#queryForMap(String)
273
324
* @see org.springframework.jdbc.core.ColumnMapRowMapper
@@ -287,7 +338,9 @@ <T> T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
287
338
* one column in that row
288
339
* @throws org.springframework.dao.DataAccessException if the query fails
289
340
* @see org.springframework.jdbc.core.JdbcTemplate#queryForLong(String)
341
+ * @deprecated in favor of {@link #queryForObject(String, SqlParameterSource, Class)}
290
342
*/
343
+ @ Deprecated
291
344
long queryForLong (String sql , SqlParameterSource paramSource ) throws DataAccessException ;
292
345
293
346
/**
@@ -304,7 +357,9 @@ <T> T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
304
357
* one column in that row
305
358
* @throws org.springframework.dao.DataAccessException if the query fails
306
359
* @see org.springframework.jdbc.core.JdbcTemplate#queryForLong(String)
360
+ * @deprecated in favor of {@link #queryForObject(String, Map, Class)}
307
361
*/
362
+ @ Deprecated
308
363
long queryForLong (String sql , Map <String , ?> paramMap ) throws DataAccessException ;
309
364
310
365
/**
@@ -319,7 +374,9 @@ <T> T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
319
374
* exactly one row, or does not return exactly one column in that row
320
375
* @throws org.springframework.dao.DataAccessException if the query fails
321
376
* @see org.springframework.jdbc.core.JdbcTemplate#queryForInt(String)
377
+ * @deprecated in favor of {@link #queryForObject(String, SqlParameterSource, Class)}
322
378
*/
379
+ @ Deprecated
323
380
int queryForInt (String sql , SqlParameterSource paramSource ) throws DataAccessException ;
324
381
325
382
/**
@@ -335,7 +392,9 @@ <T> T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
335
392
* exactly one row, or does not return exactly one column in that row
336
393
* @throws org.springframework.dao.DataAccessException if the query fails
337
394
* @see org.springframework.jdbc.core.JdbcTemplate#queryForInt(String)
395
+ * @deprecated in favor of {@link #queryForObject(String, Map, Class)}
338
396
*/
397
+ @ Deprecated
339
398
int queryForInt (String sql , Map <String , ?> paramMap ) throws DataAccessException ;
340
399
341
400
/**
@@ -378,8 +437,8 @@ <T> List<T> queryForList(String sql, Map<String, ?> paramMap, Class<T> elementTy
378
437
* list of arguments to bind to the query, expecting a result list.
379
438
* <p>The results will be mapped to a List (one entry for each row) of
380
439
* Maps (one entry for each column, using the column name as the key).
381
- * Thus Each element in the list will be of the form returned by this interface's
382
- * queryForMap() methods.
440
+ * Each element in the list will be of the form returned by this interface's
441
+ * {@code queryForMap} methods.
383
442
* @param sql SQL query to execute
384
443
* @param paramSource container of arguments to bind to the query
385
444
* @return a List that contains a Map per row
@@ -394,7 +453,7 @@ <T> List<T> queryForList(String sql, Map<String, ?> paramMap, Class<T> elementTy
394
453
* <p>The results will be mapped to a List (one entry for each row) of
395
454
* Maps (one entry for each column, using the column name as the key).
396
455
* Each element in the list will be of the form returned by this interface's
397
- * queryForMap() methods.
456
+ * {@code queryForMap} methods.
398
457
* @param sql SQL query to execute
399
458
* @param paramMap map of parameters to bind to the query
400
459
* (leaving it to the PreparedStatement to guess the corresponding SQL type)
@@ -499,14 +558,14 @@ int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHol
499
558
* @param batchValues the array of Maps containing the batch of arguments for the query
500
559
* @return an array containing the numbers of rows affected by each update in the batch
501
560
*/
502
- public int [] batchUpdate (String sql , Map <String , ?>[] batchValues );
561
+ int [] batchUpdate (String sql , Map <String , ?>[] batchValues );
503
562
504
563
/**
505
564
* Execute a batch using the supplied SQL statement with the batch of supplied arguments.
506
565
* @param sql the SQL statement to execute
507
566
* @param batchArgs the array of {@link SqlParameterSource} containing the batch of arguments for the query
508
567
* @return an array containing the numbers of rows affected by each update in the batch
509
568
*/
510
- public int [] batchUpdate (String sql , SqlParameterSource [] batchArgs );
569
+ int [] batchUpdate (String sql , SqlParameterSource [] batchArgs );
511
570
512
571
}
0 commit comments