java.lang.Object
org.seasar.doma.jdbc.builder.BatchUpdateExecutor
An executor that execute SQL UPDATE statements in batches.
This is not thread safe.
Java
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);
});
built SQLs
update Emp set name = 'SMITH', salary = 1000 where id = 10 update Emp set name = 'ALLEN', salary = 2000 where id = 20
-
Method Summary
Modifier and TypeMethodDescriptionvoidbatchSize(int batchSize) Sets the batch size.voidcallerClassName(String className) Sets the caller class name.voidcallerMethodName(String methodName) Sets the caller method name.<P> int[]execute(Iterable<P> params, BiConsumer<P, BatchBuilder> buildConsumer) Executes SQL UPDATE statements.getSqls()Returns the built SQL.static BatchUpdateExecutornewInstance(Config config) Creates a new instance.voidqueryTimeout(int queryTimeout) Sets the query timeout limit in seconds.voidsqlLogType(SqlLogType sqlLogType) Sets the SQL log format.
-
Method Details
-
newInstance
Creates a new instance.- Parameters:
config- the configuration- Returns:
- a executor
- Throws:
DomaNullPointerException- ifconfigisnull
-
queryTimeout
public void queryTimeout(int queryTimeout) Sets the query timeout limit in seconds.If not specified, the value of
Config.getQueryTimeout()is used.- Parameters:
queryTimeout- the query timeout limit in seconds- See Also:
-
sqlLogType
Sets the SQL log format.- Parameters:
sqlLogType- the SQL log format type
-
batchSize
public void batchSize(int batchSize) Sets the batch size.If not specified, the value of
Config.getBatchSize()is used.- Parameters:
batchSize- the batch size
-
callerClassName
Sets the caller class name.If not specified, the class name of this instance is used.
- Parameters:
className- the caller class name- Throws:
DomaNullPointerException- ifclassNameisnull
-
callerMethodName
Sets the caller method name.if not specified,
executeis used.- Parameters:
methodName- the caller method name- Throws:
DomaNullPointerException- ifmethodNameisnull
-
execute
Executes SQL UPDATE statements.- Type Parameters:
P- the parameter type- Parameters:
params- the parametersbuildConsumer- the code block that builds SQL statements- Returns:
- the array whose each element contains affected rows count. The array length is equal to
the
parametersize. - Throws:
DomaNullPointerException- ifparamsorbuildConsumerisnullUniqueConstraintException- if an unique constraint violation occursJdbcException- if a JDBC related error occurs
-
getSqls
Returns the built SQL.- Returns:
- the built SQL
-