Class DBChangelogConnector
- java.lang.Object
-
- com.ibm.di.connector.Connector
-
- com.ibm.di.connector.JDBCConnector
-
- 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.JDBCConnector
CONNECTOR_MODES, VERSION_INFO
-
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
Constructors Constructor Description DBChangelogConnector()Constructor for the DBChangelogConnector object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringctString(java.lang.Object ct)Converts the Object to String.booleandoWait()This method sleeps for a number of seconds specified by the 'Sleep Interval' parameter.EntrygetNextEntry()Gets the next Entry object from the 'change table'.static intgetNumberOfRecords(java.lang.String tableName, java.sql.Connection con)This method extracts the number of records in the changelog table.java.lang.ObjectgetStateKeyObject()This method returns the StateKey used as our Change Detection number.intgetStateKeySaveMethod()Retrieves the method for storing StateKey.java.lang.StringgetVersion()Version information.voidinitialize(java.lang.Object o)Reads Connector parameter's values and initialize the Connector.voidremoveProcessedRows()Removes processed rows from the 'change table'.voidreselect()Retrieves records from the 'change table' using the current value of the StateKey.voidsaveStateKey()Stores the USN values for the next synchronization.voidselectEntries()This method prepares the Connector for a sequential read.java.lang.StringtoHex(int n)Converts integer to Hex String.-
Methods inherited from class com.ibm.di.connector.JDBCConnector
alterSession, commit, deleteEntry, execSQL, execSQLSelect, extractExceptionInformation, findEntry, getConnection, getLastSqlString, getNextSQLSelectEntry, getNumSkipLookupAffected, getParameterSubstitution, getPreparedString, getSchemaSeparator, getStatement, getSubClause, getWhereClause, isDeltaSupported, isEOCflag, isInsertPaddingDisabled, isIOException, isLookupPaddingDisabled, isMSSqlServerDB, isUpdatePaddingDisabled, modEntry, putEntry, querySchema, queryTables, rollback, saveMetaData, setCommitMode, setCurrent, setEOCflag, setPaddingInInsert, setPaddingInLookup, setPaddingInUpdate, setParameterSubstitution, setPreparedDeleteStatement, setPreparedFindStatement, setPreparedInsertStatement, setPreparedModifyStatement, setPreparedSelectStatement, setResultSet, setSchemaSeparator, 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
-
-
-
-
Method Detail
-
initialize
public void initialize(java.lang.Object o) throws java.lang.ExceptionReads Connector parameter's values and initialize the Connector.- Specified by:
initializein interfaceConnectorInterface- Overrides:
initializein classJDBCConnector- Parameters:
o- Socket object, ConnectorMode object ornull- Throws:
java.lang.Exception- If invalid Connector parameter values are supplied.
-
selectEntries
public void selectEntries() throws java.lang.ExceptionThis method prepares the Connector for a sequential read. Retrieves records from 'change table'.- Specified by:
selectEntriesin interfaceConnectorInterface- Overrides:
selectEntriesin classJDBCConnector- Throws:
java.lang.Exception- If an error occurs while selecting Entries- See Also:
JDBCConnector.getNextEntry()
-
reselect
public void reselect() throws java.lang.ExceptionRetrieves records from the 'change table' using the current value of the StateKey. If StateKey is:
nulland 'Remove Processed Row' parameter istrue- the processed rows are deleted from the 'change table'
nulland 'Remove Processed Row' parameter isfalse- all entries are retrieved
- not
null- only entries with ibmsnap_commitseq > StateKey are retrieved- Throws:
java.lang.Exception- If an error occurs while retrieving records from the database
-
removeProcessedRows
public void removeProcessedRows() throws java.lang.ExceptionRemoves processed rows from the 'change table'. This method deletes all rows withibmsnap_commitseq <= StateKey. These rows are actually already returned as entries by thegetNextEntry()function.This method is called from the reselect() method only if the parameter 'Removed Processed Rows' is set to
true.- Throws:
java.lang.Exception- If the Connector can not delete processed rows in the database
-
ctString
public java.lang.String ctString(java.lang.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 java.lang.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 java.lang.Exception
Gets the next Entry object from the 'change table'.- Specified by:
getNextEntryin interfaceConnectorInterface- Overrides:
getNextEntryin classJDBCConnector- Returns:
- The next Entry
- Throws:
java.lang.Exception- If retrieving the next Entry fails.- See Also:
ConnectorInterface.selectEntries()
-
doWait
public boolean doWait() throws java.lang.ExceptionThis 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 returnnull.- Returns:
- boolean flag, if true everything is fine, if false maxWait > 0 and (lastWait - firstWait) > maxWait
- Throws:
java.lang.Exception- if an error occurs during sleeping.
-
getStateKeySaveMethod
public int getStateKeySaveMethod() throws java.lang.ExceptionRetrieves the method for storing StateKey.- Specified by:
getStateKeySaveMethodin interfaceChangelogInterface- Returns:
- the identifier of the method used for storing the StateKey in the TDI Store.
- Throws:
java.lang.Exception- - never- See Also:
ChangelogInterface.SAVE_STATE_AFTER_READ,ChangelogInterface.SAVE_STATE_END_OF_CYCLE,ChangelogInterface.SAVE_STATE_MANUAL
-
saveStateKey
public void saveStateKey() throws java.lang.ExceptionStores the USN values for the next synchronization. This method will skip the storing of the StateKey if the StateKey save method is set toChangelogInterface.SAVE_STATE_AFTER_READ- Specified by:
saveStateKeyin interfaceChangelogInterface- Throws:
java.lang.Exception- - never
-
getStateKeyObject
public java.lang.Object getStateKeyObject() throws java.lang.ExceptionThis 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:
getStateKeyObjectin interfaceChangelogInterface- Returns:
- the StateKey, wrapped in some kind of object.
- Throws:
java.lang.Exception- if an error occurs.- See Also:
ChangelogInterface
-
getVersion
public java.lang.String getVersion()
Version information.- Specified by:
getVersionin interfaceVersionInfoInterface- Overrides:
getVersionin classJDBCConnector- Returns:
- version information
-
getNumberOfRecords
public static int getNumberOfRecords(java.lang.String tableName, java.sql.Connection con) throws java.lang.ExceptionThis method extracts the number of records in the changelog table.- Parameters:
tableName- name of the changelog tablecon- Connection handle for the currently opened session to the database- Returns:
- number of records in the specified table
- Throws:
java.lang.Exception-- SQLException - if could not retrieve the number of records
- NumberFormatException - if could not parse the returned value
-
-