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, CheckpointRestartInterface, VersionInfoInterface

public class DBChangelogConnector
extends JDBCConnector
implements ConnectorInterface, CheckpointRestartInterface, 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.server.CheckpointRestartInterface
RESTART_AFTER, RESTART_BEFORE, RESTART_IN
 
Fields inherited from interface com.ibm.di.connector.ChangelogInterface
CONN_PARAM_STATE_KEY_PERSISTENCE, 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()
          Waits n seconds specified in the pollInterval parameter
 Entry getCheckpointInformation()
          Returns the state information for the connector.
 Entry getNextEntry()
          Gets the next Entry object from the "change table".
 Object getStateKeyObject()
          Gets the current changeToken object.
 int getStateKeySaveMethod()
          Returns the method used to store the current changelog number
 String getVersion()
          Return version information
 void initialize(Object o)
          Reads Connector parameter's values and initialize the Connector.
 boolean isCheckpointRestartEnabled(int mode)
          Components that support checkpoint/restart for a specific mode must return TRUE from this method.
 void prepareForRestart(ALState state, Entry restartInfo, int restartPoint)
          Notifies the connector of a restart situation.
 void removeProcessedRows()
          Removes Processed rows from the "change table"
 void reselect()
          Retrieves records from "change table"
 void saveStateKey()
          Saves the State Key in the System Store
 void selectEntries()
          Prepares the Connector for sequential read.
 String toHex(int n)
          Converts int to Hex String
 
Methods inherited from class com.ibm.di.connector.JDBCConnector
alterSession, commit, deleteEntry, execSQL, execSQLSelect, findEntry, getConnection, getNextSQLSelectEntry, getStatement, getSubClause, getWhereClause, isDeltaSupported, isIOException, modEntry, putEntry, querySchema, queryTables, rollback, saveMetaData, setCommitMode, setCurrent, 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, hasConfigValue, hasParser, initParser, isExceptionFatal, logmsg, modEntry, pushback, queryOperations, queryReply, reconnect, reconnect, registerScriptBeans, replyEntry, setConfiguration, setContext, 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 - Null, Socket or ConnectorMode class
Throws:
Exception - If invalid Connector parameter values are supplied.

selectEntries

public void selectEntries()
                   throws Exception
Prepares the Connector for 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 "change table"

Throws:
Exception - If an error occurs while retriving records from database

removeProcessedRows

public void removeProcessedRows()
                         throws Exception
Removes Processed rows from the "change table"

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

ctString

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

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

toHex

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

Parameters:
n - int 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:
Connector.selectEntries()

doWait

public boolean doWait()
               throws Exception
Waits n seconds specified in the pollInterval parameter

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

getStateKeySaveMethod

public int getStateKeySaveMethod()
                          throws Exception
Returns the method used to store the current changelog number

Specified by:
getStateKeySaveMethod in interface ChangelogInterface
Returns:
int value of the KeySaveMethod
Throws:
Exception - if an error occurs.
See Also:
ChangelogInterface

saveStateKey

public void saveStateKey()
                  throws Exception
Saves the State Key in the System Store

Specified by:
saveStateKey in interface ChangelogInterface
Throws:
Exception - if an error occurs.
See Also:
ChangelogInterface

getStateKeyObject

public Object getStateKeyObject()
                         throws Exception
Gets the current changeToken object. The last processed record.

Specified by:
getStateKeyObject in interface ChangelogInterface
Returns:
Object the changeToken
Throws:
Exception - if an error occurs.
See Also:
ChangelogInterface

getVersion

public String getVersion()
Return version information

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

isCheckpointRestartEnabled

public boolean isCheckpointRestartEnabled(int mode)
Components that support checkpoint/restart for a specific mode must return TRUE from this method. If a restart has no meaning for mode then the connector should still return TRUE.

Specified by:
isCheckpointRestartEnabled in interface CheckpointRestartInterface
Parameters:
mode - The mode the connector runs in
Returns:
true if checkpoint is supported in mode
See Also:
ServerConstants

getCheckpointInformation

public Entry getCheckpointInformation()
                               throws Exception
Returns the state information for the connector. If for some reason the connector decidies that a restart is impossible it must throw an exception. The method is called immediatly before any component methods are called. If there is no need to save any state information a null value should be returned. For eventhandlers this method is called by the dispatcher routine.

Specified by:
getCheckpointInformation in interface CheckpointRestartInterface
Returns:
The entry the connector needs to do a restart or null if that is not needed.
Throws:
Exception

prepareForRestart

public void prepareForRestart(ALState state,
                              Entry restartInfo,
                              int restartPoint)
                       throws Exception
Notifies the connector of a restart situation. This method is called after the connector has been loaded and before any other method calls are made to the connector. If the connector decides it cannot restart it must throw an exception.

Specified by:
prepareForRestart in interface CheckpointRestartInterface
Parameters:
state - The ALState object for the AssemblyLine
restartInfo - The last entry object returned by the connector in the getCheckpointInformation method
restartPoint - The relative point where restarting is taking place (e.g. RESTART_BEFORE ...)
Throws:
Exception