Repository navigation
Closed
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancementA general enhancement
Milestone
Description
Overview
The BatchSpec API introduced in 7.1 milestones for JdbcClient uses a method-chaining style in which parameters are bound to a "current" batch entry and consecutive entries are separated via add():
client.sql("INSERT INTO user (first_name, last_name) VALUES (:firstName, :lastName)")
.batch()
.param("firstName", "Jane").param("lastName", "Smith").add()
.param("firstName", "John").param("lastName", "Doe")
.update();This style is error-prone: a missing add() still compiles but silently merges parameters into a single entry. It also does not lend itself to the typical batch use case of providing parameters dynamically β for example, from an existing collection of domain objects.
Since BatchSpec has not been released yet, we should revise its design before 7.1 RC1.
Proposal
Replace the chaining style with self-contained batch entries:
BatchSpec::entry(Consumer<BatchEntry>): defines one entry via a callback.BatchSpec::entry(List<?>)andentry(Map<String, ?>): define one entry with positional or named parameters.BatchSpec::entries(List<?>)andentries(Object...): define one entry per parameter object (DTO, record,Map, orSqlParameterSource).- New
BatchEntrytype exposing only the singularparam(...)andparamSource(...)methods. - Remove
add()as well as theparam(...),params(...), andparamSource(...)methods fromBatchSpec.
entry(...) and entries(...) calls can be freely combined within the same batch.
client.sql("INSERT INTO user (first_name, last_name) VALUES (:firstName, :lastName)")
.batch()
.entry(entry -> entry.param("firstName", "Jane").param("lastName", "Smith"))
.entry(Map.of("firstName", "John", "lastName", "Doe"))
.update();
List<User> users = ...;
client.sql("INSERT INTO user (first_name, last_name) VALUES (:firstName, :lastName)")
.batch()
.entries(users)
.update();Related Issues
Reacted by JiΕΓ Krokviak
Metadata
Metadata
Assignees
Labels
in: dataIssues in data modules (jdbc, orm, oxm, tx)Issues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancementA general enhancement
Activity
Introduce entry-based DSL for JdbcClient batch updates
Document how to supply null values for JdbcClient batch entries