|
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.Differences
public class Differences
Determines 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. To synchronize the tables use the Rectify class. The source can be either a table or a view but the target must be a table. While the tables do not need to structurally agree to perform a comparison, the column names used in the comparison must agree and be of the same type or an SQLException will be thrown.
HashMap Result Statistics
The differences found are returned in a HashMap structure that contains statistics related to the comparison
as well as lists of the actual differences. Each Differences HashMap contains the following:
Usage:
The simplest comparison 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 compare the tables 'emp' and 'emp2',
both of which are in the 'SCOTT' schema, we would simply create a HashMap as follows:
// Assume the database connection has already been defined and opened in the object 'conn' HashMap m = new Differences.getDifferences(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. For example:
String[] cols = new String[3]; cols[0] = "first_name"; cols[1] = "last_name"; cols[2] = "city"; HashMap m = Differences.getDifferences(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 = new Differences.getDifferences(conn, 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 Differences.getDifferences(conn1, conn2, "scott", "emp", whereClause, "scott", "emp2", whereClause, "emp_id", cols);
There are many variants that allow one or more database connections, where clause limitations, or specific column mappings. These are only a few examples of what is possible.
Rectify
Field Summary | |
---|---|
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 |
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 |
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 |
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 | |
---|---|
Differences()
Creates a new instance of Differences |
Method Summary | |
---|---|
HashMap |
getDifferences(Connection srcConn,
Connection tgtConn,
String srcOwner,
String srcTableName,
String tgtOwner,
String tgtTableName,
String whereClause,
String keyColumn,
String[] comparisonColumns)
Creates a response HashMap that outlines the differences between objects on two data sources using a limited rowset and specific comparison columns. |
HashMap |
getDifferences(Connection conn,
String srcOwner,
String srcTableName,
String tgtOwner,
String tgtTableName,
String keyColumn)
Creates a response HashMap that outlines the differences between objects on a single data source. |
HashMap |
getDifferences(Connection conn,
String srcOwner,
String srcTableName,
String tgtOwner,
String tgtTableName,
String keyColumn,
String[] comparisonColumns)
Creates a response HashMap that outlines the differences between objects on a single data source using specific comparison columns. |
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 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 SELF_SYNC_ERR
Constructor Detail |
---|
public Differences()
Method Detail |
---|
public HashMap getDifferences(Connection srcConn, Connection tgtConn, String srcOwner, String srcTableName, String tgtOwner, String tgtTableName, String whereClause, String keyColumn, String[] comparisonColumns) 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 rowsetkeyColumn
- field used as the key columncomparisonColumns
- array of fields used for the comparison
SQLException
public HashMap getDifferences(Connection conn, String srcOwner, String srcTableName, String tgtOwner, String tgtTableName, String keyColumn, String[] comparisonColumns) throws SQLException
This variant assumes that all columns except the key column are to be compared for equality on 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 columncomparisonColumns
- array of fields used for the comparison
SQLException
public HashMap getDifferences(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 |