xmlBlaster 2.1.0 API

org.xmlBlaster.contrib.dbwatcher.detector
Class MD5ChangeDetector

java.lang.Object
  extended by org.xmlBlaster.contrib.dbwatcher.detector.MD5ChangeDetector
All Implemented Interfaces:
I_ChangeDetector

public class MD5ChangeDetector
extends java.lang.Object
implements I_ChangeDetector

Check the database and compare the MD5 of the result set to the previous one.

Configuration:

If the table does not exist in the DB no event is triggered, if an empty table comes to existence an empty event with untouched topic name is triggered:

 topic='db.change.event.${ICAO_ID}'
 
 <?xml version='1.0' encoding='UTF-8' ?>
 <sql>
 </sql>
 

Note that the previous MD5 values are hold in RAM only, after plugin restart they are lost and a complete set of data is send again.

DB statement Reported change Comment
CREATE CREATE -
INSERT INSERT On multiple table entries for a changeDetector.groupColName the change is reported as UPDATE
UPDATE UPDATE -
DELETE DELETE -
DROP DROP see mom.eraseOnDrop configuration

Author:
Marcel Ruff

Field Summary
protected  int changeCount
           
protected  java.lang.String changeDetectStatement
           
protected  I_ChangeListener changeListener
           
protected  I_DataConverter dataConverter
           
protected  I_DbPool dbPool
           
protected  java.security.MessageDigest digest
           
protected  java.lang.String groupColName
           
protected  I_Info info
           
private static java.util.logging.Logger log
           
protected  java.util.Map md5Map
           
protected  boolean poolOwner
           
protected  java.lang.String queryMeatStatement
           
protected  boolean tableExists
           
protected  java.util.Set touchSet
           
protected  boolean useGroupCol
           
 
Constructor Summary
MD5ChangeDetector()
          Default constructor, you need to call init(org.xmlBlaster.contrib.I_Info, org.xmlBlaster.contrib.dbwatcher.I_ChangeListener, org.xmlBlaster.contrib.dbwatcher.convert.I_DataConverter) thereafter.
MD5ChangeDetector(I_Info info, I_ChangeListener changeListener, I_DataConverter dataConverter)
          Convenience constructor which calls init(org.xmlBlaster.contrib.I_Info, org.xmlBlaster.contrib.dbwatcher.I_ChangeListener, org.xmlBlaster.contrib.dbwatcher.convert.I_DataConverter).
 
Method Summary
 int checkAgain(java.util.Map attrMap)
          Check the observed data for changes.
private  int checkComplete(java.sql.Connection conn, java.sql.ResultSet rs)
          The select statement contains no grouping.
private  int checkWithGroupCol(java.sql.Connection conn, java.sql.ResultSet rs)
          The select statement with grouping.
private  java.lang.String getMD5(java.lang.String value)
          Calculate the MD5 value.
 void init(I_Info info, I_ChangeListener changeListener, I_DataConverter dataConverter)
          Needs to be called after construction.
 void shutdown()
          Cleanup resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log

info

protected I_Info info

changeListener

protected I_ChangeListener changeListener

dataConverter

protected I_DataConverter dataConverter

dbPool

protected I_DbPool dbPool

poolOwner

protected boolean poolOwner

tableExists

protected boolean tableExists

digest

protected java.security.MessageDigest digest

md5Map

protected final java.util.Map md5Map

touchSet

protected final java.util.Set touchSet

changeDetectStatement

protected java.lang.String changeDetectStatement

groupColName

protected java.lang.String groupColName

useGroupCol

protected boolean useGroupCol

changeCount

protected int changeCount

queryMeatStatement

protected java.lang.String queryMeatStatement
Constructor Detail

MD5ChangeDetector

public MD5ChangeDetector()
Default constructor, you need to call init(org.xmlBlaster.contrib.I_Info, org.xmlBlaster.contrib.dbwatcher.I_ChangeListener, org.xmlBlaster.contrib.dbwatcher.convert.I_DataConverter) thereafter.


MD5ChangeDetector

public MD5ChangeDetector(I_Info info,
                         I_ChangeListener changeListener,
                         I_DataConverter dataConverter)
                  throws java.lang.Exception
Convenience constructor which calls init(org.xmlBlaster.contrib.I_Info, org.xmlBlaster.contrib.dbwatcher.I_ChangeListener, org.xmlBlaster.contrib.dbwatcher.convert.I_DataConverter).

Parameters:
info - The configuration environment
changeListener - The listener to notify if something has changed
dataConverter - A converter or null
Throws:
java.lang.Exception
Method Detail

init

public void init(I_Info info,
                 I_ChangeListener changeListener,
                 I_DataConverter dataConverter)
          throws java.lang.Exception
Needs to be called after construction.

Specified by:
init in interface I_ChangeDetector
Parameters:
info - The configuration
changeListener - The listener to notify if something has changed
dataConverter - If not null the data will be transformed immediately during change detection
Throws:
java.lang.Exception

checkAgain

public int checkAgain(java.util.Map attrMap)
               throws java.lang.Exception
Check the observed data for changes.

The method is synchronized so you can call it from the AlertScheduler or manually from outside simultaneously.

Specified by:
checkAgain in interface I_ChangeDetector
Parameters:
attrMap - This map can be null. The event source can transport some specific information to help the changeDetector doing its work efficiently.
Returns:
> 0 if the observed data has changed. If supported by the plugin the the number of changed rows,
Throws:
java.lang.Exception - Can be of any type
See Also:
I_ChangeDetector.checkAgain(Map)

checkComplete

private int checkComplete(java.sql.Connection conn,
                          java.sql.ResultSet rs)
                   throws java.lang.Exception
The select statement contains no grouping. CREATE and DROP are reliable, all other changes are marked as UPDATE.

Parameters:
rs - The JDBC query result
Returns:
The number of changes detected
Throws:
java.lang.Exception - of any type

checkWithGroupCol

private int checkWithGroupCol(java.sql.Connection conn,
                              java.sql.ResultSet rs)
                       throws java.lang.Exception
The select statement with grouping.

"CREATE" and "DROP" are reliable, all other changes "UPDATE", "INSERT" and "DELETE" are guessed and not reliable.

Note that for each removed groupColValue a "DROP" is issued even so the table still may exist.

Parameters:
rs - The JDBC query result
Returns:
The number of changes detected
Throws:
java.lang.Exception - of any type

getMD5

private java.lang.String getMD5(java.lang.String value)
Calculate the MD5 value.

Parameters:
value - The accumulated string to check
Returns:
The MD5 value

shutdown

public void shutdown()
              throws java.lang.Exception
Description copied from interface: I_ChangeDetector
Cleanup resources.

Specified by:
shutdown in interface I_ChangeDetector
Throws:
java.lang.Exception - Typicall XmlBlasterException
See Also:
org.xmlBlaster.contrib.dbwatcher.db.I_DbPool#shutdown

xmlBlaster 2.1.0 API

Copyright © 1999-2011 The xmlBlaster.org contributers.