Skip to content

Commit a23375c

Browse files
committed
Document JDBC driver requirement for KeyHolder-based update methods
Closes gh-31486
1 parent 53b9379 commit a23375c

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,12 +933,14 @@ <T> List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> ele
933933
* <p>Note that the given PreparedStatementCreator has to create a statement
934934
* with activated extraction of generated keys (a JDBC 3.0 feature). This can
935935
* either be done directly or through using a PreparedStatementCreatorFactory.
936+
* <p>This method requires support for generated keys in the JDBC driver.
936937
* @param psc a callback that provides SQL and any necessary parameters
937938
* @param generatedKeyHolder a KeyHolder that will hold the generated keys
938939
* @return the number of rows affected
939940
* @throws DataAccessException if there is any problem issuing the update
940941
* @see PreparedStatementCreatorFactory
941942
* @see org.springframework.jdbc.support.GeneratedKeyHolder
943+
* @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys()
942944
*/
943945
int update(PreparedStatementCreator psc, KeyHolder generatedKeyHolder) throws DataAccessException;
944946

@@ -1004,7 +1006,8 @@ <T> List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> ele
10041006
* <p>Note that the given PreparedStatementCreator has to create a statement
10051007
* with activated extraction of generated keys (a JDBC 3.0 feature). This can
10061008
* either be done directly or through using a PreparedStatementCreatorFactory.
1007-
* <p>Will fall back to separate updates on a single PreparedStatement
1009+
* <p>This method requires support for generated keys in the JDBC driver.
1010+
* It will fall back to separate updates on a single PreparedStatement
10081011
* if the JDBC driver does not support batch updates.
10091012
* @param psc a callback that creates a PreparedStatement given a Connection
10101013
* @param pss object to set parameters on the PreparedStatement
@@ -1016,6 +1019,7 @@ <T> List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> ele
10161019
* @throws DataAccessException if there is any problem issuing the update
10171020
* @since 6.1
10181021
* @see org.springframework.jdbc.support.GeneratedKeyHolder
1022+
* @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys()
10191023
*/
10201024
int[] batchUpdate(PreparedStatementCreator psc, BatchPreparedStatementSetter pss,
10211025
KeyHolder generatedKeyHolder) throws DataAccessException;

spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,20 +506,23 @@ <T> List<T> queryForList(String sql, Map<String, ?> paramMap, Class<T> elementTy
506506
/**
507507
* Issue an update via a prepared statement, binding the given arguments,
508508
* returning generated keys.
509+
* <p>This method requires support for generated keys in the JDBC driver.
509510
* @param sql the SQL containing named parameters
510511
* @param paramSource container of arguments and SQL types to bind to the query
511512
* @param generatedKeyHolder a {@link KeyHolder} that will hold the generated keys
512513
* @return the number of rows affected
513514
* @throws DataAccessException if there is any problem issuing the update
514515
* @see MapSqlParameterSource
515516
* @see org.springframework.jdbc.support.GeneratedKeyHolder
517+
* @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys()
516518
*/
517519
int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder)
518520
throws DataAccessException;
519521

520522
/**
521523
* Issue an update via a prepared statement, binding the given arguments,
522524
* returning generated keys.
525+
* <p>This method requires support for generated keys in the JDBC driver.
523526
* @param sql the SQL containing named parameters
524527
* @param paramSource container of arguments and SQL types to bind to the query
525528
* @param generatedKeyHolder a {@link KeyHolder} that will hold the generated keys
@@ -528,6 +531,7 @@ int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHol
528531
* @throws DataAccessException if there is any problem issuing the update
529532
* @see MapSqlParameterSource
530533
* @see org.springframework.jdbc.support.GeneratedKeyHolder
534+
* @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys()
531535
*/
532536
int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, String[] keyColumnNames)
533537
throws DataAccessException;
@@ -558,6 +562,7 @@ int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHol
558562
/**
559563
* Execute a batch using the supplied SQL statement with the batch of supplied
560564
* arguments, returning generated keys.
565+
* <p>This method requires support for generated keys in the JDBC driver.
561566
* @param sql the SQL statement to execute
562567
* @param batchArgs the array of {@link SqlParameterSource} containing the batch of
563568
* arguments for the query
@@ -568,12 +573,14 @@ int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHol
568573
* @throws DataAccessException if there is any problem issuing the update
569574
* @since 6.1
570575
* @see org.springframework.jdbc.support.GeneratedKeyHolder
576+
* @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys()
571577
*/
572578
int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder);
573579

574580
/**
575581
* Execute a batch using the supplied SQL statement with the batch of supplied arguments,
576582
* returning generated keys.
583+
* <p>This method requires support for generated keys in the JDBC driver.
577584
* @param sql the SQL statement to execute
578585
* @param batchArgs the array of {@link SqlParameterSource} containing the batch of
579586
* arguments for the query
@@ -585,7 +592,9 @@ int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHol
585592
* @throws DataAccessException if there is any problem issuing the update
586593
* @since 6.1
587594
* @see org.springframework.jdbc.support.GeneratedKeyHolder
595+
* @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys()
588596
*/
589597
int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder,
590598
String[] keyColumnNames);
599+
591600
}

spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/JdbcClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,24 @@ interface StatementSpec {
282282

283283
/**
284284
* Execute the provided SQL statement as an update.
285+
* <p>This method requires support for generated keys in the JDBC driver.
285286
* @param generatedKeyHolder a KeyHolder that will hold the generated keys
286287
* (typically a {@link org.springframework.jdbc.support.GeneratedKeyHolder})
287288
* @return the number of rows affected
288289
* @see java.sql.PreparedStatement#executeUpdate()
290+
* @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys()
289291
*/
290292
int update(KeyHolder generatedKeyHolder);
291293

292294
/**
293295
* Execute the provided SQL statement as an update.
296+
* <p>This method requires support for generated keys in the JDBC driver.
294297
* @param generatedKeyHolder a KeyHolder that will hold the generated keys
295298
* (typically a {@link org.springframework.jdbc.support.GeneratedKeyHolder})
296299
* @param keyColumnNames names of the columns that will have keys generated for them
297300
* @return the number of rows affected
298301
* @see java.sql.PreparedStatement#executeUpdate()
302+
* @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys()
299303
*/
300304
int update(KeyHolder generatedKeyHolder, String... keyColumnNames);
301305
}

0 commit comments

Comments
 (0)