public class Insert extends H2SqlPart

Generates an INSERT INTO statement for H2.


Sample Generated SQL:

INSERT INTO `tableName` (`col1`, `col2`, `col3`)
VALUES (val1, val2, val3),
       (val1, val2, val3),
       (val1, val2, val3),...
  • Constructor Details

    • Insert

      public Insert(String table)
      Constructs an Insert for the specified table.
      Parameters:
      table - the table name
  • Method Details

    • setPretty

      public Insert setPretty(boolean pretty)
      Indicates if line breaks and indentations should be added to output insert statement (default false).

      Example output (pretty = true):
      INSERT INTO `tableName` (`col1`, `col2`, `col3`)
      VALUES (val1, val2, val3),
             (val1, val2, val3),
             (val1, val2, val3),...

      Example output (pretty = false):
      INSERT INTO `tableName` (`col1`, `col2`, `col3`) VALUES (val1, val2, val3), (val1, val2, val3), (val1, val2, val3),...
      Overrides:
      setPretty in class SqlPart
    • getTable

      public String getTable()
      Returns the table name.
      Returns:
      the table name
    • nextRow

      public Insert nextRow()
      Starts a new row for inserting.
      Returns:
      this instance
    • add

      public Insert add(String columnName, Object value)
      Adds a column-value pair to the current row.
      Parameters:
      columnName - the column name
      value - the value to insert
      Returns:
      this instance
    • getRows

      public List<InsertRow> getRows()
      Returns the list of rows.
      Returns:
      the list of rows
    • getLastRow

      public InsertRow getLastRow()
      Returns the last row.
      Returns:
      the last row
    • collectSqlFragment

      public void collectSqlFragment(CodeWriter writer)
      Description copied from class: SqlPart
      Writes this part's SQL to the writer; used by SqlPart.getSqlFragment() and by enclosing parts.
      Specified by:
      collectSqlFragment in class SqlPart