xmlBlaster 2.2.0 contributions API

org.xmlBlaster.contrib.replication
Class SqlPrePostStatement

java.lang.Object
  extended by org.xmlBlaster.contrib.replication.SqlPrePostStatement
All Implemented Interfaces:
ContribConstants, I_PrePostStatement, I_ContribPlugin, ReplicationConstants

public class SqlPrePostStatement
extends java.lang.Object
implements I_PrePostStatement

SqlPrePostStatement allows the replication to execute a stored procedure before and / or after the operation on the replica (it is invoked as an optional plugin by the ReplicationWriter).

Author:
Michele Laghi

Field Summary
 
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
SqlPrePostStatement()
           
 
Method Summary
 java.util.Set getUsedPropertyKeys()
          Gets all property keys which may be used by this object.
 void init(I_Info info)
          Properties used are: dbWriter.sqlPrePostStatement.sql.pre.insert.${SCHEMA}.${TABLE} dbWriter.sqlPrePostStatement.sql.pre.update.${SCHEMA}.${TABLE} dbWriter.sqlPrePostStatement.sql.pre.delete.${SCHEMA}.${TABLE} dbWriter.sqlPrePostStatement.sql.post.insert.${SCHEMA}.${TABLE} dbWriter.sqlPrePostStatement.sql.post.update.${SCHEMA}.${TABLE} dbWriter.sqlPrePostStatement.sql.post.delete.${SCHEMA}.${TABLE}
 void postStatement(java.lang.String operation, java.sql.Connection conn, SqlInfo info, SqlDescription tableDescription, SqlRow currentRow)
          This method is invoked in the ReplicationWriter just after an INSERT, UPDATE, DELETE, CREATE, ALTER, DROP is invoked on the specified entry (the row).
 boolean preStatement(java.lang.String operation, java.sql.Connection conn, SqlInfo info, SqlDescription tableDescription, SqlRow currentRow)
          This method is invoked in the ReplicationWriter just before an INSERT, UPDATE or DELETE and CREATE, ALTER, DROP is invoked on the specified entry (the row).
 void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlPrePostStatement

public SqlPrePostStatement()
Method Detail

preStatement

public boolean preStatement(java.lang.String operation,
                            java.sql.Connection conn,
                            SqlInfo info,
                            SqlDescription tableDescription,
                            SqlRow currentRow)
                     throws java.lang.Exception
Description copied from interface: I_PrePostStatement
This method is invoked in the ReplicationWriter just before an INSERT, UPDATE or DELETE and CREATE, ALTER, DROP is invoked on the specified entry (the row). The user can manipulate the row, the sqlInfo or can perform some operations on the database. Note that the row has its state which is already modified when it comes to catalog, schema and table done by the mappers, but the row modification has not been done yet.

Specified by:
preStatement in interface I_PrePostStatement
Parameters:
operation - is the operation to be invoked for the statement. It can be one of the ReplicationConstants defined actions INSERT, UPDATE DELETE, CREATE, ALTER or DROP.
conn - The Database connection object. The implementor is not responsible for cleaning up the resource, this is done by the invoker.
tableDescription - the description (metadata) of the table from which the current table is coming from, if the row would contain entries (columns) coming from more than one table, then null is passed. The ReplicationWriter could also pass null if the operation is a CREATE and the table does not exist yet in the replica database. As this is created out of the metadata information of the destination, the catalog-, schema-, table- and column names are already the ones after any mapping modification.
currentRow - The row which currently will be processed. It can be null if the operation is a CREATE, ALTER or DROP. The columns specified in this row are already modified according to the mapping.
Returns:
true if the statement has to be executed, false otherwise (then the statement is not executed). If it returns false, then the postStatement is not executed either.
Throws:
java.lang.Exception - thrown if something went wrong in the implementation. If it is thrown, then the operation is not performed and a rollback of the entire transaction is done.

postStatement

public void postStatement(java.lang.String operation,
                          java.sql.Connection conn,
                          SqlInfo info,
                          SqlDescription tableDescription,
                          SqlRow currentRow)
                   throws java.lang.Exception
Description copied from interface: I_PrePostStatement
This method is invoked in the ReplicationWriter just after an INSERT, UPDATE, DELETE, CREATE, ALTER, DROP is invoked on the specified entry (the row). The user can manipulate the row, the sqlInfo or can perform some operations on the database. Note that the row has its state which is after any modification done by the mappers, i.e. its content corresponds to what the writer will write, not necessarly whatt the watcher has sent. This method is only invoked if preStatement returned true.

Specified by:
postStatement in interface I_PrePostStatement
Parameters:
operation - is the operation to be invoked for the statement. It can be one of the ReplicationConstants defined actions INSERT, UPDATE or DELETE, CREATE, ALTER or DROP.
conn - The Database connection object. The implementor is not responsible for cleaning up the resource, this is done by the invoker.
tableDescription - the description (metadata) of the table from which the current table is coming from, if the row would contain entries (columns) coming from more than one table, then null is passed. The ReplicationWriter could also pass null if the operation is a CREATE and the table does not exist yet in the replica database. As this is created out of the metadata information of the destination, the catalog-, schema-, table- and column names are already the ones after any mapping modification.
currentRow - The row which currently will be processed. It can be null if the operation is a CREATE, ALTER or DROP. The columns specified in this row are already modified according to the mapping.
Throws:
java.lang.Exception - thrown if something went wrong in the implementation. If it is thrown, then a rollback of the entire transaction is done.

getUsedPropertyKeys

public java.util.Set getUsedPropertyKeys()
Description copied from interface: I_ContribPlugin
Gets all property keys which may be used by this object.

Specified by:
getUsedPropertyKeys in interface I_ContribPlugin
Returns:

init

public void init(I_Info info)
          throws java.lang.Exception
Properties used are: dbWriter.sqlPrePostStatement.sql.pre.insert.${SCHEMA}.${TABLE} dbWriter.sqlPrePostStatement.sql.pre.update.${SCHEMA}.${TABLE} dbWriter.sqlPrePostStatement.sql.pre.delete.${SCHEMA}.${TABLE} dbWriter.sqlPrePostStatement.sql.post.insert.${SCHEMA}.${TABLE} dbWriter.sqlPrePostStatement.sql.post.update.${SCHEMA}.${TABLE} dbWriter.sqlPrePostStatement.sql.post.delete.${SCHEMA}.${TABLE}

Specified by:
init in interface I_ContribPlugin
Throws:
java.lang.Exception

shutdown

public void shutdown()
              throws java.lang.Exception
Specified by:
shutdown in interface I_ContribPlugin
Throws:
java.lang.Exception
See Also:
I_Plugin

xmlBlaster 2.2.0 contributions API

Copyright © 1999-2014 The xmlBlaster.org contributers.