org.afcs.warts.db
Class DataSynchronizationScript

java.lang.Object
  extended byorg.afcs.warts.db.DataSynchronization
      extended byorg.afcs.warts.db.DataSynchronizationScript

public final class DataSynchronizationScript
extends org.afcs.warts.db.DataSynchronization

The DataSynchronizationScript class is used to generate a preview of the SQL that will be executed by the DataSynchronizationAction class when two datasets are synchronized based on the analysis performed by a DataComparison instance.

Because of difficulties updating dates (precisely) and CLOB columns using scripts, running these scripts in a SQL tool will not guarantee proper data synchronization (it may work in simple cases).

LICENSE: This code is released to the public domain and may be used for any purpose whatsoever without permission or acknowledgment.

Version:
Last Modified 4 February 2004
Author:
Warren Hedley ( whedley at sdsc dot edu )

Field Summary
protected  DataComparison _comparison
          A reference to the comparison we're working with.
protected  TableDescription _destDescription
          The description of the table we're going to be manipulating.
protected  java.lang.String _destQualTableName
          The fully qualified name of the destination table (this is used in comments and debugging messages).
protected  java.lang.String _sourceQualTableName
          The fully qualified name of the source table that data is being moved from (this is used in comments and debugging messages).
 
Constructor Summary
DataSynchronizationScript(DataComparison comparison)
          Initialises a new instance that will generate synchronization scripts based on the specified data comparison.
 
Method Summary
protected  int countRowsOfType(int[] rowIndices, int type)
          Returns the number of rows in the specified array of indices that are of the specified type in the current comparison.
 java.lang.String generateDeleteScript(int[] rowsToSync)
          Returns a SQL delete script that will delete any rows found in dataset two that weren't in dataset one when the data comparison was performed and that have indices in the specified array.
 java.lang.String generateInsertScript(int[] rowsToSync)
          Returns a SQL insert script that will insert any rows not found in dataset two that were found in dataset one when the data comparison was performed and that have indices in the specified array.
 java.lang.String generateUpdateScript(int[] rowsToSync)
          Returns a SQL delete script that will update any rows found in both dataset one and two but with differing non-primary key column values when the data comparison was performed and that have indices in the specified array.
 java.lang.String toString()
          Returns a textual representation of the current instance useful for debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_comparison

protected final DataComparison _comparison
A reference to the comparison we're working with.


_destDescription

protected final TableDescription _destDescription
The description of the table we're going to be manipulating.


_destQualTableName

protected final java.lang.String _destQualTableName
The fully qualified name of the destination table (this is used in comments and debugging messages).


_sourceQualTableName

protected final java.lang.String _sourceQualTableName
The fully qualified name of the source table that data is being moved from (this is used in comments and debugging messages).

Constructor Detail

DataSynchronizationScript

public DataSynchronizationScript(DataComparison comparison)
Initialises a new instance that will generate synchronization scripts based on the specified data comparison.

Parameters:
comparison - The comparison to generate scripts for.
Throws:
java.lang.NullPointerException - If comparison is null.
Method Detail

generateDeleteScript

public java.lang.String generateDeleteScript(int[] rowsToSync)
Returns a SQL delete script that will delete any rows found in dataset two that weren't in dataset one when the data comparison was performed and that have indices in the specified array. (This allows clients to generate a script that will synchronize only a subset of the rows in a table.)

Parameters:
rowsToSync - The indices of the rows to synchronize. Only the row indices that represent deleted rows will be handled.
Returns:
A SQL delete script.
Throws:
java.lang.NullPointerException - If rowsToSync is null.

generateInsertScript

public java.lang.String generateInsertScript(int[] rowsToSync)
Returns a SQL insert script that will insert any rows not found in dataset two that were found in dataset one when the data comparison was performed and that have indices in the specified array. (This allows clients to generate a script that will synchronize only a subset of the rows in a table.)

Parameters:
rowsToSync - The indices of the rows to synchronize. Only the row indices that represent inserted rows will be handled.
Returns:
A SQL insert script.
Throws:
java.lang.NullPointerException - If rowsToSync is null.

generateUpdateScript

public java.lang.String generateUpdateScript(int[] rowsToSync)
Returns a SQL delete script that will update any rows found in both dataset one and two but with differing non-primary key column values when the data comparison was performed and that have indices in the specified array. (This allows clients to generate a script that will synchronize only a subset of the rows in a table.)

Parameters:
rowsToSync - The indices of the rows to synchronize. Only the row indices that represent updated rows will be handled.
Returns:
A SQL update script.
Throws:
java.lang.NullPointerException - If rowsToSync is null.

toString

public java.lang.String toString()
Returns a textual representation of the current instance useful for debugging.

Returns:
A textual representation of the current instance.

countRowsOfType

protected int countRowsOfType(int[] rowIndices,
                              int type)
Returns the number of rows in the specified array of indices that are of the specified type in the current comparison.

Parameters:
rowIndices - The array of row indices to scan.
type - The row type to count.
Returns:
The number of rows in the specified array of indices that are of the specified type in the current comparison.