Class 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.
- 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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JdbcLogger.Builder
A builder for constructing a JdbcLogger.Nested classes/interfaces inherited from interface com.illumon.iris.db.tables.dataimport.TableLoggerBase
TableLoggerBase.Flags, TableLoggerBase.Handle, TableLoggerBase.Operation
-
Field Summary
Fields inherited from interface com.illumon.iris.db.tables.dataimport.TableLoggerBase
DEFAULT_TABLELOGGER_FLAGS
-
Method Summary
Modifier and Type Method Description static JdbcLogger.Builder
builder(com.fishlib.io.logger.Logger logger, String jdbcDriver, String jdbcUrl, String tableName)
Creates a JdbcLoggerJdbcLogger.Builder
.static JdbcLogger.Builder
builder(com.fishlib.io.logger.Logger logger, String jdbcDriver, String jdbcUrl, String schema, String tableName)
Creates a JdbcLoggerJdbcLogger.Builder
.static JdbcLogger.Builder
builder(com.fishlib.io.logger.Logger logger, String jdbcDriver, String jdbcUrl, String catalog, String schema, String tableName)
Creates a JdbcLoggerJdbcLogger.Builder
.void
close()
Closes this resource, relinquishing any underlying resources.TableLoggerBase.Handle
getLogHandle(Table tableToLog, Collection<String> keyColumns)
Gets a handle suitable for use with logTableHandle.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.void
stopLoggingUpdates()
If we are presently logging updates, stop and remove the listener from the source table.
-
Method Details
-
close
public void close()Closes this resource, relinquishing any underlying resources.- Specified by:
close
in interfaceAutoCloseable
-
getLogHandle
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 interfaceTableLoggerBase
- Parameters:
tableToLog
- the table to log, must conform to the definition used to create this loggerkeyColumns
- 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 interfaceTableLoggerBase
- Parameters:
tableToLog
- table to log, must conform to the definition used to create this loggerindex
- subset of the table to logflags
- controls the transaction behaviorlogUpdates
- if true, continue to log updates to the tablelogPrevValues
- 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 JdbcLoggerJdbcLogger.Builder
.- Parameters:
logger
- logger to use when initializingjdbcDriver
- JDBC driver class namejdbcUrl
- JDBC connection URLcatalog
- JDBC database catalogschema
- JDBC database schematableName
- 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 JdbcLoggerJdbcLogger.Builder
.- Parameters:
logger
- logger to use when initializingjdbcDriver
- JDBC driver class namejdbcUrl
- JDBC connection URLschema
- JDBC database schematableName
- 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 JdbcLoggerJdbcLogger.Builder
.- Parameters:
logger
- logger to use when initializingjdbcDriver
- JDBC driver class namejdbcUrl
- JDBC connection URLtableName
- JDBC database table name- Returns:
- JdbcLogger builder.
-