Interface JdbcClient.BatchSpec
- Enclosing interface:
JdbcClient
Each entry(...) or entries(...) call defines one or more
complete batch entries; calls may be freely combined within the same batch.
Parameters are bound in the same fashion as for a single JdbcClient.StatementSpec,
either as JDBC-style positional parameters or as Spring-style named parameters
(but not both within the same batch).
- Since:
- 7.1
- Author:
- Juergen Hoeller, Sam Brannen, Jiri Krokviak, Yanming Zhou
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionDefine several batch entries at once, with each given parameter object defining the named parameters for one entry.Define several batch entries at once, with each element of the given list defining the named parameters for one entry.entry(Consumer<JdbcClient.BatchEntry> entryConsumer) Define a batch entry by binding its parameters through the given callback.Define a batch entry with the given list of positional parameters for "?" placeholder resolution.Define a batch entry with the given named parameters for ":x" placeholder resolution.int[]update()Execute the accumulated batch entries as a batch update.int[]Execute the accumulated batch entries as a batch update, returning generated keys.int[]Execute the accumulated batch entries as a batch update, returning generated keys.
-
Method Details
-
entry
Define a batch entry by binding its parameters through the given callback.The entry is complete once the callback returns.
- Parameters:
entryConsumer- a callback for binding the parameters of the entry- Returns:
- this batch specification (for chaining)
- Throws:
IllegalStateException- if the entry does not declare any parameters, or if named and indexed parameters are mixed within the batch
-
entry
Define a batch entry with the given list of positional parameters for "?" placeholder resolution.Each element of the list will be bound as a JDBC positional parameter with a corresponding JDBC index (i.e. list index + 1).
Note that the given list represents the parameters of a single entry; see
entries(List)for defining several entries at once.nullelements are bound as SQLNULLvalues. SinceList.of()rejectsnullelements, use a list which permits them — for example,Arrays.asList(T...)— or bind each parameter individually viaentry(Consumer).- Parameters:
values- the parameter values to bind- Returns:
- this batch specification (for chaining)
- Throws:
IllegalStateException- if the list is empty, or if named and indexed parameters are mixed within the batch- See Also:
-
entry
Define a batch entry with the given named parameters for ":x" placeholder resolution.- Parameters:
paramMap- a map of names and parameter values to bind- Returns:
- this batch specification (for chaining)
- Throws:
IllegalStateException- if the map is empty, or if named and indexed parameters are mixed within the batch- See Also:
-
entries
Define several batch entries at once, with each given parameter object defining the named parameters for one entry.Each parameter object is resolved in the same fashion as for
JdbcClient.BatchEntry.paramSource(Object): based on its JavaBean properties, record components, or raw fields. AMapor anSqlParameterSourceinstance is supported as well.- Parameters:
namedParamObjects- the parameter objects, one per batch entry- Returns:
- this batch specification (for chaining)
- Throws:
IllegalStateException- if named and indexed parameters are mixed within the batch- See Also:
-
entries
Define several batch entries at once, with each element of the given list defining the named parameters for one entry.Each parameter object is resolved in the same fashion as for
JdbcClient.BatchEntry.paramSource(Object): based on its JavaBean properties, record components, or raw fields. AMapor anSqlParameterSourceinstance is supported as well.Note that each element of the given list represents a separate entry; see
entry(List)for defining a single entry with positional parameters.- Parameters:
namedParamObjects- the parameter objects, one per batch entry- Returns:
- this batch specification (for chaining)
- Throws:
IllegalStateException- if named and indexed parameters are mixed within the batch
-
update
int[] update()Execute the accumulated batch entries as a batch update.- Returns:
- an array containing the numbers of rows affected by each execution in the batch
(may also contain special JDBC-defined negative values for affected rows such as
Statement.SUCCESS_NO_INFO/Statement.EXECUTE_FAILED) - Throws:
org.springframework.dao.DataAccessException- if there is any problem issuing the update- See Also:
-
update
Execute the accumulated batch entries as a batch update, returning generated keys.- Parameters:
generatedKeyHolder- aKeyHolderthat will hold the generated keys- Returns:
- an array containing the numbers of rows affected by each execution in the batch
(may also contain special JDBC-defined negative values for affected rows such as
Statement.SUCCESS_NO_INFO/Statement.EXECUTE_FAILED) - Throws:
org.springframework.dao.DataAccessException- if there is any problem issuing the update- See Also:
-
update
Execute the accumulated batch entries as a batch update, returning generated keys.- Parameters:
generatedKeyHolder- aKeyHolderthat will hold the generated keyskeyColumnNames- names of the columns that will have keys generated for them- Returns:
- an array containing the numbers of rows affected by each execution in the batch
(may also contain special JDBC-defined negative values for affected rows such as
Statement.SUCCESS_NO_INFO/Statement.EXECUTE_FAILED) - Throws:
org.springframework.dao.DataAccessException- if there is any problem issuing the update- See Also:
-