Class H2InsertWriter


public class H2InsertWriter extends TextWriter
Generates H2 insert statement from records.
  • Field Details

    • pretty

      protected boolean pretty
    • batchSize

      protected int batchSize
    • batchedInserts

      protected int batchedInserts
    • tableName

      protected final String tableName
  • Constructor Details

    • H2InsertWriter

      public H2InsertWriter(String tableName, File file, boolean append)
      Constructs an H2InsertWriter for the specified table, file, and append mode.
      Parameters:
      tableName - the name of the table
      file - the file to write to
      append - true to append to existing file
    • H2InsertWriter

      public H2InsertWriter(String tableName, File file)
      Constructs an H2InsertWriter for the specified table and file.
      Parameters:
      tableName - the name of the table
      file - the file to write to
    • H2InsertWriter

      public H2InsertWriter(String tableName, Writer writer)
      Constructs an H2InsertWriter for the specified table and writer.
      Parameters:
      tableName - the name of the table
      writer - the writer to write to
  • Method Details

    • writeRecord

      protected void writeRecord(Record record) throws Throwable
      Description copied from class: AbstractWriter
      Writes one row; called first for the header row (see AbstractWriter.isHeaderRow()) when field names are written, then for each record.
      Specified by:
      writeRecord in class AbstractWriter
      Throws:
      Throwable
    • close

      public void close()
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class TextWriter
    • getTableName

      public String getTableName()
      Returns the table name.
      Returns:
      the table name
    • isPretty

      public boolean isPretty()
      Returns whether pretty formatting is enabled.
      Returns:
      true if pretty formatting is enabled
    • setPretty

      public H2InsertWriter 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),...
    • getBatchSize

      public int getBatchSize()
      Returns the batch size.
      Returns:
      the batch size
    • setBatchSize

      public H2InsertWriter setBatchSize(int batchSize)
      Sets the number of records to chunk together in batch inserts. Inserts are not batched if this value is 1 or less. H2InsertWriter defaults to non batching inserts.

      Example output (batchSize = 2):
      INSERT INTO `tableName` (`col1`, `col2`, `col3`)
      VALUES (val1, val2, val3),
             (val1, val2, val3);

      Example output (batchSize = 0):
      INSERT INTO `tableName` (`col1`, `col2`, `col3`) VALUES (val1, val2, val3);
      INSERT INTO `tableName` (`col1`, `col2`, `col3`) VALUES (val1, val2, val3);
    • isBatchMode

      public boolean isBatchMode()
      Returns whether batch mode is enabled.
      Returns:
      true if batch mode is enabled
    • setFieldNamesInFirstRow

      public H2InsertWriter setFieldNamesInFirstRow(boolean fieldNamesInFirstRow)
      Description copied from class: AbstractWriter
      Indicates if a header row of field names is written before the first record (default is true); must be called before AbstractWriter.open().
      Overrides:
      setFieldNamesInFirstRow in class AbstractWriter
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Endpoint
      Adds this endpoint's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Overrides:
      addExceptionProperties in class TextWriter
    • getSqlValueLiteral

      protected String getSqlValueLiteral(Field field)
      Returns the SQL literal written for a field's value: null, a quoted string, a number, TRUE/FALSE, a JDBC escape such as {d '...'} for dates and times, a JSON string for records, or X'...' for blobs.