public class SchemaComparator
extends java.lang.Object
Usage:
SchemaComparator comparator = SchemaComparator.getInstanceExistingState(database);
ComparisonResult result = comparator.compareWithPrevious();
if (!result.isSame())
{
// Use changes provided by the result
}
In case it is required to reset the state (server restart, etc.) - this overwrites the last known state file:
SchemaComparator comparator = SchemaComparator.saveInitialState(database);
| Modifier and Type | Field and Description |
|---|---|
private static java.util.regex.Pattern |
COMMENT_EXTENT_COLUMN |
private Database |
database
Database reference - used for all connections; can't be changed in one instance of the comparator.
|
private static java.util.Collection<java.lang.String> |
EXCLUDED_TABLES
List of lower-case names of tables that should not be used in schema comparison.
|
private static java.io.File |
LAST_KNOWN_STATE_FILE
Path to file into which last known database state is serialized.
|
private static DatabaseState |
lastKnownState
In-memory storage of the last known state.
|
private static int |
MINIMUM_EXTENT_COLUMNS |
private static java.util.regex.Pattern |
PATTERN_EXTENT_COLUMN |
private static java.util.regex.Pattern |
PATTERN_EXTENT_TABLE |
private static boolean |
WRITE_KNOWN_STATE_FILE |
private static java.lang.String |
XML_ASCENDING |
private static java.lang.String |
XML_COLUMN |
private static java.lang.String |
XML_COLUMNS |
private static java.lang.String |
XML_COMMENT |
private static java.lang.String |
XML_DEFAULT |
private static java.lang.String |
XML_INDEX |
private static java.lang.String |
XML_NAME |
private static java.lang.String |
XML_NULLABLE |
private static java.lang.String |
XML_PRECISION |
private static java.lang.String |
XML_PRIMARY |
private static java.lang.String |
XML_SEQUENCE |
private static java.lang.String |
XML_SEQUENCES |
private static java.lang.String |
XML_TABLE |
private static java.lang.String |
XML_TABLES |
private static java.lang.String |
XML_TYPE |
private static java.lang.String |
XML_UNIQUE |
| Modifier | Constructor and Description |
|---|---|
private |
SchemaComparator(Database database)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
ComparisonResult |
compare(DatabaseState previousState)
Compare current state with given state.
|
ComparisonResult |
compareWithPrevious()
Compare current state with last known state.
|
void |
enrichExtentFields(ComparisonResult result)
EXTENT property of columns are stored in separate tables/columns (normalized/denormalized mode).
|
private void |
getAndCompareColumns(java.sql.Connection conn,
DatabaseState previousState,
ComparisonResult comparisonResult)
Load information on columns from the provided connection, put the state into result.
|
private void |
getAndCompareIndexes(java.sql.Connection conn,
DatabaseState previousState,
ComparisonResult comparisonResult)
Load information on indexes from the provided connection, put the state into result.
|
private void |
getAndCompareSequences(java.sql.Connection conn,
DatabaseState previousState,
ComparisonResult comparisonResult)
Load information on sequences from the provided connection, put the state into result.
|
private void |
getAndCompareTables(java.sql.Connection conn,
DatabaseState previousState,
ComparisonResult comparisonResult)
Load information on tables from the provided connection, put the state into result.
|
ComparisonResult |
getFreshResult()
Compare current state with an empty database state, effectively reporting everything found in the scan
as new.
|
static SchemaComparator |
getInstanceExistingState(Database database)
Get an instance of the Comparator, assuming the current database state file exists (it will be loaded
on demand).
|
(package private) DatabaseState |
getLastKnownState()
Load last persisted state.
|
void |
removeTableFromLastKnownState(Table table)
If table validation or DMO generation failed, this method can remove it from result so that it can be
loaded next time.
|
static SchemaComparator |
saveInitialState(Database database)
Get an instance of the Comparator, load the current database state for use in comparison.
|
(package private) void |
saveLastKnownState(DatabaseState newState)
Persist the database state.
|
private void |
updateResultByExtentColumn(ComparisonResult result,
Table table,
int extent,
java.lang.String baseName)
Update result to reflect detected EXTENT based on columns (denormalized mode).
|
private static final java.io.File LAST_KNOWN_STATE_FILE
private static final boolean WRITE_KNOWN_STATE_FILE
private static final java.util.regex.Pattern PATTERN_EXTENT_TABLE
private static final java.util.regex.Pattern PATTERN_EXTENT_COLUMN
private static final java.util.regex.Pattern COMMENT_EXTENT_COLUMN
private static final int MINIMUM_EXTENT_COLUMNS
private static final java.lang.String XML_TABLES
private static final java.lang.String XML_TABLE
private static final java.lang.String XML_COLUMNS
private static final java.lang.String XML_COLUMN
private static final java.lang.String XML_INDEX
private static final java.lang.String XML_ASCENDING
private static final java.lang.String XML_SEQUENCES
private static final java.lang.String XML_SEQUENCE
private static final java.lang.String XML_NAME
private static final java.lang.String XML_TYPE
private static final java.lang.String XML_PRECISION
private static final java.lang.String XML_NULLABLE
private static final java.lang.String XML_PRIMARY
private static final java.lang.String XML_UNIQUE
private static final java.lang.String XML_DEFAULT
private static final java.lang.String XML_COMMENT
private final Database database
private static DatabaseState lastKnownState
private static final java.util.Collection<java.lang.String> EXCLUDED_TABLES
private SchemaComparator(Database database)
database - Database reference.public static SchemaComparator saveInitialState(Database database) throws PersistenceException
database - Database to which to connect.PersistenceExceptionpublic static SchemaComparator getInstanceExistingState(Database database)
database - Database to which to connect.public ComparisonResult getFreshResult() throws PersistenceException
ComparisonResult instance.PersistenceException - if there is an error performing the JDBC scan.public ComparisonResult compareWithPrevious() throws PersistenceException
ComparisonResult instance.PersistenceException - if there is an error performing the JDBC scan.public ComparisonResult compare(DatabaseState previousState) throws PersistenceException
previousState - Previous known state for comparison.PersistenceException - if there is an error performing the JDBC scan.DatabaseState getLastKnownState() throws PersistenceException
PersistenceException - if there was an error reading the last known state, other than a file not found errorvoid saveLastKnownState(DatabaseState newState) throws PersistenceException
newState - Database state to persist.PersistenceExceptionprivate void getAndCompareTables(java.sql.Connection conn,
DatabaseState previousState,
ComparisonResult comparisonResult)
throws java.sql.SQLException
conn - Already initiated connection.previousState - Last known state.comparisonResult - Instance of result to be filled in.java.sql.SQLException - on unsuccessful calls to DB.private void getAndCompareColumns(java.sql.Connection conn,
DatabaseState previousState,
ComparisonResult comparisonResult)
throws java.sql.SQLException
conn - Already initiated connection.previousState - Last known state.comparisonResult - Instance of result to be filled in.java.sql.SQLException - on unsuccessful calls to DB.private void getAndCompareIndexes(java.sql.Connection conn,
DatabaseState previousState,
ComparisonResult comparisonResult)
throws java.sql.SQLException
conn - Already initiated connection.previousState - Last known state.comparisonResult - Instance of result to be filled in.java.sql.SQLException - On unsuccessful calls to DB.private void getAndCompareSequences(java.sql.Connection conn,
DatabaseState previousState,
ComparisonResult comparisonResult)
throws java.sql.SQLException
conn - Already initiated connection.previousState - Last known state.comparisonResult - Instance of result to be filled in.java.sql.SQLException - on unsuccessful calls to DB.public void removeTableFromLastKnownState(Table table) throws PersistenceException
table - failing tablePersistenceException - only thrown if file storage is enabled and writing it failspublic void enrichExtentFields(ComparisonResult result)
result - Original comparison resultprivate void updateResultByExtentColumn(ComparisonResult result, Table table, int extent, java.lang.String baseName)
result - Original comparison resulttable - Table containing extent columnsextent - Calculated extent valuebaseName - Calculated name of the base column