xmlBlaster 2.2.0 API

org.xmlBlaster.contrib.replication
Class ReplicationConverter

java.lang.Object
  extended by org.xmlBlaster.contrib.replication.ReplicationConverter
All Implemented Interfaces:
ContribConstants, I_DataConverter, ReplicationConstants

public class ReplicationConverter
extends java.lang.Object
implements I_DataConverter, ReplicationConstants

Creates a standardized XML dump from the given ResultSets. Note this class is not thread safe, in other words you must make sure the same instance of this class can not be invoked concurently from more than one thread.

Author:
Michele Laghi
See Also:
I_DataConverter, ResultSetToXmlConverter

Field Summary
private  java.util.List allTransactions
          All transactions in this message (needed to delete entries after publishing)
private  I_DbPool dbPool
           
private  I_DbSpecific dbSpecific
           
private  ChangeEvent event
           
private  I_Info info
           
private static java.util.logging.Logger log
           
private  long messageSeq
           
private  java.lang.String messageSeqPropertyName
           
private  long newReplKey
           
private  long oldReplKey
           
private  java.lang.String oldReplKeyPropertyName
           
private  java.io.OutputStream out
           
private  I_Info persistentInfo
           
private  java.lang.String replPrefix
           
private  boolean sendInitialTableContent
           
private  boolean sendUnchangedUpdates
           
private  long size
           
private  SqlInfo sqlInfo
           
private  java.lang.String transactionId
           
private  I_AttributeTransformer transformer
           
private  long transSeq
           
private  java.lang.String transSeqPropertyName
           
private  boolean useReaderCharset
           
 
Fields inherited from interface org.xmlBlaster.contrib.dbwatcher.convert.I_DataConverter
ALL, BASE64, IGNORE_MESSAGE, META_ONLY, ROW_ONLY
 
Fields inherited from interface org.xmlBlaster.contrib.replication.ReplicationConstants
ABSOLUTE_COUNT, ACTION_ATTR, ALREADY_PROCESSED_ATTR, ALTER_ACTION, CATALOG_ATTR, CONTRIB_PERSISTENT_MAP, CREATE_ACTION, DB_ID_ATTR, DELETE_ACTION, DROP_ACTION, DUMP_ACTION, DUMP_CONTENT_ATTR, DUMP_FILENAME, DUMP_POSTFIX, END_OF_TRANSITION, EXCEPTION_ATTR, EXTRA_REPL_KEY_ATTR, GUID_ATTR, INITIAL_DATA_END, INITIAL_DATA_END_TO_REMOTE, INITIAL_DATA_ID, INITIAL_DUMP_AS_XML, INITIAL_FILES_LOCATION, INITIAL_UPDATE_COLLECT, INITIAL_UPDATE_ONLY_REGISTER, INITIAL_UPDATE_START_BATCH, INITIAL_XML_CMD, INSERT_ACTION, KEEP_TRANSACTION_OPEN, MASTER_ATTR, MAX_ENTRIES_ATTR, MESSAGE_SEQ, NUM_OF_TRANSACTIONS, OLD_CONTENT_ATTR, PURPOSE_REPLICATION, REPL_KEY_ATTR, REPL_MANAGER_SESSION, REPL_MANAGER_TOPIC, REPL_PREFIX_DEFAULT, REPL_PREFIX_GROUP_KEY, REPL_PREFIX_KEY, REPL_REQUEST_CANCEL_UPDATE, REPL_REQUEST_RECREATE_TRIGGERS, REPL_REQUEST_UPDATE, REPL_VERSION, REPLICATION_CMD, REPLICATION_FORCE_SENDING, REPLICATION_MAX_ENTRIES_DEFAULT, REPLICATION_MAX_ENTRIES_KEY, REPLICATION_SEND_UNCHANGED_UPDATES, REPLICATION_VERSION, REQUEST_BROADCAST_SQL_TOPIC, REQUEST_CANCEL_UPDATE_TOPIC, REQUEST_INITIAL_DATA_TOPIC, REQUEST_RECREATE_TRIGGERS, RESPONSE_INITIAL_DATA_TOPIC, SCHEMA_ATTR, SIMPLE_MESSAGE, SLAVE_NAME, SQL_TOPIC_ATTR, STATEMENT_ACTION, STATEMENT_ATTR, STATEMENT_ID_ATTR, STATEMENT_PRIO_ATTR, SUPPORTED_VERSIONS, TABLE_NAME_ATTR, TRANSACTION_ATTR, TRANSACTION_SEQ, UPDATE_ACTION, VERSION_ATTR, VERSION_TOKEN
 
Fields inherited from interface org.xmlBlaster.contrib.ContribConstants
FILE_DATE, FILENAME_ATTR, FILENAME_ATTR_OLD_FASHION, SUBDIR_ATTR, TIMESTAMP_ATTR, TOPIC_NAME
 
Constructor Summary
ReplicationConverter()
          Default constructor, you need to call init(info) thereafter.
ReplicationConverter(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()
          This method is invoked before sending the message over the mom.
private  java.lang.String getContent(java.sql.ResultSet rs, int clobPos)
           
 long getCurrentMessageSize()
          Returns the size of the message as it is at the current moment
static I_DbSpecific getDbSpecific(I_Info info, boolean forceNewIfNeeded)
          This method creates every time a new instance
private static java.util.Set getKeys(java.lang.String val, java.lang.String sep)
           
 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.
 void init(I_Info info)
          Needs to be called after construction.
 void setOutputStream(java.io.OutputStream out, java.lang.String command, java.lang.String ident, ChangeEvent event)
          This has to be called before the first I_DataConverter.addInfo(Map) or #addInfo(ResultSet, int) 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

dbSpecific

private I_DbSpecific dbSpecific

sqlInfo

private SqlInfo sqlInfo

info

private I_Info info

transformer

private I_AttributeTransformer transformer

out

private java.io.OutputStream out

sendInitialTableContent

private boolean sendInitialTableContent

oldReplKey

private long oldReplKey

persistentInfo

private I_Info persistentInfo

oldReplKeyPropertyName

private java.lang.String oldReplKeyPropertyName

event

private ChangeEvent event

transactionId

private java.lang.String transactionId

allTransactions

private java.util.List allTransactions
All transactions in this message (needed to delete entries after publishing)


replPrefix

private java.lang.String replPrefix

dbPool

private I_DbPool dbPool

transSeqPropertyName

private java.lang.String transSeqPropertyName

transSeq

private long transSeq

messageSeqPropertyName

private java.lang.String messageSeqPropertyName

messageSeq

private long messageSeq

newReplKey

private long newReplKey

sendUnchangedUpdates

private boolean sendUnchangedUpdates

useReaderCharset

private boolean useReaderCharset

size

private long size
Constructor Detail

ReplicationConverter

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


ReplicationConverter

public ReplicationConverter(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

getDbSpecific

public static I_DbSpecific getDbSpecific(I_Info info,
                                         boolean forceNewIfNeeded)
                                  throws java.lang.Exception
This method creates every time a new instance

Parameters:
info -
forceNewIfNeeded - if true and the entry is not found in the registry, a new object is created, initialized and added to the registry, otherwise it only returns entries found in the registry (without initializing the object) or null if none is found.
Returns:
Throws:
java.lang.Exception

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)

getKeys

private static java.util.Set getKeys(java.lang.String val,
                                     java.lang.String sep)

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()

getContent

private final java.lang.String getContent(java.sql.ResultSet rs,
                                          int clobPos)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

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. This method is invoked for each SQL Operation. Each transaction, i.e. each message can contain several such operations.

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)

addInfo

public void addInfo(java.util.Map attributeMap)
             throws java.lang.Exception
Description copied from interface: I_DataConverter
Add a map with attributes to the XML string. This is usually called by the I_AttributeTransformer class.

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

done

public int done()
         throws java.lang.Exception
This method is invoked before sending the message over the mom.

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

setOutputStream

public void setOutputStream(java.io.OutputStream out,
                            java.lang.String command,
                            java.lang.String ident,
                            ChangeEvent event)
                     throws java.lang.Exception
Description copied from interface: I_DataConverter
This has to be called before the first I_DataConverter.addInfo(Map) or #addInfo(ResultSet, int) call.

Specified by:
setOutputStream in interface I_DataConverter
Parameters:
out - The stream to dump the converted data to
command - An optional command string or null
ident - the identity or optionally null.
event - The ChangeEvent associated to this invocation. Is never null.
Throws:
java.lang.Exception - of any type

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.

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.