org.osesb.scheduledjobs.databasepoller
Class SelectAndCheckpointProcessedRowsTableSetAdapter

java.lang.Object
  extended by org.osesb.connectors.jdbc.TableSetAdapter
      extended by org.osesb.connectors.jdbc.SelectStatementTableSetAdapter
          extended by org.osesb.scheduledjobs.databasepoller.SelectAndCheckpointProcessedRowsTableSetAdapter
Direct Known Subclasses:
SelectAndDeleteProcessedRowsTableSetAdapter

public class SelectAndCheckpointProcessedRowsTableSetAdapter
extends SelectStatementTableSetAdapter

SelectAndCheckpointProcessedRowsTableSetAdapter is a TableSetAdapter that is designed to be used with a database poller scheduled job.

SelectAndCheckpointProcessedRowsTableSetAdapter extends org.osesb.connectors.jdbc.SelectStatementTableSetAdapter with methods that scan database tables for changes and checkpoint processed rows so that rows are not processed more than once.

More specifically, SelectAndCheckpointProcessedRowsTableSetAdapter is designed to be used with a TableSet that configures a scrollable, updatable ResultSet where the org.osesb.utilities.jdbc.SQLStatements are configured with org.osesb.utilities.jdbc.SQLInputParameters and where the values of the SQLInputParameters are given by a scripted variable. Scripted variables are supported by the org.osesb.scriptedvariables package.

It is difficult to design a set of database poller classes that can meet the variety of requirements that one is likely to encounter. For example, suppose that database rows are to be checkpointed using a timestamp column and a messageID column where the messageID column is updated with the messageID of the message that is sent to osESB via the configured ClientGateway. Further suppose that the database ResultSet(s) are transformed to XML and that one message per row is sent to osESB. In these circumstances, the built-in MessagePipeline stages that are in the org.osesb.messagepipeline.builtinstages package need to be extended for the ClientGateway that is configured by the database poller to send messages to osESB.

Because of the complexities in real-world database poller implementations, it was decided to provide a default database poller class, DefaultDatabasePollerScheduledJob, that uses a SelectAndCheckpointProcessedRowsTableSetAdapter and then provide examples in the org.osesb.scheduledjobs.databasepoller.test package.

SelectAndCheckpointProcessedRowsTableSetAdapter extends SelectStatementTableSetAdapter, which accomplishes the table scan, and adds a checkpointProcessedRows() method that is invoked to checkpoint processed rows after message(s) are sent to osESB transfort handlers. Typically, a scrollable, updatable ResultSet is configured for the select statement and the processed rows are checkpointed using SQLInputParameter whose values are given by the 'now' scripted variable.

By default, processTableSet() looks for a SQL statement named 'selectStatement' in the SQLStatementListConfiguration portion of the TableSetConfiguration file. To specify a SQLStatement with a different name, configure an adapter property named 'selectStatementName'.


Field Summary
 
Fields inherited from class org.osesb.connectors.jdbc.SelectStatementTableSetAdapter
connectedResultSetConnection
 
Fields inherited from class org.osesb.connectors.jdbc.TableSetAdapter
log, parentTableSet, tableSetAdapterConfiguration, thisClassName
 
Constructor Summary
SelectAndCheckpointProcessedRowsTableSetAdapter(TableSet parentTableSet, TableSetAdapterConfiguration tableSetAdapterConfiguration)
          Creates a new instance of SelectAndCheckpointProcessedRowsTableSetAdapter.
 
Method Summary
 java.lang.Object[] checkpointProcessedRows(java.sql.ResultSet rs)
          Checkpoint processed rows using a scrollable, updatable ResultSet where the org.osesb.utilities.jdbc.SQLStatements are configured with org.osesb.utilities.jdbc.SQLInputParameters and where the values of the SQLInputParameters are given by a scripted variable.
 java.lang.Object[] doCustomProcessing(java.lang.Object[] parameters)
          Custom processing method.
static void main(java.lang.String[] args)
          main() For testing and sandboxing.
 
Methods inherited from class org.osesb.connectors.jdbc.SelectStatementTableSetAdapter
processStatement, processTableSet
 
Methods inherited from class org.osesb.connectors.jdbc.TableSetAdapter
getParentTableSet, logMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelectAndCheckpointProcessedRowsTableSetAdapter

public SelectAndCheckpointProcessedRowsTableSetAdapter(TableSet parentTableSet,
                                                       TableSetAdapterConfiguration tableSetAdapterConfiguration)
                                                throws java.lang.Exception
Creates a new instance of SelectAndCheckpointProcessedRowsTableSetAdapter.

Parameters:
parentTableSet - The TableSet that owns this TableSetAdapter.
Throws:
java.lang.Exception - if constructed with a null TableSet.
Method Detail

doCustomProcessing

public java.lang.Object[] doCustomProcessing(java.lang.Object[] parameters)
                                      throws java.lang.Exception
Custom processing method. Invoke checkpointProcessedRows() and release JDBC resources.

SelectAndCheckpointProcessedRowsTableSetAdapter is designed to be used with a TableSet that configures a scrollable, updatable ResultSet where the org.osesb.utilities.jdbc.SQLStatements are configured with org.osesb.utilities.jdbc.SQLInputParameters and where the values of the SQLInputParameters are given by a scripted variable. Scripted variables are supported by the org.osesb.scriptedvariables package.

The scrollable, updatable ResultSet is processed by checkpointProcessedRows() in order to checkpoint processed rows.

Overrides:
doCustomProcessing in class SelectStatementTableSetAdapter
Parameters:
parameters - Custom processing parameters.
Returns:
the result of custom processing as an Object[].
Throws:
java.lang.Exception - if an error is encountered during custom processing.

checkpointProcessedRows

public java.lang.Object[] checkpointProcessedRows(java.sql.ResultSet rs)
                                           throws java.lang.Exception
Checkpoint processed rows using a scrollable, updatable ResultSet where the org.osesb.utilities.jdbc.SQLStatements are configured with org.osesb.utilities.jdbc.SQLInputParameters and where the values of the SQLInputParameters are given by a scripted variable. Scripted variables are supported by the org.osesb.scriptedvariables package.

checkpointProcessedRows() DOES NOT release TableSet and JDBC resources; it is the responsibility of the caller to invoke TableSet#releaseConnection().

Parameters:
rs - The ResultSet that was returned by processTableSet().
Returns:
the result of SQL processing of as an Object[] where the first element of the array is an Integer for the number of rows that were updated.
Throws:
java.lang.Exception - if there is a problem with processing the TableSet SQL.

main

public static void main(java.lang.String[] args)
main() For testing and sandboxing.

Parameters:
args - commandline arguments