xmlBlaster 2.2.0 contributions API

org.xmlBlaster.contrib.replication.impl
Class SpecificDefault

java.lang.Object
  extended by org.xmlBlaster.contrib.replication.impl.SpecificDefault
All Implemented Interfaces:
I_ContribPlugin, I_DbSpecific
Direct Known Subclasses:
SpecificDB2, SpecificDbReadonly, SpecificOracle, SpecificPostgres

public abstract class SpecificDefault
extends java.lang.Object
implements I_DbSpecific


Field Summary
protected  boolean blockLoop
           
static boolean COMMIT_NO
           
static boolean COMMIT_YES
           
protected  DbMetaHelper dbMetaHelper
           
protected  I_DbPool dbPool
           
protected  I_Info info
           
protected  InitialUpdater initialUpdater
           
protected  boolean isDbWriteable
           
protected  org.xmlBlaster.contrib.replication.impl.SpecificDefault.Replacer replacer
           
protected  org.xmlBlaster.util.ReplaceVariable replaceVariable
           
protected  java.lang.String replPrefix
           
protected  java.lang.String replVersion
           
static boolean ROLLBACK_NO
           
static boolean ROLLBACK_YES
           
protected  I_AttributeTransformer transformer
           
 
Fields inherited from interface org.xmlBlaster.contrib.replication.I_DbSpecific
NEEDS_PUBLISHER_KEY, WIPEOUT_ALL, WIPEOUT_FUNCTIONS, WIPEOUT_INDEXES, WIPEOUT_NO_TABLES, WIPEOUT_ONLY_TABLES, WIPEOUT_PACKAGES, WIPEOUT_PROCEDURES, WIPEOUT_SEQUENCES, WIPEOUT_SYNONYMS, WIPEOUT_TABLES, WIPEOUT_TRIGGERS, WIPEOUT_VIEWS
 
Constructor Summary
SpecificDefault()
          Not doing anything.
 
Method Summary
 boolean addTableToWatch(TableToWatchInfo firstTableToWatch, boolean force, java.lang.String[] destinations, boolean forceSend)
          Adds a table to be watcher/replicated.
 void addTrigger(java.sql.Connection conn, java.lang.String catalog, java.lang.String schema, java.lang.String tableName)
           
 void addTriggersIfNeeded(boolean force, java.lang.String[] destinations, boolean forceSend)
          If force is true, it deletes first all entries from the Tables table (kind of reset).
 void bootstrap(java.sql.Connection conn, boolean doWarn, boolean force)
          This method is invoked for the initial setup of the database.
 byte[] broadcastStatement(java.lang.String sql, long maxResponseEntries, boolean isHighPrio, boolean isMaster, java.lang.String sqlTopic, java.lang.String statementId)
          broadcasts a statement to be replicated.
 void cancelUpdate(java.lang.String replSlave)
          Tells the DbSpecific to cancel the ongoing initial update for the given slave.
 int checkSequenceForCreation(java.lang.String creationRequest)
          Checks if the sequence has to be created.
 int checkTableForCreation(java.lang.String creationRequest)
          Checks if the table has to be created.
 void checkTriggerConsistency(boolean doFix)
          Checks the consistency of the triggers.
 int checkTriggerForCreation(java.lang.String creationRequest)
          Checks if the trigger has to be created.
 void cleanup(java.sql.Connection conn, boolean doWarn)
          This method is invoked for the cleanup while testing.
 void clearCancelUpdate(java.lang.String replSlave)
          Tells the DbSpecific to clear the cancel flag for ongoing updates for the given slave.
 void forceTableChangeCheck()
          Invokes the function to check wether a table has been created, dropped or altered.
 java.util.List getContentFromClasspath(java.lang.String filename, java.lang.String method, java.lang.String flushSeparator, java.lang.String cmdSeparator)
           
 java.lang.String getCreateTableStatement(SqlDescription infoDescription, I_Mapper mapper)
          Returns the statement necessary to create a new table.
 java.lang.String getName()
          Returns a name identifying this SpecificDefault.
 java.lang.String getObjectName(java.lang.String op, java.lang.String req)
          Gets the specified object name and returns its value (name).
protected  java.lang.String getOwnSchema()
           
static java.lang.String getReplPrefix(I_Info info)
           
 java.util.Set getUsedPropertyKeys()
          Gets all property keys which may be used by this object.
 long incrementReplKey(java.sql.Connection conn)
          Increments and retreives the ${replPrefix}key sequence counter.
 void init(I_Info info)
           
 void initialCommand(java.lang.String[] slaveNames, java.lang.String completeFilename, java.lang.String version)
          This is the intial command which is invoked on the OS.
 void initialCommandPre()
          This is the command/script which is invoked before cleaning up resources on the initial update on the slave side (before the wipeout of the schema to be replicated).
 void initiateUpdate(java.lang.String topic, java.lang.String replManagerAddress, java.lang.String[] slaveNames, java.lang.String requestedVersion, java.lang.String initialFilesLocation)
          Initiates an initial update.
 boolean isDatasourceReadonly()
           
static void main(java.lang.String[] args)
          Example code.
 void readNewTable(java.lang.String catalog, java.lang.String schema, java.lang.String table, java.util.Map attrs, boolean sendInitialContents)
          Reads the metadata and content of the specified table.
protected  java.sql.Connection releaseIntoPool(java.sql.Connection conn, boolean doCommit)
          Always returns null (to nullify the connection).
static java.sql.Connection releaseIntoPool(java.sql.Connection conn, boolean doCommit, I_DbPool pool)
          Always returns null (to nullify the connection).
protected  java.sql.Connection removeFromPool(java.sql.Connection conn, boolean doRollback)
          Always returns null (to nullify the connection).
static java.sql.Connection removeFromPool(java.sql.Connection conn, boolean doRollback, I_DbPool pool)
          Always returns null (to nullify the connection).
 void removeSchemaTriggers(java.lang.String schema)
          Currently made public for testing.
 void removeTableToWatch(TableToWatchInfo tableToWatch, boolean removeAlsoSchemaTrigger)
          Removes a table from the repl_tables.
protected abstract  boolean sequenceExists(java.sql.Connection conn, java.lang.String sequenceName)
           
 void setAttributeTransformer(I_AttributeTransformer transformer)
           
 void shutdown()
           
static java.lang.String toString(java.lang.String[] str)
          Convenience method for nice output, also used to set the _destination property in the Client properties of a message.
protected abstract  boolean triggerExists(java.sql.Connection conn, java.lang.String triggerName)
           
protected  void updateFromFile(java.sql.Connection conn, java.lang.String method, java.lang.String propKey, java.lang.String propDefault, boolean doWarn, boolean force, org.xmlBlaster.contrib.replication.impl.SpecificDefault.Replacer repl)
          Reads the content to be executed from a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xmlBlaster.contrib.replication.I_DbSpecific
addSchemaToWatch, createTableTrigger, getColumnStatement, getContentFromGuid, removeTrigger, triggerExists, wipeoutSchema
 

Field Detail

ROLLBACK_YES

public static final boolean ROLLBACK_YES
See Also:
Constant Field Values

ROLLBACK_NO

public static final boolean ROLLBACK_NO
See Also:
Constant Field Values

COMMIT_YES

public static final boolean COMMIT_YES
See Also:
Constant Field Values

COMMIT_NO

public static final boolean COMMIT_NO
See Also:
Constant Field Values

info

protected I_Info info

dbPool

protected I_DbPool dbPool

dbMetaHelper

protected DbMetaHelper dbMetaHelper

replPrefix

protected java.lang.String replPrefix

replVersion

protected java.lang.String replVersion

replaceVariable

protected org.xmlBlaster.util.ReplaceVariable replaceVariable

replacer

protected org.xmlBlaster.contrib.replication.impl.SpecificDefault.Replacer replacer

initialUpdater

protected InitialUpdater initialUpdater

transformer

protected I_AttributeTransformer transformer

isDbWriteable

protected boolean isDbWriteable

blockLoop

protected boolean blockLoop
Constructor Detail

SpecificDefault

public SpecificDefault()
Not doing anything.

Method Detail

getContentFromClasspath

public java.util.List getContentFromClasspath(java.lang.String filename,
                                              java.lang.String method,
                                              java.lang.String flushSeparator,
                                              java.lang.String cmdSeparator)
                                       throws java.lang.Exception
Parameters:
filename -
method -
Returns:
List of String[]
Throws:
java.lang.Exception

getObjectName

public final java.lang.String getObjectName(java.lang.String op,
                                            java.lang.String req)
Gets the specified object name and returns its value (name). For example 'CREATE TABLE one' would return 'one'. Needed on bootstrapping. NOTE: only made public for testing purposes.

Parameters:
op -
req -
Returns:

checkTableForCreation

public final int checkTableForCreation(java.lang.String creationRequest)
                                throws java.lang.Exception
Checks if the table has to be created. If it is a 'CREATE TABLE' operation a non-negative value is returned, if it is another kind of operation, -1 is returned. If the table already exists, it returns zero. If the table does not exist, it returns 1. NOTE: only made public for testing purposes.

Parameters:
creationRequest - the sql request to analyze.
Returns:
Throws:
java.lang.Exception

sequenceExists

protected abstract boolean sequenceExists(java.sql.Connection conn,
                                          java.lang.String sequenceName)
                                   throws java.lang.Exception
Throws:
java.lang.Exception

triggerExists

protected abstract boolean triggerExists(java.sql.Connection conn,
                                         java.lang.String triggerName)
                                  throws java.lang.Exception
Throws:
java.lang.Exception

checkSequenceForCreation

public int checkSequenceForCreation(java.lang.String creationRequest)
                             throws java.lang.Exception
Checks if the sequence has to be created. If it is a 'CREATE SEQUENCE' operation a non-negative value is returned, if it is another kind of operation, -1 is returned. If the sequence already exists, it returns zero. If the sequence does not exist, it returns 1.

Parameters:
creationRequest - the sql request to analyze. NOTE: only made public for testing purposes.
Returns:
Throws:
java.lang.Exception

checkTriggerForCreation

public final int checkTriggerForCreation(java.lang.String creationRequest)
                                  throws java.lang.Exception
Checks if the trigger has to be created. If it is a 'CREATE TRIGGER' operation a non-negative value is returned, if it is another kind of operation, -1 is returned. If the triggger already exists, it returns zero. If the trigger does not exist, it returns 1.

Parameters:
creationRequest - the sql request to analyze. NOTE: only made public for testing purposes.
Returns:
Throws:
java.lang.Exception

toString

public static java.lang.String toString(java.lang.String[] str)
Convenience method for nice output, also used to set the _destination property in the Client properties of a message.

Parameters:
str -
Returns:

updateFromFile

protected void updateFromFile(java.sql.Connection conn,
                              java.lang.String method,
                              java.lang.String propKey,
                              java.lang.String propDefault,
                              boolean doWarn,
                              boolean force,
                              org.xmlBlaster.contrib.replication.impl.SpecificDefault.Replacer repl)
                       throws java.lang.Exception
Reads the content to be executed from a file.

Parameters:
conn - The connection on which to operate. Must not be null.
method - The method which uses this invocation (used for logging purposes).
propKey - The name (or key) of the property to retrieve. The content of this property is the bootstrap file name
propDefault - The default of the property.
force - if force is true it will add it no matter what (overwrites existing stuff), otherwise it will check for existence.
Throws:
java.lang.Exception - if an exception occurs when reading the bootstrap file. Note that in case of an exception you need to erase the connection from the pool (if you are using a pool)

bootstrap

public void bootstrap(java.sql.Connection conn,
                      boolean doWarn,
                      boolean force)
               throws java.lang.Exception
Description copied from interface: I_DbSpecific
This method is invoked for the initial setup of the database. In production this method is probably never called. Initial configuration (for example procedural configuration), creation of 'system tables' , 'system functions' and triggers (if any) is done here. We use the term 'system' to specify such elements which are used internally for the replication.

Specified by:
bootstrap in interface I_DbSpecific
doWarn - if false no warning is given on excrption.
force - if true, then everything is cleaned up, if false, then tables and sequences are only rebuilt if not existing.
Throws:
java.lang.Exception
See Also:
In case of an exception you need to cleanup the connection yourself.

cleanup

public void cleanup(java.sql.Connection conn,
                    boolean doWarn)
             throws java.lang.Exception
Description copied from interface: I_DbSpecific
This method is invoked for the cleanup while testing. In production this method is probably never called. Cleanup of initial configuration (for example procedural configuration), dropping of 'system tables' , 'system functions' and triggers (if any) is done here. We use the term 'system' to specify such elements which are used internally for the replication.

Specified by:
cleanup in interface I_DbSpecific
doWarn - if false no warning is given on excrption.
Throws:
java.lang.Exception
See Also:
In case of an exception you need to cleanup the connection yourself.

getUsedPropertyKeys

public final 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:
See Also:
I_ContribPlugin.getUsedPropertyKeys()

getName

public final java.lang.String getName()
Returns a name identifying this SpecificDefault. This is the replication.prefix.

Specified by:
getName in interface I_DbSpecific
Returns:

init

public void init(I_Info info)
          throws java.lang.Exception
Specified by:
init in interface I_ContribPlugin
Throws:
java.lang.Exception
See Also:
I_ContribPlugin.init(I_Info)

getOwnSchema

protected java.lang.String getOwnSchema()

checkTriggerConsistency

public void checkTriggerConsistency(boolean doFix)
                             throws java.lang.Exception
Checks the consistency of the triggers. If an entry is found in the TABLES table, and the table does not exist, nothing is done.

Specified by:
checkTriggerConsistency in interface I_DbSpecific
Throws:
java.lang.Exception

shutdown

public final void shutdown()
Specified by:
shutdown in interface I_ContribPlugin
See Also:
I_ContribPlugin.shutdown()

incrementReplKey

public long incrementReplKey(java.sql.Connection conn)
                      throws java.lang.Exception
Increments and retreives the ${replPrefix}key sequence counter. The connection must not be null. Description of sequences for oracle: http://www.lc.leidenuniv.nl/awcourse/oracle/server.920/a96540/statements_615a.htm#2067095

Specified by:
incrementReplKey in interface I_DbSpecific
Parameters:
conn -
Returns:
Throws:
java.lang.Exception
See Also:
I_DbSpecific.incrementReplKey(Connection)

addTrigger

public void addTrigger(java.sql.Connection conn,
                       java.lang.String catalog,
                       java.lang.String schema,
                       java.lang.String tableName)
                throws java.lang.Exception
Specified by:
addTrigger in interface I_DbSpecific
Throws:
java.lang.Exception
See Also:
org.xmlBlaster.contrib.replication.I_DbSpecific#addTrigger(java.sql.Connection, java.lang.String, java.lang.String, java.lang.String, org.xmlBlaster.contrib.dbwriter.info.SqlInfo)

readNewTable

public final void readNewTable(java.lang.String catalog,
                               java.lang.String schema,
                               java.lang.String table,
                               java.util.Map attrs,
                               boolean sendInitialContents)
                        throws java.lang.Exception
Description copied from interface: I_DbSpecific
Reads the metadata and content of the specified table. This is needed for database implementations which can not detect synchronously if a CREATE has been done or which can not register the necessary triggers on that newly created table.

Specified by:
readNewTable in interface I_DbSpecific
Parameters:
catalog - can be null
schema - can be null
table - can not be null
attrs - can be null
sendInitialContents - if true it will send all the contents of the added table, if false it will not send anything. So normally if you made a dump of the Database you don't want to send all the content of the tables again.
Throws:
java.lang.Exception
See Also:
I_DbSpecific#readNewTable(String, String, String, Map)

forceTableChangeCheck

public void forceTableChangeCheck()
                           throws java.lang.Exception
Description copied from interface: I_DbSpecific
Invokes the function to check wether a table has been created, dropped or altered.

Specified by:
forceTableChangeCheck in interface I_DbSpecific
Throws:
java.lang.Exception

addTableToWatch

public final boolean addTableToWatch(TableToWatchInfo firstTableToWatch,
                                     boolean force,
                                     java.lang.String[] destinations,
                                     boolean forceSend)
                              throws java.lang.Exception
Description copied from interface: I_DbSpecific
Adds a table to be watcher/replicated. It adds the entry to the repl_tables and makes sure that it is added with the correct case (depending upon how case sensitivity is handled by the implementation of the database).

Specified by:
addTableToWatch in interface I_DbSpecific
force - if true, then the trigger is added even if it exists already.
destinations - can be null. If it has to be sent to an individual client you pass its session name here. If you pass null, then it is published in pub/sub modus. If you want to publish it to more than one client, you pass more destinations.
forceSend - if true, all content data of the table will be sent.
Returns:
true if the table was added, false otherwise. If the table already was registered (added), then it will not add it anymore.
Throws:
java.lang.Exception - if an exception occurs on the backend. For example if the table already has been added, it will throw an exception.
See Also:
I_DbSpecific#addTableToWatch(String, String, String, String, String, boolean, String, boolean)

removeSchemaTriggers

public void removeSchemaTriggers(java.lang.String schema)
Currently made public for testing.

Parameters:
schema -

removeTableToWatch

public final void removeTableToWatch(TableToWatchInfo tableToWatch,
                                     boolean removeAlsoSchemaTrigger)
                              throws java.lang.Exception
Description copied from interface: I_DbSpecific
Removes a table from the repl_tables. This method will make sure that the correct case sensitivity for the table name will be used.

Specified by:
removeTableToWatch in interface I_DbSpecific
removeAlsoSchemaTrigger - if true it will also remove the associated schema trigger.
Throws:
java.lang.Exception
See Also:
I_DbSpecific#removeTableToWatch(String)

getCreateTableStatement

public final java.lang.String getCreateTableStatement(SqlDescription infoDescription,
                                                      I_Mapper mapper)
Description copied from interface: I_DbSpecific
Returns the statement necessary to create a new table.

Specified by:
getCreateTableStatement in interface I_DbSpecific
Parameters:
infoDescription - The description from which to create the statement.
mapper - the mapper to convert the table name (and in future the column names). Can be null, if null, no mapping is done.
Returns:
See Also:
I_DbSpecific.getCreateTableStatement(SqlDescription, I_Mapper)

addTriggersIfNeeded

public void addTriggersIfNeeded(boolean force,
                                java.lang.String[] destinations,
                                boolean forceSend)
                         throws java.lang.Exception
If force is true, it deletes first all entries from the Tables table (kind of reset).

Specified by:
addTriggersIfNeeded in interface I_DbSpecific
Parameters:
force - to force recreation of triggers even if they exist already.
Throws:
java.lang.Exception

initiateUpdate

public void initiateUpdate(java.lang.String topic,
                           java.lang.String replManagerAddress,
                           java.lang.String[] slaveNames,
                           java.lang.String requestedVersion,
                           java.lang.String initialFilesLocation)
                    throws java.lang.Exception
Description copied from interface: I_DbSpecific
Initiates an initial update. It is invoked by the InitialUpdater in asynchronous mode.

Specified by:
initiateUpdate in interface I_DbSpecific
replManagerAddress - the address to which to send acknowleges.
slaveNames - the name of the slave interested in these updates
requestedVersion - the version for which to start replication. If null the current version
initialFilesLocation - tells where to store the initial files in case the replication data has to be transfered manually by means of copying files. is ment.
Throws:
java.lang.Exception
See Also:
org.xmlBlaster.contrib.replication.I_DbSpecific#initiateUpdate(java.lang.String)

initialCommand

public void initialCommand(java.lang.String[] slaveNames,
                           java.lang.String completeFilename,
                           java.lang.String version)
                    throws java.lang.Exception
Description copied from interface: I_DbSpecific
This is the intial command which is invoked on the OS. It is basically used for the import and export of the DB. Could also be used for other operations on the OS. It is a helper method.

Specified by:
initialCommand in interface I_DbSpecific
Parameters:
slaveNames - an array containing the slaveNames to be updated. can be null.
completeFilename - the filename to be used to execute.
version - the version for which to start replication. If null the current version is ment.
Throws:
java.lang.Exception
See Also:
org.xmlBlaster.contrib.replication.I_DbSpecific#initialCommand(java.lang.String, java.lang.String)

initialCommandPre

public void initialCommandPre()
                       throws java.lang.Exception
Description copied from interface: I_DbSpecific
This is the command/script which is invoked before cleaning up resources on the initial update on the slave side (before the wipeout of the schema to be replicated).

Specified by:
initialCommandPre in interface I_DbSpecific
Throws:
java.lang.Exception - if an exception occurs when executing the script.
See Also:
I_DbSpecific.initialCommandPre()

broadcastStatement

public byte[] broadcastStatement(java.lang.String sql,
                                 long maxResponseEntries,
                                 boolean isHighPrio,
                                 boolean isMaster,
                                 java.lang.String sqlTopic,
                                 java.lang.String statementId)
                          throws java.lang.Exception
Description copied from interface: I_DbSpecific
broadcasts a statement to be replicated.

Specified by:
broadcastStatement in interface I_DbSpecific
isMaster - true if it is on the master side, i.e. in the DbWatcher. Then it will first put an entry in the ITEMS table and thereafter execute the statement.
sqlTopic - the topic on which the response will be published.
statementId - The unique Id identifying this statement. This will also be the topic on which the response is sent.
Returns:
a byte[] containing the response (an xml literal)
Throws:
java.lang.Exception
See Also:
org.xmlBlaster.contrib.replication.I_DbSpecific#broadcastStatement(java.lang.String, long, long, boolean, boolean, String, String)

removeFromPool

protected java.sql.Connection removeFromPool(java.sql.Connection conn,
                                             boolean doRollback)
Always returns null (to nullify the connection).

Parameters:
conn - The connection. Can be null, in which case nothing is done.
doRollback - if true, a rollback is done, on false no rollback is done.
Returns:
always null.

removeFromPool

public static java.sql.Connection removeFromPool(java.sql.Connection conn,
                                                 boolean doRollback,
                                                 I_DbPool pool)
Always returns null (to nullify the connection).

Parameters:
conn - The connection. Can be null, in which case nothing is done.
doRollback - if true, a rollback is done, on false no rollback is done.
pool - the pool to which the connection belongs.
Returns:
always null.

releaseIntoPool

protected java.sql.Connection releaseIntoPool(java.sql.Connection conn,
                                              boolean doCommit)
Always returns null (to nullify the connection).

Parameters:
conn - The connection. Can be null, in which case nothing is done.
doCommit - if true, a commit is done, on false no commit is done.
Returns:
always null.

releaseIntoPool

public static java.sql.Connection releaseIntoPool(java.sql.Connection conn,
                                                  boolean doCommit,
                                                  I_DbPool pool)
Always returns null (to nullify the connection).

Parameters:
conn - The connection. Can be null, in which case nothing is done.
doCommit - if true, a commit is done, on false no commit is done.
pool - the pool to which the connection belongs.
Returns:
always null.

cancelUpdate

public void cancelUpdate(java.lang.String replSlave)
Description copied from interface: I_DbSpecific
Tells the DbSpecific to cancel the ongoing initial update for the given slave.

Specified by:
cancelUpdate in interface I_DbSpecific
Parameters:
replSlave - the String identifying the slave name.
See Also:
I_DbSpecific.cancelUpdate(java.lang.String)

clearCancelUpdate

public void clearCancelUpdate(java.lang.String replSlave)
Description copied from interface: I_DbSpecific
Tells the DbSpecific to clear the cancel flag for ongoing updates for the given slave.

Specified by:
clearCancelUpdate in interface I_DbSpecific
Parameters:
replSlave - the String identifying the slave name.
See Also:
I_DbSpecific.clearCancelUpdate(java.lang.String)

getReplPrefix

public static java.lang.String getReplPrefix(I_Info info)

main

public static void main(java.lang.String[] args)
Example code.

java -Djava.util.logging.config.file=testlog.properties org.xmlBlaster.contrib.replication.ReplicationManager -db.password secret

Parameters:
args - Command line

setAttributeTransformer

public void setAttributeTransformer(I_AttributeTransformer transformer)
Specified by:
setAttributeTransformer in interface I_DbSpecific

isDatasourceReadonly

public boolean isDatasourceReadonly()
Specified by:
isDatasourceReadonly in interface I_DbSpecific

xmlBlaster 2.2.0 contributions API

Copyright © 1999-2014 The xmlBlaster.org contributers.