Class MapBatchInsertBuilder

java.lang.Object
org.seasar.doma.jdbc.builder.MapBatchInsertBuilder

public class MapBatchInsertBuilder extends Object
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 Details

    • newInstance

      public static MapBatchInsertBuilder newInstance(Config config, String tableName)
      Creates a new instance.
      Parameters:
      config - the configuration
      tableName - the table name
      Returns:
      a builder
      Throws:
      DomaNullPointerException - if config or tableName is null
    • execute

      public int[] execute(Iterable<? extends Map<String,Object>> parameter)
      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 parameter size.
      Throws:
      DomaNullPointerException - if parameter is null
      DomaIllegalArgumentException - if parameter is empty
      UniqueConstraintException - if an unique constraint violation occurs
      JdbcException - 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

      public void sqlLogType(SqlLogType 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

      public void callerClassName(String className)
      Sets the caller class name.

      If not specified, the class name of this instance is used.

      Parameters:
      className - the caller class name
      Throws:
      DomaNullPointerException - if className is null
    • callerMethodName

      public void callerMethodName(String methodName)
      Sets the caller method name.

      if not specified, execute is used.

      Parameters:
      methodName - the caller method name
      Throws:
      DomaNullPointerException - if methodName is null
    • getSqls

      public List<? extends Sql<?>> getSqls()
      Returns the built SQL.
      Returns:
      the built SQL