xmlBlaster 2.2.0 contributions API

org.xmlBlaster.contrib.dbwatcher
Class DbWatcher

java.lang.Object
  extended by org.xmlBlaster.contrib.dbwatcher.DbWatcher
All Implemented Interfaces:
java.util.EventListener, I_ChangeListener

public class DbWatcher
extends java.lang.Object
implements I_ChangeListener

This is the core processor class to handle database observation.

We handle detected changes of the observed target, typically a database table, and forward them to the I_ChangePublisher implementation, typically a message oriented middleware (MoM). The changes are XML formatted as implemented by the I_DataConverter plugin.

This class loads all plugins by reflection and starts them. Each plugin has its specific configuration paramaters. Descriptions thereof you find in the plugins documentation.

To get you quickly going have a look into Example.java

Configuration:

Author:
Marcel Ruff
See Also:
org.xmlBlaster.contrib.dbwatcher.test.TestResultSetToXmlConverter

Constructor Summary
DbWatcher()
          Default constructor, you need to call init(org.xmlBlaster.contrib.I_Info) thereafter.
DbWatcher(I_Info info)
          Convenience constructor, creates a processor for changes, calls init(org.xmlBlaster.contrib.I_Info).
 
Method Summary
 I_ChangeDetector getChangeDetector()
          Access the change detector handele.
static I_ChangePublisher getChangePublisher(I_Info info)
           
static I_DbPool getDbInfoPool(I_Info info)
          We scan for dbinfo.* properties and replace it with db.* in a second info object to use for the configuration of the DbPool.
static I_DbPool getDbPool(I_Info info)
           
 I_ChangePublisher getMom()
          Access the MoM handele.
 void hasChanged(ChangeEvent changeEvent)
          Is called for every data source changed.
 void init(I_Info info)
          Creates a processor for changes.
 int publishMessagesFromStmt(java.lang.String stmt, boolean useGroupCol, ChangeEvent changeEvent, java.sql.Connection conn)
          Does a SQL query with stmt and sends all ResultSets to I_ChangePublisher.
static java.sql.Connection releaseWithCommit(java.sql.Connection conn, I_DbPool pool)
          Helper method used for cleanup: invoke conn = DbWatcher.
static java.lang.String replaceVariable(java.lang.String text, java.lang.String token)
          Replace e.g.
 void shutdown()
          Cleanup resources.
 void startAlertProducers()
          Start the work.
 void stopAlertProducers()
          Suspend processing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbWatcher

public DbWatcher()
Default constructor, you need to call init(org.xmlBlaster.contrib.I_Info) thereafter.


DbWatcher

public DbWatcher(I_Info info)
          throws java.lang.Exception
Convenience constructor, creates a processor for changes, calls init(org.xmlBlaster.contrib.I_Info).

Parameters:
info - Configuration
Throws:
java.lang.Exception - Can be of any type
Method Detail

getChangePublisher

public static I_ChangePublisher getChangePublisher(I_Info info)
                                            throws java.lang.Exception
Throws:
java.lang.Exception

getDbPool

public static I_DbPool getDbPool(I_Info info)
                          throws java.lang.Exception
Throws:
java.lang.Exception

getDbInfoPool

public static I_DbPool getDbInfoPool(I_Info info)
                              throws java.lang.Exception
We scan for dbinfo.* properties and replace it with db.* in a second info object to use for the configuration of the DbPool. Defaults to getDbPool if no 'dbinfo.url' is specified in the configuration.

Parameters:
info -
Returns:
Throws:
java.lang.Exception

init

public void init(I_Info info)
          throws java.lang.Exception
Creates a processor for changes. The alert producers need to be started later with a call to startAlertProducers()

Parameters:
info - Configuration
Throws:
java.lang.Exception - Can be of any type

startAlertProducers

public void startAlertProducers()
Start the work.


stopAlertProducers

public void stopAlertProducers()
Suspend processing.


getMom

public I_ChangePublisher getMom()
Access the MoM handele.

Returns:
The I_ChangePublisher plugin

getChangeDetector

public I_ChangeDetector getChangeDetector()
Access the change detector handele.

Returns:
The I_ChangeDetector plugin

hasChanged

public void hasChanged(ChangeEvent changeEvent)
Description copied from interface: I_ChangeListener
Is called for every data source changed.

Specified by:
hasChanged in interface I_ChangeListener
Parameters:
changeEvent - Transports all needed information about the change
See Also:
I_ChangeListener.hasChanged(ChangeEvent)

publishMessagesFromStmt

public int publishMessagesFromStmt(java.lang.String stmt,
                                   boolean useGroupCol,
                                   ChangeEvent changeEvent,
                                   java.sql.Connection conn)
                            throws java.lang.Exception
Description copied from interface: I_ChangeListener
Does a SQL query with stmt and sends all ResultSets to I_ChangePublisher.

The messages are formatted by the configured I_DataConverter plugin.

Note: This is a common convenienve function, in a future refactoring we should have this method in a separate interface.

Specified by:
publishMessagesFromStmt in interface I_ChangeListener
Parameters:
stmt - The SQL query string (with/without grouping)
useGroupCol - If true we send a message for each ChangeEvent.getGroupColName() change
changeEvent - The reason to send
conn - The JDBC connection, if null we get one ourself in auto commit mode
Returns:
The number of changes detected TODO! (currently returns -1)
Throws:
java.lang.Exception - of any type
See Also:
I_ChangeListener.publishMessagesFromStmt(java.lang.String, boolean, org.xmlBlaster.contrib.dbwatcher.ChangeEvent, java.sql.Connection)

replaceVariable

public static java.lang.String replaceVariable(java.lang.String text,
                                               java.lang.String token)
Replace e.g. ${XY} with the given token.

Parameters:
text - The complete string which may contain zero to many ${...} variables, if null we return null
token - The replacement token, if null the original text is returned
Returns:
The new value where all ${} are replaced.

shutdown

public void shutdown()
              throws java.lang.Exception
Cleanup resources.

Specified by:
shutdown in interface I_ChangeListener
Throws:
java.lang.Exception - Can be of any type

releaseWithCommit

public static java.sql.Connection releaseWithCommit(java.sql.Connection conn,
                                                    I_DbPool pool)
                                             throws java.lang.Exception
Helper method used for cleanup: invoke conn = DbWatcher.

Parameters:
conn -
pool -
Returns:
always null (to be set to the connection)
Throws:
java.lang.Exception

xmlBlaster 2.2.0 contributions API

Copyright © 1999-2014 The xmlBlaster.org contributers.