Class JdbcWriter


public class JdbcWriter extends DataWriter
Writes records to a database table.
  • Field Details

    • currentRecord

      protected Record currentRecord
  • Constructor Details

    • JdbcWriter

      public JdbcWriter(Connection connection, String tableName, IInsert insert)
      Creates a new instance with the autoCloseConnection property set to false.
      Parameters:
      connection -
      tableName -
      insert -
    • JdbcWriter

      public JdbcWriter(Connection connection, String tableName)
      Creates a new instance with the autoCloseConnection property set to false.
      Parameters:
      connection -
      tableName -
    • JdbcWriter

      public JdbcWriter(JdbcConnectionFactory factory, String tableName, IInsert insert)
      Creates a new instance with the autoCloseConnection property set to true.
      Parameters:
      factory -
      tableName -
      insert -
    • JdbcWriter

      public JdbcWriter(JdbcConnectionFactory factory, String tableName)
      Creates a new instance with the autoCloseConnection property set to true.
      Parameters:
      factory -
      tableName -
  • Method Details

    • getConnection

      public Connection getConnection()
    • getTableName

      public String getTableName()
    • getAutoCloseConnection

      public boolean getAutoCloseConnection()
      Indicates if the database connection in this endpoint should be closed when the endpoint is closed. The default is false if this instance was constructed with a Connection or true if constructed with a JdbcConnectionFactory.
    • setAutoCloseConnection

      public JdbcWriter setAutoCloseConnection(boolean closeConnection)
      Indicates if the database connection in this endpoint should be closed when the endpoint is closed. The default is false if this instance was constructed with a Connection or true if constructed with a JdbcConnectionFactory.
    • getBatchSize

      public int getBatchSize()
      Returns the number of records to chunk together in batch updates; 1 or less (the default is -1) disables batching.
    • setBatchSize

      public JdbcWriter setBatchSize(int batchSize)
      Sets the number of records to chunk together in batch updates. Updates are not batched if this value is 1 or less. JdbcWriter defaults to non batching updates.
    • isBatchMode

      public boolean isBatchMode()
      Indicates if updates are batched, i.e. the batch size is greater than 1.
    • isCommitBatch

      public boolean isCommitBatch()
      Indicates if this writer should call commit on the connection after every batch is sent, otherwise, commit is called after the final batch update (default is false).
    • setCommitBatch

      public JdbcWriter setCommitBatch(boolean commitBatch)
      Indicates if this writer should call commit on the connection after every batch is sent, otherwise, commit is called after the final batch update (default is false).
    • setDescription

      public JdbcWriter setDescription(String description)
      Description copied from class: Endpoint
      Sets the optional text shown for this endpoint in Endpoint.toString() and exception properties.
      Overrides:
      setDescription in class Endpoint
    • getInsert

      public IInsert getInsert()
    • setJdbcType

      public JdbcWriter setJdbcType(String fieldName, int jdbcType)
      Forces the specified field's values to be sent to the database using PreparedStatement.setObject(parameterIndex, fieldValue, jdbcType) (instead of the appropriate PreparedStatement.setXXX() method for its field's type). This method may be used to pass database-specific abstract data types.
      Parameters:
      fieldName - the field to override.
      jdbcType - one of the Types constants or a database specific value.
    • getJdbcType

      public Integer getJdbcType(String fieldName)
      The Types constant (or a database specific value) assigned to the specified field using setJdbcType(String, int) or null if none was set.
      Returns:
      one of the Types constants or a database specific value.
    • setJdbcType

      public JdbcWriter setJdbcType(Class<?> type, int jdbcType)
      Forces field values of the specified Java class type to be sent to the database using PreparedStatement.setObject(parameterIndex, fieldValue, jdbcType) (instead of the appropriate PreparedStatement.setXXX() method for its field's type). This method may be used to pass database-specific abstract data types.
      Parameters:
      type - the Java class type to override.
      jdbcType - one of the Types constants or a database specific value.
    • getJdbcType

      public Integer getJdbcType(Class<?> type)
      The Types constant (or a database specific value) assigned to the specified Java class type using setJdbcType(Class, int) or null if none was set.
      Returns:
      one of the Types constants or a database specific value.
    • isDebug

      public boolean isDebug()
      Indicates if the generated SQL should be logged (default false).
    • setDebug

      public JdbcWriter setDebug(boolean debug)
      Indicates if the generated SQL should be logged (default false).
    • 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 DataWriter
    • setParameterValue

      public void setParameterValue(Field field, PreparedStatement statement, int parameterIndex) throws SQLException
      Sets the 1-based statement parameter from the field, honoring any JDBC type assigned with setJdbcType.
      Throws:
      SQLException
    • write

      public void write(Record record) throws DataException
      Description copied from class: DataWriter
      Writes the specified record to this DataWriter and increases the record-count by 1. Any exception raised while writing will be converted to a DataException using DataObject.exception(Throwable).

      Subclasses generally do not need to override this method, instead they should implement DataWriter.writeImpl(Record).

      Overrides:
      write in class DataWriter
      Throws:
      DataException
    • writeImpl

      protected void writeImpl(Record record) throws Throwable
      Description copied from class: DataWriter
      Overridden by subclasses to write the specified record to this DataWriter.

      Contract for subclasses (see also docs/authoring/DataWriter.md):

      Specified by:
      writeImpl in class DataWriter
      Throws:
      Throwable
    • open

      public void open()
      Description copied from class: DataEndpoint
      Makes this endpoint ready for reading or writing.
      Overrides:
      open in class DataEndpoint
    • close

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