xmlBlaster 2.2.0 API

org.xmlBlaster.contrib.dbwatcher.convert
Class ResultSetToXmlConverter

java.lang.Object
  extended by org.xmlBlaster.contrib.dbwatcher.convert.ResultSetToXmlConverter
All Implemented Interfaces:
I_DataConverter

public class ResultSetToXmlConverter
extends java.lang.Object
implements I_DataConverter

Creates a standardized XML dump from the given ResultSets.

Configurations are:

Here is an example XML dump, note that all meta data settings (like isNullable) are as described in JDBC (see ResultSetMetaData.java):

<?xml version='1.0' encoding='UTF-8' ?>
<sql>
 <desc>
  <command>INSERT</command>
  <ident>AFTN_CIRCUIT_STATE</ident>
  <colname type='DATE' nullable='0'>DATUM</colname>
  <colname type='NUMBER' precision='11' signed='false'>CPU</colname>
  <colname type='NUMBER' precision='10' scale='3'>OLG</colname>
  <colname type='VARCHAR2' precision='8' nullable='0'>FS_ST</colname>
 </desc>
 <row num='0'>
  <col name='DATUM'>2005-01-05 15:41:36.0</col>
  <col name='CPU'>238089</col>
  <col name='OLG'>-12.333</col>
  <col name='FS_ST'>GW</col>
  <attr name='SUBNET_ID'>TCP</attr>
  <attr name='CIRCUIT_STATE'>OPERATIVE</attr>
 </row>
 <row num='1'>
  <col name='DATUM'>2005-01-05 15:41:36.0</col>
  <col name='CPU'>238092</col>
  <col name='OLG'>1.513</col>
  <col name='FS_ST'>GW</col>
  <attr name='SUBNET_ID'>TCP</attr>
  <attr name='CIRCUIT_STATE'>OPERATIVE</attr>
 </row>
</sql>
 

The additional <attr> tags can be created by configuring an I_AttributeTransformer plugin.

This class is not thread save, use separate instances if used by multiple threads.

Author:
Marcel Ruff
See Also:
I_DataConverter

Field Summary
protected  boolean addMeta
           
protected  java.lang.String charSet
           
protected  java.lang.String command
           
protected  boolean commandIsAdded
           
protected  boolean doneCalled
           
protected  java.lang.String ident
           
private static java.util.logging.Logger log
           
private  int maxRows
           
protected  java.io.OutputStream out
           
protected  java.lang.String postStatement
           
protected  java.lang.String rootTag
           
protected  int rowCounter
           
private  long size
           
protected  I_AttributeTransformer transformer
           
 
Fields inherited from interface org.xmlBlaster.contrib.dbwatcher.convert.I_DataConverter
ALL, BASE64, IGNORE_MESSAGE, META_ONLY, ROW_ONLY
 
Constructor Summary
ResultSetToXmlConverter()
          Default constructor, you need to call init(info) thereafter.
ResultSetToXmlConverter(I_Info info)
          Create this plugin.
 
Method Summary
 void addInfo(java.sql.Connection conn, java.sql.ResultSet rs, int what)
          Add another result set to the XML string
 void addInfo(java.util.Map attributeMap)
          Add a map with attributes to the XML string.
 int done()
          After the last addInfo() call this method to complete the XML dump.
 long getCurrentMessageSize()
          Returns the size of the message as it is at the current moment
 java.lang.String getPostStatement()
          Gets the statement (if any) to be executed after processing one message.In case of the DbWatcher to be used to send/publish messages on detected changes, this can be used to delete entries in a queue.
static byte[] getResultSetAsXmlLiteral(java.sql.Connection conn, java.sql.ResultSet rs, java.lang.String command, java.lang.String ident, long maxRows)
           
 void init(I_Info info)
          Needs to be called after construction.
protected  int protectionNeeded(java.lang.String value)
          If value contains XML harmful characters it needs to be wrapped by CDATA or encoded to Base64.
 void setOutputStream(java.io.OutputStream out, java.lang.String command, java.lang.String ident, ChangeEvent event)
          This should be called before the first #addInfo(ResultSet) call.
 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

transformer

protected I_AttributeTransformer transformer

rootTag

protected java.lang.String rootTag

out

protected java.io.OutputStream out

command

protected java.lang.String command

ident

protected java.lang.String ident

rowCounter

protected int rowCounter

commandIsAdded

protected boolean commandIsAdded

doneCalled

protected boolean doneCalled

addMeta

protected boolean addMeta

postStatement

protected java.lang.String postStatement

charSet

protected java.lang.String charSet

maxRows

private int maxRows

size

private long size
Constructor Detail

ResultSetToXmlConverter

public ResultSetToXmlConverter()
Default constructor, you need to call init(info) thereafter.


ResultSetToXmlConverter

public ResultSetToXmlConverter(I_Info info)
                        throws java.lang.Exception
Create this plugin.

Parameters:
info - Possible configuration parameters you find in the class description
Throws:
java.lang.Exception - If transformer instantiation fails
Method Detail

init

public void init(I_Info info)
          throws java.lang.Exception
Description copied from interface: I_DataConverter
Needs to be called after construction.

Specified by:
init in interface I_DataConverter
Parameters:
info - The configuration environment
Throws:
java.lang.Exception
See Also:
I_DataConverter.init(I_Info)

setOutputStream

public void setOutputStream(java.io.OutputStream out,
                            java.lang.String command,
                            java.lang.String ident,
                            ChangeEvent event)
                     throws java.lang.Exception
This should be called before the first #addInfo(ResultSet) call.

Specified by:
setOutputStream in interface I_DataConverter
Parameters:
event - can be null since it is not used in this implementation.
out - The stream to dump the converted data to
command - An optional command string or null
ident - the identity or optionally null.
Throws:
java.lang.Exception - of any type
See Also:
org.xmlBlaster.contrib.dbwatcher.convert.I_DataConverter#setOutputStream(OutputStream, String, String)

addInfo

public void addInfo(java.util.Map attributeMap)
             throws java.lang.Exception
Add a map with attributes to the XML string.

Specified by:
addInfo in interface I_DataConverter
Parameters:
attributeMap - A map containing key/values to dump
Throws:
java.lang.Exception - of any type
See Also:
I_DataConverter.addInfo(Map)

addInfo

public void addInfo(java.sql.Connection conn,
                    java.sql.ResultSet rs,
                    int what)
             throws java.lang.Exception
Add another result set to the XML string

Specified by:
addInfo in interface I_DataConverter
rs - The JDBC result set
what - One of I_DataConverter.ALL, I_DataConverter.META_ONLY or I_DataConverter.ROW_ONLY. I_DataConverter.META_ONLY is useful for an empty table where rs access fails.
Throws:
java.lang.Exception - of any type
See Also:
org.xmlBlaster.contrib.dbwatcher.convert.I_DataConverter#addInfo(ResultSet, int)

protectionNeeded

protected int protectionNeeded(java.lang.String value)
If value contains XML harmful characters it needs to be wrapped by CDATA or encoded to Base64.

Parameters:
value - The string to verify
Returns:
0 No protection necessary 1 Protection with CDATA is needed 2 Protection with Base64 is needed

done

public int done()
         throws java.lang.Exception
Description copied from interface: I_DataConverter
After the last addInfo() call this method to complete the XML dump. The user needs to call I_DataConverter.setOutputStream(java.io.OutputStream, java.lang.String, java.lang.String, org.xmlBlaster.contrib.dbwatcher.ChangeEvent) again to reuse this instance.

Specified by:
done in interface I_DataConverter
Returns:
Number of processed ResultSets
Throws:
java.lang.Exception - typically java.io.UnsupportedEncodingException, java.io.IOException
See Also:
I_DataConverter.done()

shutdown

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

Specified by:
shutdown in interface I_DataConverter
Throws:
java.lang.Exception - of any type
See Also:
I_DataConverter.shutdown()

getPostStatement

public java.lang.String getPostStatement()
Description copied from interface: I_DataConverter
Gets the statement (if any) to be executed after processing one message.In case of the DbWatcher to be used to send/publish messages on detected changes, this can be used to delete entries in a queue. In such cases, after having sent the message, this post statement is executed by the DbWatcher. If the message could not be sent, this post statement is not invoked.

Specified by:
getPostStatement in interface I_DataConverter
Returns:
the String containing an sql statement to be executed shortly after the processed message has been finished. In normal cases this means after having published the change message.

getResultSetAsXmlLiteral

public static byte[] getResultSetAsXmlLiteral(java.sql.Connection conn,
                                              java.sql.ResultSet rs,
                                              java.lang.String command,
                                              java.lang.String ident,
                                              long maxRows)
                                       throws java.lang.Exception
Throws:
java.lang.Exception

getCurrentMessageSize

public long getCurrentMessageSize()
Description copied from interface: I_DataConverter
Returns the size of the message as it is at the current moment

Specified by:
getCurrentMessageSize in interface I_DataConverter
Returns:

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.