Class MultiRowStatementInsert

java.lang.Object
com.northconcepts.datapipeline.core.DataObject
com.northconcepts.datapipeline.jdbc.insert.MultiRowStatementInsert
All Implemented Interfaces:
IInsert, Cloneable
Direct Known Subclasses:
OracleMultiRowStatementInsert

public class MultiRowStatementInsert extends DataObject implements IInsert

Sample Generated SQL:
INSERT INTO tableName (col1, col2, col3) VALUES
(val1, val2, val3),
(val1, val2, val3),
(val1, val2, val3),..

  • Field Details

  • Constructor Details

    • MultiRowStatementInsert

      public MultiRowStatementInsert()
  • Method Details

    • isDebug

      public boolean isDebug()
      Description copied from interface: IInsert
      Indicates if the generated SQL should be logged (default false).
      Specified by:
      isDebug in interface IInsert
    • setDebug

      public MultiRowStatementInsert setDebug(boolean debug)
      Description copied from interface: IInsert
      Set to true to log generated SQL (default false).
      Specified by:
      setDebug in interface IInsert
    • prepare

      public void prepare(JdbcWriter writer, Record record) throws Throwable
      Description copied from interface: IInsert
      Called once, with the first record written, to generate the SQL and create the statement(s).
      Specified by:
      prepare in interface IInsert
      Throws:
      Throwable
    • setValues

      public void setValues(JdbcWriter writer, Record record) throws Throwable
      Description copied from interface: IInsert
      Applies the record's values to the pending statement; called for every record written.
      Specified by:
      setValues in interface IInsert
      Throws:
      Throwable
    • getSqlValueLiteral

      protected String getSqlValueLiteral(Field field)
      Returns the field's value as a SQL literal (null for null fields), delegating to the literal method for its type.
    • getStringLiteral

      protected String getStringLiteral(String value)
      Returns the value in single quotes with embedded single quotes doubled; also used for UUID, CHAR and any field type without its own literal method.
    • getIntLiteral

      protected String getIntLiteral(int value)
    • getLongLiteral

      protected String getLongLiteral(long value)
    • getDoubleLiteral

      protected String getDoubleLiteral(double value)
    • getBigIntegerLiteral

      protected String getBigIntegerLiteral(BigInteger value)
    • getBigDecimalLiteral

      protected String getBigDecimalLiteral(BigDecimal value)
    • getDateTimeLiteral

      protected String getDateTimeLiteral(Date value)
      Returns the value as a JDBC timestamp escape, {ts 'yyyy-MM-dd HH:mm:ss.SSS'}.
    • getBooleanLiteral

      protected String getBooleanLiteral(boolean value)
      Returns TRUE or FALSE.
    • getByteLiteral

      protected String getByteLiteral(byte value)
    • getFloatLiteral

      protected String getFloatLiteral(float value)
    • getShortLiteral

      protected String getShortLiteral(short value)
    • getDateLiteral

      protected String getDateLiteral(Date value)
      Returns the value as a JDBC date escape, {d 'yyyy-MM-dd'}.
    • getTimeLiteral

      protected String getTimeLiteral(Time value)
      Returns the value as a JDBC time escape, {t 'HH:mm:ss.SSS'}.
    • getBytesLiteral

      protected String getBytesLiteral(byte[] value)
    • executeUpdate

      public void executeUpdate() throws Throwable
      Description copied from interface: IInsert
      Executes the statement with the values applied; called after each record when the writer is not batching.
      Specified by:
      executeUpdate in interface IInsert
      Throws:
      Throwable
    • getInsertSqlPrefix

      protected String getInsertSqlPrefix()
      Returns the SQL that precedes the rows of values; the SQL buffer is truncated back to its length after each execution.
    • setInsertSqlPrefix

      protected MultiRowStatementInsert setInsertSqlPrefix(String insertSqlPrefix)
      Sets the SQL that precedes the rows of values; the SQL buffer is truncated back to its length after each execution.
    • getInsertSql

      protected StringBuilder getInsertSql()
      Returns the SQL buffer holding the prefix followed by the rows of values not yet executed.
    • getInsertStatement

      protected Statement getInsertStatement()
    • setInsertStatement

      protected MultiRowStatementInsert setInsertStatement(Statement insertStatement)
    • getRecordsPendingInsert

      protected int getRecordsPendingInsert()
    • setRecordsPendingInsert

      protected MultiRowStatementInsert setRecordsPendingInsert(int recordsPendingInsert)
    • isBatchSupported

      public boolean isBatchSupported()
      Description copied from interface: IInsert
      Returns true if IInsert.addBatch() and IInsert.executeBatch() are supported; otherwise JdbcWriter.setBatchSize(int) rejects batch sizes above 1.
      Specified by:
      isBatchSupported in interface IInsert
    • addBatch

      public void addBatch() throws Throwable
      Description copied from interface: IInsert
      Adds the applied values to the batch; called instead of IInsert.executeUpdate() when the writer is batching.
      Specified by:
      addBatch in interface IInsert
      Throws:
      Throwable
    • executeBatch

      public void executeBatch() throws Throwable
      Description copied from interface: IInsert
      Executes the batch; called each time the writer's batch size is reached and on close if records remain.
      Specified by:
      executeBatch in interface IInsert
      Throws:
      Throwable
    • close

      public void close() throws Throwable
      Description copied from interface: IInsert
      Releases the statement(s); called when the writer is closed.
      Specified by:
      close in interface IInsert
      Throws:
      Throwable
    • clone

      public MultiRowStatementInsert clone()
      Description copied from interface: IInsert
      Returns a new, unprepared copy with the same settings; JdbcMultiWriter uses one for each connection.
      Specified by:
      clone in interface IInsert
      Overrides:
      clone in class Object
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: DataObject
      Adds this object'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.
      Specified by:
      addExceptionProperties in interface IInsert
      Overrides:
      addExceptionProperties in class DataObject