org.jboss.soa.esb.listeners.gateway
Class SqlTableGatewayListener

java.lang.Object
  extended by org.jboss.soa.esb.listeners.gateway.SqlTableGatewayListener
All Implemented Interfaces:
java.lang.Runnable

public class SqlTableGatewayListener
extends java.lang.Object
implements java.lang.Runnable

Polls an SQL table for rows that satisfy conditions defined in the xml runtime configuration

When a row that matches conditions is retrieved, it's contents are packed into an ESB Message and

The following fields are mandatory (see checkMyParms()):

SQL table name
list of fields to retrieve
list of key fields to use in the update statement
a field that will be used to mark a row as 'pending(p)', 'in process(w)', 'done(d)' or 'in error(e)'

Since:
Version 4.0
Author:
schifest@heuristica.com.ar

Nested Class Summary
static class SqlTableGatewayListener.PackageRowContents
          Default gateway action for SQL table rows

It will just drop the result set contents into a Message

static class SqlTableGatewayListener.ROW_STATE
           
 
Field Summary
protected  java.lang.String[] _columns
           
protected  java.lang.Object _composer
           
protected  java.lang.Class _composerClass
           
protected  java.lang.String _composerName
           
protected  ConfigTree _config
           
protected  GatewayListenerController _controller
           
protected  Courier _courier
           
protected  java.util.Map<java.lang.String,java.lang.Object> _currentRow
           
protected  JdbcCleanConn _dbConn
           
protected  boolean _deleteAfterOK
           
protected  java.lang.String _driver
           
protected  java.lang.String _inProcessField
           
protected  java.lang.String _inProcessVals
           
protected  java.lang.String _keyFields
           
protected  java.lang.String[] _keys
           
protected static org.apache.log4j.Logger _logger
           
protected  EPR _myEpr
           
protected  java.lang.String _orderBy
           
protected  java.lang.String _password
           
protected  java.lang.reflect.Method _processMethod
           
protected  java.sql.PreparedStatement _PSdeleteRow
           
protected  java.sql.PreparedStatement _PSscan
           
protected  java.sql.PreparedStatement _PSsel4U
           
protected  java.sql.PreparedStatement _PSupdate
           
protected  java.lang.String _selectFields
           
protected  java.lang.String _serviceCategory
           
protected  java.lang.String _serviceName
           
protected  long _sleepBetweenPolls
           
protected  java.lang.String _tableName
           
protected  java.util.Collection<EPR> _targetEprs
           
protected  java.lang.String _targetServiceCategory
           
protected  java.lang.String _targetServiceName
           
protected  java.lang.String _url
           
protected  java.lang.String _user
           
protected  java.lang.String _where
           
static java.lang.String DEFAULT_IN_PROCESS_STATES
           
 
Constructor Summary
SqlTableGatewayListener(GatewayListenerController commandListener, ConfigTree config)
           
 
Method Summary
protected  boolean changeStatus(SqlTableGatewayListener.ROW_STATE fromState, SqlTableGatewayListener.ROW_STATE toState)
           
protected  boolean changeStatusToDone()
           
protected  boolean changeStatusToError()
           
protected  boolean changeStatusToWorking()
           
protected  void checkMyParms()
          Check for mandatory and optional attributes in parameter tree
protected  boolean deleteCurrentRow()
          Try to delete 'current row' from polled table
protected  java.lang.String deleteStatement()
          Assemble the SQL statement to delete the current row in the table row uniquely identified by the list of fields in the "keyFields" parameter
protected  JdbcCleanConn getDbConn()
          Obtain a new database connection with parameter info
protected  java.lang.String getStatus(SqlTableGatewayListener.ROW_STATE p_oState)
           
protected  java.util.List<java.util.Map<java.lang.String,java.lang.Object>> pollForCandidates()
           
protected  void prepareStatements()
           
protected  void resolveComposerClass()
           
 void run()
           
protected  java.lang.String scanStatement()
          Assemble the SQL statement to scan (poll) the table
protected  java.lang.String selectForUpdStatement()
          Assemble the SQL "select for update" statement for the "inProcessField" parameter in the table row uniquely identified by the list of fields in the "keyFields" parameter
protected  java.lang.String updateStatement()
          Assemble the SQL statement to update the field in the "inProcessField" parameter in the table row uniquely identified by the list of fields in the "keyFields" parameter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_logger

protected static final org.apache.log4j.Logger _logger

_config

protected ConfigTree _config

_controller

protected GatewayListenerController _controller

_sleepBetweenPolls

protected long _sleepBetweenPolls

_serviceCategory

protected java.lang.String _serviceCategory

_serviceName

protected java.lang.String _serviceName

_targetServiceCategory

protected java.lang.String _targetServiceCategory

_targetServiceName

protected java.lang.String _targetServiceName

_myEpr

protected EPR _myEpr

_targetEprs

protected java.util.Collection<EPR> _targetEprs

_composerName

protected java.lang.String _composerName

_composerClass

protected java.lang.Class _composerClass

_composer

protected java.lang.Object _composer

_processMethod

protected java.lang.reflect.Method _processMethod

_courier

protected Courier _courier

_driver

protected java.lang.String _driver

_url

protected java.lang.String _url

_user

protected java.lang.String _user

_password

protected java.lang.String _password

_tableName

protected java.lang.String _tableName

_selectFields

protected java.lang.String _selectFields

_keyFields

protected java.lang.String _keyFields

_where

protected java.lang.String _where

_orderBy

protected java.lang.String _orderBy

_inProcessField

protected java.lang.String _inProcessField

_inProcessVals

protected java.lang.String _inProcessVals

_deleteAfterOK

protected boolean _deleteAfterOK

_columns

protected java.lang.String[] _columns

_keys

protected java.lang.String[] _keys

_PSscan

protected java.sql.PreparedStatement _PSscan

_PSsel4U

protected java.sql.PreparedStatement _PSsel4U

_PSupdate

protected java.sql.PreparedStatement _PSupdate

_PSdeleteRow

protected java.sql.PreparedStatement _PSdeleteRow

_dbConn

protected JdbcCleanConn _dbConn

_currentRow

protected java.util.Map<java.lang.String,java.lang.Object> _currentRow

DEFAULT_IN_PROCESS_STATES

public static final java.lang.String DEFAULT_IN_PROCESS_STATES
See Also:
Constant Field Values
Constructor Detail

SqlTableGatewayListener

public SqlTableGatewayListener(GatewayListenerController commandListener,
                               ConfigTree config)
                        throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable

checkMyParms

protected void checkMyParms()
                     throws java.lang.Exception
Check for mandatory and optional attributes in parameter tree

Throws:
java.lang.Exception - - if mandatory atts are not right or actionClass not in classpath

prepareStatements

protected void prepareStatements()
                          throws ConfigurationException
Throws:
ConfigurationException

resolveComposerClass

protected void resolveComposerClass()
                             throws java.lang.Exception
Throws:
java.lang.Exception

pollForCandidates

protected java.util.List<java.util.Map<java.lang.String,java.lang.Object>> pollForCandidates()

getDbConn

protected JdbcCleanConn getDbConn()
                           throws java.lang.Exception
Obtain a new database connection with parameter info

Returns:
A new connection
Throws:
java.lang.Exception - - if problems are encountered

scanStatement

protected java.lang.String scanStatement()
Assemble the SQL statement to scan (poll) the table

Returns:
- The resulting SQL statement

updateStatement

protected java.lang.String updateStatement()
Assemble the SQL statement to update the field in the "inProcessField" parameter in the table row uniquely identified by the list of fields in the "keyFields" parameter

Returns:
- The resulting SQL statement

selectForUpdStatement

protected java.lang.String selectForUpdStatement()
Assemble the SQL "select for update" statement for the "inProcessField" parameter in the table row uniquely identified by the list of fields in the "keyFields" parameter

Returns:
- The resulting SQL statement

deleteStatement

protected java.lang.String deleteStatement()
Assemble the SQL statement to delete the current row in the table row uniquely identified by the list of fields in the "keyFields" parameter

Returns:
- The resulting SQL statement

deleteCurrentRow

protected boolean deleteCurrentRow()
Try to delete 'current row' from polled table

Returns:
true if row deletion was successful - false otherwise

getStatus

protected java.lang.String getStatus(SqlTableGatewayListener.ROW_STATE p_oState)

changeStatusToWorking

protected boolean changeStatusToWorking()

changeStatusToDone

protected boolean changeStatusToDone()

changeStatusToError

protected boolean changeStatusToError()

changeStatus

protected boolean changeStatus(SqlTableGatewayListener.ROW_STATE fromState,
                               SqlTableGatewayListener.ROW_STATE toState)