Class JdbcLogger

java.lang.Object
com.illumon.iris.export.jdbc.JdbcLogger
All Implemented Interfaces:
TableLoggerBase, AutoCloseable

public class JdbcLogger
extends Object
implements TableLoggerBase, AutoCloseable

A utility that logs Deephaven table snapshots and/or incremental updates to a JDBC table. It is expected that the target table is "compatible" with the source: JDBC metadata is interrogated to ensure the types of the source table columns match those of the corresponding target columns. Column names may be mapped, but any additional conversion must be performed in Deephaven prior to logging.

This logger may be used in two "modes". The default reproduces the content of the source table via a combination of SQL INSERT, UPDATE and DELETE statements (batched when possible). In "log mode", each incremental update to the source table is logged as an INSERT to the target table, along with (optional) information about which row was affected and the relevant operation (Added/Removed/Modified).

In addition, a number of different transaction modes may be used:

  • When "RowByRow" is specified, each logged row/operation is individually committed.
  • When "Atomic" is specified, each update to the source table is logged as an atomic operation - i.e. if an update affecting 100 rows is received by the table listener, these are committed as a unit.
The following modes only apply when logging snapshots:
  • When "Start" or "None" is specified, SQL operations are executed in the current transaction, but no commit is executed.
  • When "End" is specified, the final row of the snapshot is followed by a single commit operation.
The "Atomic" mode is recommended in most cases for optimal performance.
  • Method Details

    • close

      public void close()
      Closes this resource, relinquishing any underlying resources.
      Specified by:
      close in interface AutoCloseable
    • getLogHandle

      public TableLoggerBase.Handle getLogHandle​(Table tableToLog, Collection<String> keyColumns)
      Description copied from interface: TableLoggerBase
      Gets a handle suitable for use with logTableHandle. If you are repeatedly logging rows from a table, it is more efficient to check the definition once rather than on each log call.
      Specified by:
      getLogHandle in interface TableLoggerBase
      Parameters:
      tableToLog - the table to log, must conform to the definition used to create this logger
      keyColumns - if not null, gives the columns for which to log previous values on remove and row modification
      Returns:
      a handle that can be passed into logTableHandle, with dummy column sources for previous columns not specified
    • logTable

      public void logTable​(Table tableToLog, Index index, TableLoggerBase.Flags flags, boolean logUpdates, boolean logPrevValues, Collection<String> keyColumns)
      Log the contents of the given table to the JDBC. Optionally, continue to log updates as well. Any number of source tables may be logged to the same JDBC table, but only one may log updates at one time.
      Specified by:
      logTable in interface TableLoggerBase
      Parameters:
      tableToLog - table to log, must conform to the definition used to create this logger
      index - subset of the table to log
      flags - controls the transaction behavior
      logUpdates - if true, continue to log updates to the table
      logPrevValues - if true, log the old version of each row when rows are modified (only applicable when logUpdates is true)
      keyColumns - if specified, log only these columns when logging previous values. Make sure the target columns are nullable
    • stopLoggingUpdates

      public void stopLoggingUpdates()
      If we are presently logging updates, stop and remove the listener from the source table.
    • builder

      public static JdbcLogger.Builder builder​(com.fishlib.io.logger.Logger logger, String jdbcDriver, String jdbcUrl, String catalog, String schema, String tableName)
      Creates a JdbcLogger JdbcLogger.Builder.
      Parameters:
      logger - logger to use when initializing
      jdbcDriver - JDBC driver class name
      jdbcUrl - JDBC connection URL
      catalog - JDBC database catalog
      schema - JDBC database schema
      tableName - JDBC database table name
      Returns:
      JdbcLogger builder.
    • builder

      public static JdbcLogger.Builder builder​(com.fishlib.io.logger.Logger logger, String jdbcDriver, String jdbcUrl, String schema, String tableName)
      Creates a JdbcLogger JdbcLogger.Builder.
      Parameters:
      logger - logger to use when initializing
      jdbcDriver - JDBC driver class name
      jdbcUrl - JDBC connection URL
      schema - JDBC database schema
      tableName - JDBC database table name
      Returns:
      JdbcLogger builder.
    • builder

      public static JdbcLogger.Builder builder​(com.fishlib.io.logger.Logger logger, String jdbcDriver, String jdbcUrl, String tableName)
      Creates a JdbcLogger JdbcLogger.Builder.
      Parameters:
      logger - logger to use when initializing
      jdbcDriver - JDBC driver class name
      jdbcUrl - JDBC connection URL
      tableName - JDBC database table name
      Returns:
      JdbcLogger builder.