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.String
ctString(java.lang.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(java.lang.String tableName, java.sql.Connection con)
This method extracts the number of records in the changelog table.java.lang.Object
getStateKeyObject()
This method returns the StateKey used as our Change Detection number.int
getStateKeySaveMethod()
Retrieves the method for storing StateKey.java.lang.String
getVersion()
Version information.void
initialize(java.lang.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.java.lang.String
toHex(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.Exception
Reads Connector parameter's values and initialize the Connector.- Specified by:
initialize
in interfaceConnectorInterface
- Overrides:
initialize
in 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.Exception
This method prepares the Connector for a sequential read. Retrieves records from 'change table'.- Specified by:
selectEntries
in interfaceConnectorInterface
- Overrides:
selectEntries
in classJDBCConnector
- Throws:
java.lang.Exception
- If an error occurs while selecting Entries- See Also:
JDBCConnector.getNextEntry()
-
reselect
public void reselect() throws java.lang.Exception
Retrieves records from the 'change table' using the current value of the StateKey. If StateKey is:
null
and 'Remove Processed Row' parameter istrue
- the processed rows are deleted from the 'change table'
null
and '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.Exception
Removes 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:
getNextEntry
in interfaceConnectorInterface
- Overrides:
getNextEntry
in 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.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 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.Exception
Retrieves the method for storing StateKey.- Specified by:
getStateKeySaveMethod
in 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.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 toChangelogInterface.SAVE_STATE_AFTER_READ
- Specified by:
saveStateKey
in interfaceChangelogInterface
- Throws:
java.lang.Exception
- - never
-
getStateKeyObject
public java.lang.Object getStateKeyObject() throws java.lang.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 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:
getVersion
in interfaceVersionInfoInterface
- Overrides:
getVersion
in classJDBCConnector
- Returns:
- version information
-
getNumberOfRecords
public static int getNumberOfRecords(java.lang.String tableName, java.sql.Connection con) throws java.lang.Exception
This 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
-
-