|
MDi JLib 1.7.4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.microdeveloper.db.rectifier.Rectify
public class Rectify
Resolves the data differences between two tables in one or two Oracle databases. To use the class, you can minimally specify the owner and table name or you can specify the particular columns to compare with. Despite the comparison columns all columns are updated when reconciling differences. To compare the tables without changing the data use the Differences class. The source can be either a table or a view but the target must be a table. Unlike differences, the two objects must structurally agree or an SQLException will be thrown. It is possible to use a View as the source and a table as the destination but care must be taken to ensure that the table columns have sufficient size to accomodate the View data. Whe updating the target, the matching row is first deleted and a new row is inserted. An SQL update is not performed when reconciling differences.
Atomic Transactions
If desired, the synchronization can be perfromed as an atomic transaction (the default).
An atomic transaction only commits the work when all actions have been completed. For example, should an error occur
part way through the sync, all changes are rolled back when atomic is true. Conversely, when atomic is false, all
updates performed up to the point of error are committed. For large updates, the atomic transaction should perform
better as all DML is executed in batch whereas non-atomic transactions are executed and committed as needed.
HashMap Result Statistics
Like the Differences class, the deltas found and changed are returned in a HashMap structure that contains statistics related to the comparison
as well as lists of the actual differences that were affected. Each Differences HashMap contains the following:
Usage:
The simplest rectify usage would be where the two tables exist in the same database
and all of the columns and rows are used in the comparison. For example, to synchronize the tables 'emp' and 'emp2',
both of which are in the 'SCOTT' schema, we would use the short form of resolveDifferences as in:
// Assume the database connection has already been defined and opened in the object 'conn' HashMap m = new Rectify.resolveDifferences(conn, "scott", "emp", "scott", "emp2", "emp_id");
To limit the comparison, you can specify a list of columns to compare by supplying a singular array of column
names. If any of these columns differ, the entire row is updated in the target. For example:
String[] cols = new String[3]; cols[0] = "first_name"; cols[1] = "last_name"; cols[2] = "city"; HashMap m = new Rectify.resolveDifferences(conn, "scott", "emp", "scott", "emp2", "emp_id", cols);
You can also limit the rows compared by specifying the where clause. The where clause can be specified for either
the source, the target, or both. For example:
String whereClause = "WHERE mgr_id = '123'"; HashMap m = Rectify.resolveDifferences(conn, "scott", "emp", whereClause, "scott", "emp2", whereClause, "emp_id", cols);
You can compare across databases as well by specifyng more than one connection object. For example:
Connection conn1 = new Connector("orcl_1").getConnection(); Connection conn2 = new Connector("orcl_2").getConnection(); HashMap m = new Rectify.resolveDifferences(conn1, conn2, "scott", "emp", whereClause, "scott", "emp2", whereClause, "emp_id", cols);
In general, if the tables are large, it is better to truncate and replace the target than to synchronize. If, however, the target contains orphans that you wish to retain, synchronization is the only option.
Differences
Field Summary | |
---|---|
static String |
COLUMN_ERR
Error when attempting to fetch the column data |
static String |
DELETE_MAP_KEY
Key to the HashMap that contains the delete (target orphan) elements. |
static String |
DIFF_KEY
Key for the count of differing records |
static String |
DML_ERR
Error when exception is thrown during batch update |
static String |
ERROR_KEY
Key for the count of recoverable errors during the synchronization |
static String |
ERROR_MAP_KEY
Key to the HashMap that contains the data key elements that caused soft errors. |
static String |
FIELD_SEP_CHAR
Character sequence used to separate field values during comparison |
static String |
INSERT_MAP_KEY
Key to the HashMap that contains the insert (source orphan) elements. |
static String |
OBJECT_EXISTS_ERR
Error when a given object requested for comparison is not found for the connection given |
static String |
PROBLEM_MAP_KEY
Key to the HashMap that contains the data key elements with problems. |
static String |
SELF_SYNC_ERR
Error for when the source and the target are the same (self comparison) |
static String |
SOFT_ERROR_HALT
Error message used when a soft error is encountered and haltOnError is set to true |
static String |
SRC_CLOSED_ERR
Error when source database connection is not open |
static String |
SRC_COUNT_KEY
Key for the count of records compared from the source |
static String |
SRC_ORPHAN_KEY
Key for the count of orphan records in the source |
static String |
TGT_CLOSED_ERR
Error when target database connection is not open |
static String |
TGT_COUNT_KEY
Key for the count of records compared from the target |
static String |
TGT_ORPHAN_KEY
Key for the count of orphan records in the target |
static String |
TOO_FEW_DELETED_ERR
Error when too few rows are deleted during an update (should be 1 to 1) |
static String |
TOO_FEW_INSERTED_ERR
Error when too few rows are inserted during an update (should be 1 to 1) |
static String |
TOO_MANY_DELETED_ERR
Error when too many rows are deleted during an update (should be 1 to 1) |
static String |
TOO_MANY_INSERTED_ERR
Error when too many rows are inserted during an update (should be 1 to 1) |
static String |
UPDATE_MAP_KEY
Key to the HashMap that contains the updated (differing) elements. |
static String |
WARNING_KEY
Key for the count of warnings during the comparison |
Constructor Summary | |
---|---|
Rectify()
Creates a new instance of Rectify |
Method Summary | |
---|---|
HashMap |
resolveDifferences(Connection srcConn,
Connection tgtConn,
String srcOwner,
String srcTableName,
String tgtOwner,
String tgtTableName,
String whereClause,
String keyColumn,
String[] comparisonColumns,
boolean syncDeletes,
boolean haltOnError,
boolean atomic)
Synchronizes objects between two data sources using a filtered rowset and specific comparison columns with discreet control over the execution parameters. |
HashMap |
resolveDifferences(Connection conn,
String srcOwner,
String srcTableName,
String tgtOwner,
String tgtTableName,
String keyColumn)
Synchronizes objects between a single data source with default execution parameters. |
HashMap |
resolveDifferences(Connection conn,
String srcOwner,
String srcTableName,
String tgtOwner,
String tgtTableName,
String keyColumn,
boolean syncDeletes,
boolean haltOnError,
boolean atomic)
Synchronizes objects between a single data source with discreet control over the execution parameters. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String SRC_ORPHAN_KEY
public static final String TGT_ORPHAN_KEY
public static final String SRC_COUNT_KEY
public static final String TGT_COUNT_KEY
public static final String DIFF_KEY
public static final String WARNING_KEY
public static final String ERROR_KEY
public static final String ERROR_MAP_KEY
public static final String PROBLEM_MAP_KEY
public static final String INSERT_MAP_KEY
public static final String UPDATE_MAP_KEY
public static final String DELETE_MAP_KEY
public static final String FIELD_SEP_CHAR
public static final String SRC_CLOSED_ERR
public static final String TGT_CLOSED_ERR
public static final String OBJECT_EXISTS_ERR
public static final String COLUMN_ERR
public static final String SELF_SYNC_ERR
public static final String TOO_MANY_DELETED_ERR
public static final String TOO_MANY_INSERTED_ERR
public static final String DML_ERR
public static final String TOO_FEW_DELETED_ERR
public static final String TOO_FEW_INSERTED_ERR
public static final String SOFT_ERROR_HALT
Constructor Detail |
---|
public Rectify()
Method Detail |
---|
public HashMap resolveDifferences(Connection srcConn, Connection tgtConn, String srcOwner, String srcTableName, String tgtOwner, String tgtTableName, String whereClause, String keyColumn, String[] comparisonColumns, boolean syncDeletes, boolean haltOnError, boolean atomic) throws SQLException
srcConn
- connection to the source databasetgtConn
- connection to the target databasesrcOwner
- owning schema of the source table or viewsrcTableName
- source table or view nametgtOwner
- owning schema of the target tabletgtTableName
- target table namewhereClause
- where clause to limit rowset comparedkeyColumn
- field used as the key columncomparisonColumns
- array of fields used for the comparisonsyncDeletes
- true if target orphans should be removed otherwise false to ignore target orphanshaltOnError
- set to true if you want the synchronization to stop immediately when a soft error occurs.atomic
- set to true if you want the synchronization to be atomic (all or nothing).
SQLException
public HashMap resolveDifferences(Connection conn, String srcOwner, String srcTableName, String tgtOwner, String tgtTableName, String keyColumn, boolean syncDeletes, boolean haltOnError, boolean atomic) throws SQLException
This variant assumes that all columns except the key column are to be compared for equality.
conn
- connection to the source and target databasesrcOwner
- owning schema of the source table or viewsrcTableName
- source table or view nametgtOwner
- owning schema of the target tabletgtTableName
- target table namekeyColumn
- field used as the key columnsyncDeletes
- true if target orphans should be removed otherwise false to ignore target orphanshaltOnError
- set to true if you want the synchronization to stop immediately when a soft error occurs.atomic
- set to true if you want the synchronization to be atomic (all or nothing).
SQLException
public HashMap resolveDifferences(Connection conn, String srcOwner, String srcTableName, String tgtOwner, String tgtTableName, String keyColumn) throws SQLException
This variant assumes that all columns except the key column are to be compared for equality, all rows are to be compared, and that both the source and target exist within the same database.
conn
- connection to the source and target databasesrcOwner
- owning schema of the source table or viewsrcTableName
- source table or view nametgtOwner
- owning schema of the target tabletgtTableName
- target table namekeyColumn
- field used as the key column
SQLException
|
MDi JLib 1.7.4 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |