Interface JdbcClient.BatchSpec

Enclosing interface:
JdbcClient

public static interface JdbcClient.BatchSpec
A specification for accumulating several batch entries for a batch update, with each entry representing the parameters for one statement execution within the batch.

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 Type
    Method
    Description
    entries(Object... namedParamObjects)
    Define several batch entries at once, with each given parameter object defining the named parameters for one entry.
    entries(List<?> namedParamObjects)
    Define several batch entries at once, with each element of the given list defining the named parameters for one entry.
    Define a batch entry by binding its parameters through the given callback.
    entry(List<?> values)
    Define a batch entry with the given list of positional parameters for "?" placeholder resolution.
    entry(Map<String,?> paramMap)
    Define a batch entry with the given named parameters for ":x" placeholder resolution.
    int[]
    Execute the accumulated batch entries as a batch update.
    int[]
    update(KeyHolder generatedKeyHolder)
    Execute the accumulated batch entries as a batch update, returning generated keys.
    int[]
    update(KeyHolder generatedKeyHolder, String... keyColumnNames)
    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

      JdbcClient.BatchSpec entry(List<?> values)
      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.

      null elements are bound as SQL NULL values. Since List.of() rejects null elements, use a list which permits them — for example, Arrays.asList(T...) — or bind each parameter individually via entry(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

      JdbcClient.BatchSpec entry(Map<String,?> paramMap)
      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

      JdbcClient.BatchSpec entries(Object... namedParamObjects)
      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. A Map or an SqlParameterSource instance 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

      JdbcClient.BatchSpec entries(List<?> namedParamObjects)
      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. A Map or an SqlParameterSource instance 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

      int[] update(KeyHolder generatedKeyHolder)
      Execute the accumulated batch entries as a batch update, returning generated keys.
      Parameters:
      generatedKeyHolder - a KeyHolder that 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

      int[] update(KeyHolder generatedKeyHolder, String... keyColumnNames)
      Execute the accumulated batch entries as a batch update, returning generated keys.
      Parameters:
      generatedKeyHolder - a KeyHolder that will hold the generated keys
      keyColumnNames - 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: