java.lang.Object
org.seasar.doma.jdbc.builder.MapBatchInsertBuilder
A builder that builds SQL INSERT statements from maps for a batch execution.
This is not thread safe.
Java
MapBatchInsertBuilder builder = MapBatchInsertBuilder.newInstance(config, "Emp");
builder.batchSize(10);
builder.execute(new ArrayList<Map<String, Object>>() {
{
add(new LinkedHashMap<String, Object>() {
{
put("name", "SMITH");
put("salary", 1000);
}
});
add(new LinkedHashMap<String, Object>() {
{
put("name", "ALLEN");
put("salary", 2000);
}
});
}
});
built SQLs
insert into Emp
(name, salary)
values('SMITH', 1000)
insert into Emp
(name, salary)
values('ALLEN', 2000)
-
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.int[]Executes SQL INSERT statements.getSqls()Returns the built SQL.static MapBatchInsertBuildernewInstance(Config config, String tableName) 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 configurationtableName- the table name- Returns:
- a builder
- Throws:
DomaNullPointerException- ifconfigortableNameisnull
-
execute
Executes SQL INSERT statements.- Parameters:
parameter- the parameter- Returns:
- the array whose each element contains affected rows count. The array length is equal to
the
parametersize. - Throws:
DomaNullPointerException- ifparameterisnullDomaIllegalArgumentException- ifparameteris emptyUniqueConstraintException- if an unique constraint violation occursJdbcException- if a JDBC related error occurs
-
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
-
getSqls
Returns the built SQL.- Returns:
- the built SQL
-