public class BatchUpdateExecutor
extends java.lang.Object
This is not thread safe.
List<Employee> employees = Arrays
.asList(new Employee[] { new Employee(10, "SMITH", new BigDecimal("1000")),
new Employee(20, "ALLEN", new BigDecimal("2000")) });
BatchUpdateExecutor executor = BatchUpdateExecutor.newInstance(config);
executor.batchSize(10);
executor.execute(employees, (emp, builder) -> {
builder.sql("update Emp");
builder.sql("set");
builder.sql("name = ").param(String.class, emp.name).sql(",");
builder.sql("salary = ").param(BigDecimal.class, emp.salary);
builder.sql("where");
builder.sql("id = ").param(int.class, emp.id);
});
update Emp set name = 'SMITH', salary = 1000 where id = 10 update Emp set name = 'ALLEN', salary = 2000 where id = 20
| Modifier and Type | Method and Description |
|---|---|
void |
batchSize(int batchSize)
Sets the batch size.
|
void |
callerClassName(java.lang.String className)
Sets the caller class name.
|
void |
callerMethodName(java.lang.String methodName)
Sets the caller method name.
|
<P> int[] |
execute(java.lang.Iterable<P> params,
java.util.function.BiConsumer<P,BatchBuilder> buildConsumer)
Executes SQL UPDATE statements.
|
java.util.List<? extends Sql<?>> |
getSqls()
Returns the built SQL.
|
static BatchUpdateExecutor |
newInstance(Config config)
Creates a new instance.
|
void |
queryTimeout(int queryTimeout)
Sets the query timeout limit in seconds.
|
void |
sqlLogType(SqlLogType sqlLogType)
Sets the SQL log format.
|
public static BatchUpdateExecutor newInstance(Config config)
config - the configurationDomaNullPointerException - if config is nullpublic void queryTimeout(int queryTimeout)
If not specified, the value of Config.getQueryTimeout() is used.
queryTimeout - the query timeout limit in secondsStatement.setQueryTimeout(int)public void sqlLogType(SqlLogType sqlLogType)
sqlLogType - the SQL log format typepublic void batchSize(int batchSize)
If not specified, the value of Config.getBatchSize() is used.
batchSize - the batch sizepublic void callerClassName(java.lang.String className)
If not specified, the class name of this instance is used.
className - the caller class nameDomaNullPointerException - if className is nullpublic void callerMethodName(java.lang.String methodName)
if not specified, execute is used.
methodName - the caller method nameDomaNullPointerException - if methodName is nullpublic <P> int[] execute(java.lang.Iterable<P> params,
java.util.function.BiConsumer<P,BatchBuilder> buildConsumer)
P - the parameter typeparams - the parametersbuildConsumer - the code block that builds SQL statementsparameter size.DomaNullPointerException - if params or buildConsumer is nullUniqueConstraintException - if an unique constraint violation occursJdbcException - if a JDBC related error occurspublic java.util.List<? extends Sql<?>> getSqls()