com.ge.research.utils.db
Class DBPoller

java.lang.Object
  extended bycom.ge.research.utils.db.DBPoller
All Implemented Interfaces:
java.lang.Runnable

public abstract class DBPoller
extends java.lang.Object
implements java.lang.Runnable

Abstract class that defines the general functionality for a database polling utility.

Version:
$Revision: 1.1 $ $Date: 2006/08/11 00:17:26 $
Author:
garbiras
Created on:
Mar 30, 2005

Field Summary
static int DEFAULT_POLLING_FREQ
          The default polling frequency set to 3 minutes
 
Constructor Summary
DBPoller(javax.sql.DataSource datasource)
          Calls the default constructor with argument DEFAULT_POLLING_FREQ
DBPoller(javax.sql.DataSource datasource, int frequency)
          Default constructor.
DBPoller(java.lang.String resourceFile)
          Calls the default resource file constructor with argument DEFAULT_POLLING_FREQ
DBPoller(java.lang.String resourceFile, int frequency)
          Default resource file constructor.
 
Method Summary
 void addDeleteEventListener(DeleteEventListener listener)
          Add a listener to watch for database delete events
 void addInsertEventListener(InsertEventListener listener)
          Add a listener to watch for database insert events
 void addUpdateEventListener(UpdateEventListener listener)
          Add a listener to watch for database update events
protected  void freeConnection(java.sql.Connection connection)
          Returns the connection to the connection pool, if that is where it was originally obtained from.
protected  java.sql.Connection getConnection()
          Obtains a database connection from the active datasource
 long getPollFrequency()
          Returns the polling frequency in milliseconds
protected abstract  java.util.Vector queryForDeletes(java.sql.Connection connection)
          Performs the specific logic to check for delete events and creates a DeleteEvent for each one found, with the desired event information.
protected abstract  java.util.Vector queryForInserts(java.sql.Connection connection)
          Performs the specific logic to check for insert events and creates an InsertEvent for each one found, with the desired event information.
protected abstract  java.util.Vector queryForUpdates(java.sql.Connection connection)
          Performs the specific logic to check for delete events and creates an UpdateEvent for each one found, with the desired event information.
 void removeDeleteEventListener(DeleteEventListener listener)
          Remove a listener from watching for database delete events
 void removeInsertEventListener(InsertEventListener listener)
          Remove a listener from watching for database insert events
 void removeUpdateEventListener(UpdateEventListener listener)
          Remove a listener from watching for database update events
 void run()
          Executes the polling, notifying registered listeners when events occur.
 void setPollFrequency(long frequency)
          Sets the polling frequency to the number of milliseconds specified by frequency.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_POLLING_FREQ

public static final int DEFAULT_POLLING_FREQ
The default polling frequency set to 3 minutes

See Also:
Constant Field Values
Constructor Detail

DBPoller

public DBPoller(javax.sql.DataSource datasource)
Calls the default constructor with argument DEFAULT_POLLING_FREQ

Parameters:
datasource - the datasource to acquire database connection information from
See Also:
DBPoller(javax.sql.DataSource, int)

DBPoller

public DBPoller(java.lang.String resourceFile)
         throws java.lang.Exception
Calls the default resource file constructor with argument DEFAULT_POLLING_FREQ

Parameters:
resourceFile - the resource bundle to use to setup a database connection broker
Throws:
java.lang.Exception - If an error occurs while setting up the connection broker
See Also:
DBPoller(java.lang.String, int)

DBPoller

public DBPoller(javax.sql.DataSource datasource,
                int frequency)
Default constructor. Sets the datasource to use to acquire connections. Sets the polling frequency.

Parameters:
datasource - the datasource to acquire database connection information from
frequency - the millisecond value for the poll frequency
See Also:
setPollFrequency(long)

DBPoller

public DBPoller(java.lang.String resourceFile,
                int frequency)
         throws java.lang.Exception
Default resource file constructor. Calls the default constructor with argument SingleConnectionManager

Parameters:
resourceFile - the resource bundle to use to setup a database connection broker
frequency - the millisecond value for the poll frequency
Throws:
java.lang.Exception - If an error occurs while setting up the connection broker
See Also:
DBPoller(javax.sql.DataSource, int)
Method Detail

addDeleteEventListener

public final void addDeleteEventListener(DeleteEventListener listener)
Add a listener to watch for database delete events

Parameters:
listener - the listener object to notify when delete events happen

addInsertEventListener

public final void addInsertEventListener(InsertEventListener listener)
Add a listener to watch for database insert events

Parameters:
listener - the listener object to notify when insert events happen

addUpdateEventListener

public final void addUpdateEventListener(UpdateEventListener listener)
Add a listener to watch for database update events

Parameters:
listener - the listener object to notify when update events happen

getPollFrequency

public final long getPollFrequency()
Returns the polling frequency in milliseconds

Returns:
The number of milliseconds for the polling frequency

removeDeleteEventListener

public final void removeDeleteEventListener(DeleteEventListener listener)
Remove a listener from watching for database delete events

Parameters:
listener - the listener object to remove from notification

removeInsertEventListener

public final void removeInsertEventListener(InsertEventListener listener)
Remove a listener from watching for database insert events

Parameters:
listener - the listener object to remove from notification

removeUpdateEventListener

public final void removeUpdateEventListener(UpdateEventListener listener)
Remove a listener from watching for database update events

Parameters:
listener - the listener object to remove from notification

setPollFrequency

public final void setPollFrequency(long frequency)
Sets the polling frequency to the number of milliseconds specified by frequency. If the frequency is less than zero, the polling frequency is set to zero.

Parameters:
frequency - the new millisecond value for the poll frequency

run

public final void run()
Executes the polling, notifying registered listeners when events occur.

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run(), Thread.sleep(long), getConnection(), freeConnection(java.sql.Connection), queryForDeletes(java.sql.Connection), queryForInserts(java.sql.Connection), queryForUpdates(java.sql.Connection)

freeConnection

protected void freeConnection(java.sql.Connection connection)
Returns the connection to the connection pool, if that is where it was originally obtained from.

Parameters:
connection - the database connection to return to the pool

getConnection

protected java.sql.Connection getConnection()
                                     throws java.sql.SQLException
Obtains a database connection from the active datasource

Returns:
An active database connection
Throws:
java.sql.SQLException - If an error occurs while attempting to retrieve a connection

queryForDeletes

protected abstract java.util.Vector queryForDeletes(java.sql.Connection connection)
Performs the specific logic to check for delete events and creates a DeleteEvent for each one found, with the desired event information. Called by the run() method Returns a list of the events found, null if no events were found. This method should not close the Connection resource when finished. The Connection resource may be reused outside of this method, and as such it is the calling method's responsibility to close the Connection resource.

Parameters:
connection - the database connection to use to execute the polling query
Returns:
The list of DeleteEvents found and created, to be passed to the registered delete event listeners.

queryForInserts

protected abstract java.util.Vector queryForInserts(java.sql.Connection connection)
Performs the specific logic to check for insert events and creates an InsertEvent for each one found, with the desired event information. Called by the run() method. Returns a list of the events found, null if no events were found. This method should not close the Connection resource when finished. The Connection resource may be reused outside of this method, and as such it is the calling method's responsibility to close the Connection resource.

Parameters:
connection - the database connection to use to execute the polling query
Returns:
The list of InsertEvents found and created, to be passed to the registered insert event listeners.

queryForUpdates

protected abstract java.util.Vector queryForUpdates(java.sql.Connection connection)
Performs the specific logic to check for delete events and creates an UpdateEvent for each one found, with the desired event information. Called by the run() method Returns a list of the events found, null if no events were found. This method should not close the Connection resource when finished. The Connection resource may be reused outside of this method, and as such it is the calling method's responsibility to close the Connection resource.

Parameters:
connection - the database connection to use to execute the polling query
Returns:
The list of DeleteEvents found and created, to be passed to the registered update event listeners.