org.jaffa.tools.database
Class SyncSchema

java.lang.Object
  extended byorg.jaffa.tools.database.SyncSchema

public class SyncSchema
extends Object

This tool calculates the difference between two database schemas

This is an example of how it can be used


  try {
      SyncSchema s = new SyncSchema();
  
      s.setSourceDriverString("oracle.jdbc.driver.OracleDriver");
      s.setSourceConnection("jdbc:oracle:thin:@xxx.com:1521:source");
      s.setSourceUser("source");
      s.setSourcePassword("test");
      s.setSourceSchema("MySchema");
  
      s.setTargetDriverString("oracle.jdbc.driver.OracleDriver");
      s.setTargetConnection("jdbc:oracle:thin:@xxx.com:1521:target");
      s.setTargetUser("target");
      s.setTargetPassword("test");
      s.setTargetSchema("MySchema");
  
      s.setTableFilter("A%");
  
      s.process();
      Collection l = s.getTables();
      for(Iterator i = l.iterator(); i.hasNext(); ) {
          SyncSchema.Table t = (SyncSchema.Table) i.next();
          System.out.println("Schema:" + t.getSchema() + ", Table:" + t.getName() + " (" + t.getType() + ") [" + SyncSchema.getSyncName(t.getSyncStatus()) + "]");
          if(t.getFields() != null && t.getSyncStatus() == SyncSchema.TABLE_CHANGED ) {
              for(Iterator i2 = t.getFields().values().iterator(); i2.hasNext(); ) {
                  SyncSchema.Field f = (SyncSchema.Field) i2.next();
                  if(f.getSyncStatus() != SyncSchema.FIELD_SAME)
                  System.out.println("    " + f.getSeq() + "." + f.getName() + " [" + SyncSchema.getSyncName(f.getSyncStatus()) + "] - " + f.getChanges() );
              }
          }
      }
  } catch (Exception e) {
      e.printStackTrace();
  }
 

Version:
1.0
Author:
paule

Nested Class Summary
 class SyncSchema.Field
          Java bean to store Field information for
 class SyncSchema.Table
          Java bean to store Table information
 
Field Summary
static int FIELD_ADDDED
          Used on Field.getSyncStatus() to indicate this field has been added
static int FIELD_CHANGED
          Used on Field.getSyncStatus() to indicate this field has been changed some how
static int FIELD_CHANGED_SIZE
          Used on Field.getSyncStatus() to indicate this field has been changed in size, it may also have had other properties changed
static int FIELD_CHANGED_TYPE
          Used on Field.getSyncStatus() to indicate this field has had its data type changed.
static int FIELD_MOVED
          Used on Field.getSyncStatus() to indicate this field has been moved (i.e. its position in the table has moved due to additions or deletions before it)
static int FIELD_REMOVED
          Used on Field.getSyncStatus() to indicate this field has been removed
static int FIELD_SAME
          Used on Field.getSyncStatus() to indicate this field has not been changed
static int TABLE_ADDED
          Used on Table.getSyncStatus() to indicate this table has been added
static int TABLE_CHANGED
          Used on Table.getSyncStatus() to indicate this table has been changed
static int TABLE_REMOVED
          Used on Table.getSyncStatus() to indicate this table has been removed
static int TABLE_SAME
          Used on Table.getSyncStatus() to indicate this table has not been changed
 
Constructor Summary
SyncSchema()
          Creates a new instance of SyncSchema
 
Method Summary
 String getSourceConnection()
          Getter for property sourceConnection.
 String getSourceDriverString()
          Getter for property sourceDriverString.
 String getSourcePassword()
          Getter for property sourcePassword.
 String getSourceSchema()
          Getter for property sourceSchema.
 String getSourceUser()
          Getter for property sourceUser.
static String getSyncName(int sync)
          Get the description for a given SyncState value
 String getTableFilter()
          Getter for property tableFilter.
 Collection getTables()
          Get the list of processed tables
 String getTargetConnection()
          Getter for property targetConnection.
 String getTargetDriverString()
          Getter for property targetDriverString.
 String getTargetPassword()
          Getter for property targetPassword.
 String getTargetSchema()
          Getter for property targetSchema.
 String getTargetUser()
          Getter for property targetUser.
 void process()
          Run the main compare process.
 void setSourceConnection(String sourceConnection)
          Setter for property sourceConnection.
 void setSourceDriverString(String sourceDriverString)
          Setter for property sourceDriverString.
 void setSourcePassword(String sourcePassword)
          Setter for property sourcePassword.
 void setSourceSchema(String sourceSchema)
          Setter for property sourceSchema.
 void setSourceUser(String sourceUser)
          Setter for property sourceUser.
 void setTableFilter(String tableFilter)
          Setter for property tableFilter.
 void setTargetConnection(String targetConnection)
          Setter for property targetConnection.
 void setTargetDriverString(String targetDriverString)
          Setter for property targetDriverString.
 void setTargetPassword(String targetPassword)
          Setter for property targetPassword.
 void setTargetSchema(String targetSchema)
          Setter for property targetSchema.
 void setTargetUser(String targetUser)
          Setter for property targetUser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TABLE_ADDED

public static final int TABLE_ADDED
Used on Table.getSyncStatus() to indicate this table has been added

See Also:
Constant Field Values

TABLE_REMOVED

public static final int TABLE_REMOVED
Used on Table.getSyncStatus() to indicate this table has been removed

See Also:
Constant Field Values

TABLE_SAME

public static final int TABLE_SAME
Used on Table.getSyncStatus() to indicate this table has not been changed

See Also:
Constant Field Values

TABLE_CHANGED

public static final int TABLE_CHANGED
Used on Table.getSyncStatus() to indicate this table has been changed

See Also:
Constant Field Values

FIELD_REMOVED

public static final int FIELD_REMOVED
Used on Field.getSyncStatus() to indicate this field has been removed

See Also:
Constant Field Values

FIELD_ADDDED

public static final int FIELD_ADDDED
Used on Field.getSyncStatus() to indicate this field has been added

See Also:
Constant Field Values

FIELD_MOVED

public static final int FIELD_MOVED
Used on Field.getSyncStatus() to indicate this field has been moved (i.e. its position in the table has moved due to additions or deletions before it)

See Also:
Constant Field Values

FIELD_CHANGED

public static final int FIELD_CHANGED
Used on Field.getSyncStatus() to indicate this field has been changed some how

See Also:
Constant Field Values

FIELD_CHANGED_SIZE

public static final int FIELD_CHANGED_SIZE
Used on Field.getSyncStatus() to indicate this field has been changed in size, it may also have had other properties changed

See Also:
Constant Field Values

FIELD_CHANGED_TYPE

public static final int FIELD_CHANGED_TYPE
Used on Field.getSyncStatus() to indicate this field has had its data type changed. It may also have had other properties changed, including size

See Also:
Constant Field Values

FIELD_SAME

public static final int FIELD_SAME
Used on Field.getSyncStatus() to indicate this field has not been changed

See Also:
Constant Field Values
Constructor Detail

SyncSchema

public SyncSchema()
Creates a new instance of SyncSchema

Method Detail

process

public void process()
             throws Exception
Run the main compare process. Make sure you have called all the correct setters to configure the process. After this you can use getTables() to see the output

Throws:
Exception - General Exception thrown if there is a processing error. Typically the underlying exception is an SQLException.

getTables

public Collection getTables()
Get the list of processed tables

Returns:
A collection of tables, this is in a list sorted by table name

getSourceDriverString

public String getSourceDriverString()
Getter for property sourceDriverString.

Returns:
Value of property sourceDriverString.

setSourceDriverString

public void setSourceDriverString(String sourceDriverString)
Setter for property sourceDriverString.

Parameters:
sourceDriverString - New value of property sourceDriverString.

getTargetDriverString

public String getTargetDriverString()
Getter for property targetDriverString.

Returns:
Value of property targetDriveCrlass.

setTargetDriverString

public void setTargetDriverString(String targetDriverString)
Setter for property targetDriverString.

Parameters:
targetDriverString - New value of property targetDriverString.

getSourceConnection

public String getSourceConnection()
Getter for property sourceConnection.

Returns:
Value of property sourceConnection.

setSourceConnection

public void setSourceConnection(String sourceConnection)
Setter for property sourceConnection.

Parameters:
sourceConnection - New value of property sourceConnection.

getTargetConnection

public String getTargetConnection()
Getter for property targetConnection.

Returns:
Value of property targetConnection.

setTargetConnection

public void setTargetConnection(String targetConnection)
Setter for property targetConnection.

Parameters:
targetConnection - New value of property targetConnection.

getSourceUser

public String getSourceUser()
Getter for property sourceUser.

Returns:
Value of property sourceUser.

setSourceUser

public void setSourceUser(String sourceUser)
Setter for property sourceUser.

Parameters:
sourceUser - New value of property sourceUser.

getTargetUser

public String getTargetUser()
Getter for property targetUser.

Returns:
Value of property targetUser.

setTargetUser

public void setTargetUser(String targetUser)
Setter for property targetUser.

Parameters:
targetUser - New value of property targetUser.

getSourcePassword

public String getSourcePassword()
Getter for property sourcePassword.

Returns:
Value of property sourcePassword.

setSourcePassword

public void setSourcePassword(String sourcePassword)
Setter for property sourcePassword.

Parameters:
sourcePassword - New value of property sourcePassword.

getTargetPassword

public String getTargetPassword()
Getter for property targetPassword.

Returns:
Value of property targetPassword.

setTargetPassword

public void setTargetPassword(String targetPassword)
Setter for property targetPassword.

Parameters:
targetPassword - New value of property targetPassword.

getSyncName

public static String getSyncName(int sync)
Get the description for a given SyncState value

Parameters:
sync - sync code to get description for
Returns:
description of code

getTableFilter

public String getTableFilter()
Getter for property tableFilter.

Returns:
Value of property tableFilter.

setTableFilter

public void setTableFilter(String tableFilter)
Setter for property tableFilter.

Parameters:
tableFilter - New value of property tableFilter.

getSourceSchema

public String getSourceSchema()
Getter for property sourceSchema.

Returns:
Value of property sourceSchema.

setSourceSchema

public void setSourceSchema(String sourceSchema)
Setter for property sourceSchema.

Parameters:
sourceSchema - New value of property sourceSchema.

getTargetSchema

public String getTargetSchema()
Getter for property targetSchema.

Returns:
Value of property targetSchema.

setTargetSchema

public void setTargetSchema(String targetSchema)
Setter for property targetSchema.

Parameters:
targetSchema - New value of property targetSchema.


Copyright © 2002-2004 JAFFA Project.