com.ibm.di.connector
Class DBChangelogConnector

java.lang.Object
  extended by com.ibm.di.connector.Connector
      extended by com.ibm.di.connector.JDBCConnector
          extended by com.ibm.di.connector.DBChangelogConnector
All Implemented Interfaces:
ChangelogInterface, ConnectorInterface, SkipLookupInterface, VersionInfoInterface

public class DBChangelogConnector
extends JDBCConnector
implements ConnectorInterface, ChangelogInterface

The DBChangelogConnector provides a way to to detect changes in specific RDBMS tables. The Connector connects to the underline database through JDBC driver and creates Entries from specific 'change table' containing one record per modified record in the target table.

The Connector regularly saves current state into the System Store to avoid duplications when retrieving Entries. Records can also be deleted after the retrieving.


Field Summary
 
Fields inherited from class com.ibm.di.connector.Connector
ALL_MODES, myLog, PROPERTY_MESSAGE, PROPERTY_READER, PROPERTY_WRITER
 
Fields inherited from interface com.ibm.di.connector.ChangelogInterface
CONN_PARAM_STATE_KEY_PERSISTENCE, PARAM_MERGE_BOTH_NOT_MERGED, PARAM_MERGE_CHANGELOG_AND_DATA, PARAM_MERGE_ONLY_CHANGED_DATA, PARAM_VAL_AFTER_READ, PARAM_VAL_END_OF_CYCLE, PARAM_VAL_MANUAL, SAVE_STATE_AFTER_READ, SAVE_STATE_END_OF_CYCLE, SAVE_STATE_MANUAL
 
Constructor Summary
DBChangelogConnector()
          Constructor for the DBChangelogConnector object.
 
Method Summary
 String ctString(Object ct)
          Converts the Object to String.
 boolean doWait()
          This method sleeps for a number of seconds specified by the 'Sleep Interval' parameter.
 Entry getNextEntry()
          Gets the next Entry object from the 'change table'.
static int getNumberOfRecords(String tableName, Connection con)
          This method extracts the number of records in the changelog table.
 Object getStateKeyObject()
          This method returns the StateKey used as our Change Detection number.
 int getStateKeySaveMethod()
          Retrieves the method for storing StateKey.
 String getVersion()
          Version information.
 void initialize(Object o)
          Reads Connector parameter's values and initialize the Connector.
 void removeProcessedRows()
          Removes processed rows from the 'change table'.
 void reselect()
          Retrieves records from the 'change table' using the current value of the StateKey.
 void saveStateKey()
          Stores the USN values for the next synchronization.
 void selectEntries()
          This method prepares the Connector for a sequential read.
 String toHex(int n)
          Converts integer to Hex String.
 
Methods inherited from class com.ibm.di.connector.JDBCConnector
alterSession, commit, deleteEntry, execSQL, execSQLSelect, findEntry, getConnection, getNextSQLSelectEntry, getNumSkipLookupAffected, getParameterSubstitution, getPreparedString, getStatement, getSubClause, getWhereClause, isDeltaSupported, isEOCflag, isInsertPaddingDisabled, isIOException, isLookupPaddingDisabled, isUpdatePaddingDisabled, modEntry, putEntry, querySchema, queryTables, rollback, saveMetaData, setCommitMode, setCurrent, setEOCflag, setPaddingInInsert, setPaddingInLookup, setPaddingInUpdate, setParameterSubstitution, setPreparedDeleteStatement, setPreparedFindStatement, setPreparedInsertStatement, setPreparedModifyStatement, setPreparedSelectStatement, setResultSet, setSessionParameters, sqlValue, terminate
 
Methods inherited from class com.ibm.di.connector.Connector
addFindEntry, allModes, clearFindEntries, debug, debugMode, findEntry, getBoolean, getClassInstance, getConfiguration, getContext, getFindEntryCount, getFirstFindEntry, getLog, getMaxDuplicateEntries, getModes, getModes, getName, getNextClient, getNextFindEntry, getParam, getParser, getProperty, getPushbackEntry, getRawConnectorConfiguration, getRSInterface, getUI, hasConfigValue, hasParser, initParser, isExceptionFatal, logError, logmsg, modEntry, pushback, queryOperations, queryReply, reconnect, reconnect, registerScriptBeans, replyEntry, setConfiguration, setContext, setDebugMode, setLog, setMaxDuplicateEntries, setModes, setModes, setName, setParam, setParser, setProperty, setRSInterface, terminateServer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.ibm.di.connector.ConnectorInterface
deleteEntry, findEntry, getConfiguration, getContext, getFindEntryCount, getFirstFindEntry, getMaxDuplicateEntries, getName, getNextClient, getNextFindEntry, getParam, getPushbackEntry, getRawConnectorConfiguration, isDeltaSupported, isExceptionFatal, isIOException, modEntry, modEntry, pushback, putEntry, queryOperations, queryReply, querySchema, reconnect, registerScriptBeans, replyEntry, setConfiguration, setContext, setCurrent, setLog, setMaxDuplicateEntries, setName, setParam, setRSInterface, terminate, terminateServer
 

Constructor Detail

DBChangelogConnector

public DBChangelogConnector()
Constructor for the DBChangelogConnector object.

Method Detail

initialize

public void initialize(Object o)
                throws Exception
Reads Connector parameter's values and initialize the Connector.

Specified by:
initialize in interface ConnectorInterface
Overrides:
initialize in class JDBCConnector
Parameters:
o - Socket object, ConnectorMode object or null
Throws:
Exception - If invalid Connector parameter values are supplied.

selectEntries

public void selectEntries()
                   throws Exception
This method prepares the Connector for a sequential read. Retrieves records from 'change table'.

Specified by:
selectEntries in interface ConnectorInterface
Overrides:
selectEntries in class JDBCConnector
Throws:
Exception - If an error occurs while selecting Entries
See Also:
JDBCConnector.getNextEntry()

reselect

public void reselect()
              throws Exception
Retrieves records from the 'change table' using the current value of the StateKey. If StateKey is:
  • null and 'Remove Processed Row' parameter is true - the processed rows are deleted from the 'change table'

  • null and 'Remove Processed Row' parameter is false - all entries are retrieved

  • not null - only entries with ibmsnap_commitseq > StateKey are retrieved
  • Throws:
    Exception - If an error occurs while retrieving records from the database

    removeProcessedRows

    public void removeProcessedRows()
                             throws Exception
    Removes processed rows from the 'change table'. This method deletes all rows with ibmsnap_commitseq <= StateKey. These rows are actually already returned as entries by the getNextEntry() function.

    This method is called from the reselect() method only if the parameter 'Removed Processed Rows' is set to true.

    Throws:
    Exception - If the Connector can not delete processed rows in the database

    ctString

    public String ctString(Object ct)
    Converts the Object to String.

    Example:
    By using this method you can print the values of the IBMSNAP_COMMITSEQ and IBMSNAP_INTENTSEQ properties of the read entry.

     var csn = conn.getProperty("IBMSNAP_COMMITSEQ");
     task.logmsg("IBMSNAP_COMMITSEQ: "+RDBMS.connector.ctString(csn);
     
     var isn = conn.getProperty("IBMSNAP_INTENTSEQ");
     task.logmsg("IBMSNAP_INTENTSEQ: "+RDBMS.connector.ctString(isn);
     

    Parameters:
    ct - the Object that need to be converted
    Returns:
    the converted String

    toHex

    public String toHex(int n)
    Converts integer to Hex String.

    Parameters:
    n - the integer that need to be converted to Hex String
    Returns:
    the converted String

    getNextEntry

    public Entry getNextEntry()
                       throws Exception
    Gets the next Entry object from the 'change table'.

    Specified by:
    getNextEntry in interface ConnectorInterface
    Overrides:
    getNextEntry in class JDBCConnector
    Returns:
    The next Entry
    Throws:
    Exception - If retrieving the next Entry fails.
    See Also:
    ConnectorInterface.selectEntries()

    doWait

    public boolean doWait()
                   throws Exception
    This method sleeps for a number of seconds specified by the 'Sleep Interval' parameter.

    It is called by the getNextEntry() method after an entry is retrieved from the 'change table' to make the connector sleep for a specified interval of time before polling for next entry. If no new entries are added to the 'change table' for a timeout value the getNextEntry() method will return null.

    Returns:
    boolean flag, if true everything is fine, if false maxWait > 0 and (lastWait - firstWait) > maxWait
    Throws:
    Exception - if an error occurs during sleeping.

    getStateKeySaveMethod

    public int getStateKeySaveMethod()
                              throws Exception
    Retrieves the method for storing StateKey.

    Specified by:
    getStateKeySaveMethod in interface ChangelogInterface
    Returns:
    the identifier of the method used for storing the StateKey in the TDI Store.
    Throws:
    Exception - - never
    See Also:
    ChangelogInterface.SAVE_STATE_AFTER_READ, ChangelogInterface.SAVE_STATE_END_OF_CYCLE, ChangelogInterface.SAVE_STATE_MANUAL

    saveStateKey

    public void saveStateKey()
                      throws Exception
    Stores the USN values for the next synchronization. This method will skip the storing of the StateKey if the StateKey save method is set to ChangelogInterface.SAVE_STATE_AFTER_READ

    Specified by:
    saveStateKey in interface ChangelogInterface
    Throws:
    Exception - - never

    getStateKeyObject

    public Object getStateKeyObject()
                             throws Exception
    This method returns the StateKey used as our Change Detection number. This number shows the last processed record and is retrieved from the ibmsnap_commitseq column in the configured table of the underlying database.

    Example:
    Here is an example how to print the StateKey using this method.

     key statekey = conn.getStateKeyObject();
     task.logmsg("Iterator State Key: " + thisConnector.connector.ctString(statekey));
     
     
    return an Object representing the commit sequence number of the last processed record throws Exception if an error occurs.

    Specified by:
    getStateKeyObject in interface ChangelogInterface
    Returns:
    the StateKey, wrapped in some kind of object.
    Throws:
    Exception - if an error occurs.
    See Also:
    ChangelogInterface

    getVersion

    public String getVersion()
    Version information.

    Specified by:
    getVersion in interface VersionInfoInterface
    Overrides:
    getVersion in class JDBCConnector
    Returns:
    version information

    getNumberOfRecords

    public static int getNumberOfRecords(String tableName,
                                         Connection con)
                                  throws Exception
    This method extracts the number of records in the changelog table.

    Parameters:
    tableName - name of the changelog table
    con - Connection handle for the currently opened session to the database
    Returns:
    number of records in the specified table
    Throws:
    Exception -
  • SQLException - if could not retrieve the number of records

  • NumberFormatException - if could not parse the returned value