Class MySqlUpsertWriter


public class MySqlUpsertWriter extends MySqlInsertWriter
Generates MySQL upsert statement from records.
  • Constructor Details

    • MySqlUpsertWriter

      public MySqlUpsertWriter(String table, File file, boolean append)
    • MySqlUpsertWriter

      public MySqlUpsertWriter(String table, File file)
    • MySqlUpsertWriter

      public MySqlUpsertWriter(String table, Writer writer)
  • 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.
      Overrides:
      writeRecord in class MySqlInsertWriter
      Throws:
      Throwable
    • close

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

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

      Example output (pretty = true):
      INSERT INTO `tableName` (`col1`, `col2`)
      VALUES (val1, val2),
             (val1, val2),
             (val1, val2)
      ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);

      Example output (pretty = false):
      INSERT INTO `tableName` (`col1`, `col2`) VALUES (val1, val2), (val1, val2), (val1, val2) ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);
      Overrides:
      setPretty in class MySqlInsertWriter
    • setBatchSize

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

      Example output (batchSize = 2):
      INSERT INTO `tableName` (`col1`, `col2`)
      VALUES (val1, val2),
             (val1, val2,
             (val1, val2)
      ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);
      Example output (batchSize = 0):
      INSERT INTO `tableName` (`col1`, `col2`) VALUES (val1, val2) ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);
      INSERT INTO `tableName` (`col1`, `col2`) VALUES (val1, val2) ON DUPLICATE KEY UPDATE `col1` = VALUES(`col1`), `col2` = VALUES(`col2`);
      Overrides:
      setBatchSize in class MySqlInsertWriter