Module org.itsallcode.jdbc
Package org.itsallcode.jdbc.batch
Class RowPreparedStatementBatchBuilder<T>
java.lang.Object
org.itsallcode.jdbc.batch.RowPreparedStatementBatchBuilder<T>
- Type Parameters:
T
- row type
Builder for
PreparedStatement
batch jobs for a Stream
or
Iterable
of row objects using e.g. INSERT
or UPDATE
statements.
Create a new instance using
DbOperations.preparedStatementBatch(Class)
.
-
Constructor Summary
ConstructorsConstructorDescriptionRowPreparedStatementBatchBuilder
(Function<String, SimplePreparedStatement> statementFactory) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionDefine table and column names used for generating theINSERT
statement.into
(Identifier tableName, List<Identifier> columnNames) Define table and column names used for generating theINSERT
statement.mapping
(ParamConverter<T> rowMapper) Define mapping how rows are converted toObject[]
for inserting.mapping
(RowPreparedStatementSetter<T> preparedStatementSetter) DefineRowPreparedStatementSetter
that sets values of aPreparedStatement
for each row.maxBatchSize
(int maxBatchSize) Define maximum batch size, usingPreparedStatementBatchBuilder.DEFAULT_MAX_BATCH_SIZE
as default.DefineIterator
of rows to insert.DefineStream
of rows to insert.Define the SQL statement to be used for the batch job, e.g.void
start()
Start the batch insert process using the given rows.
-
Constructor Details
-
RowPreparedStatementBatchBuilder
Create a new instance.- Parameters:
statementFactory
- factory for creatingSimplePreparedStatement
-
-
Method Details
-
sql
Define the SQL statement to be used for the batch job, e.g.INSERT
orUPDATE
.- Parameters:
sql
- SQL statement- Returns:
this
for fluent programming
-
into
Define table and column names used for generating theINSERT
statement.- Parameters:
tableName
- table namecolumnNames
- column names- Returns:
this
for fluent programming
-
into
Define table and column names used for generating theINSERT
statement.- Parameters:
tableName
- table namecolumnNames
- column names- Returns:
this
for fluent programming
-
rows
DefineStream
of rows to insert.- Parameters:
rows
- rows to insert- Returns:
this
for fluent programming
-
rows
DefineIterator
of rows to insert.- Parameters:
rows
- rows to insert- Returns:
this
for fluent programming
-
mapping
Define mapping how rows are converted toObject[]
for inserting.- Parameters:
rowMapper
- row mapper- Returns:
this
for fluent programming
-
mapping
public RowPreparedStatementBatchBuilder<T> mapping(RowPreparedStatementSetter<T> preparedStatementSetter) DefineRowPreparedStatementSetter
that sets values of aPreparedStatement
for each row.- Parameters:
preparedStatementSetter
- prepared statement setter- Returns:
this
for fluent programming
-
maxBatchSize
Define maximum batch size, usingPreparedStatementBatchBuilder.DEFAULT_MAX_BATCH_SIZE
as default.- Parameters:
maxBatchSize
- maximum batch size- Returns:
this
for fluent programming
-
start
Start the batch insert process using the given rows.
-