net.sf.hajdbc.sync
Class DifferentialSynchronizationStrategy

java.lang.Object
  extended by net.sf.hajdbc.sync.DifferentialSynchronizationStrategy
All Implemented Interfaces:
SynchronizationStrategy

public class DifferentialSynchronizationStrategy
extends Object
implements SynchronizationStrategy

Database-independent synchronization strategy that only updates differences between two databases. This strategy is best used when there are few differences between the active database and the inactive database (i.e. barely out of sync). The following algorithm is used:

  1. Drop the foreign keys on the inactive database (to avoid integrity constraint violations)
  2. For each database table:
    1. Drop the unique constraints on the table (to avoid integrity constraint violations)
    2. Find the primary key(s) of the table
    3. Query all rows in the inactive database table, sorting by the primary key(s)
    4. Query all rows on the active database table
    5. For each row in table:
      1. If primary key of the rows are the same, determine whether or not row needs to be updated
      2. Otherwise, determine whether row should be deleted, or a new row is to be inserted
    6. Re-create the unique constraints on the table (to avoid integrity constraint violations)
  3. Re-create the foreign keys on the inactive database
  4. Synchronize sequences

Author:
Paul Ferraro

Constructor Summary
DifferentialSynchronizationStrategy()
           
 
Method Summary
 int getFetchSize()
           
 int getMaxBatchSize()
           
 void setFetchSize(int fetchSize)
           
 void setMaxBatchSize(int maxBatchSize)
           
<D> void
synchronize(SynchronizationContext<D> context)
          Synchronizes a target database with a source database as defined by the synchronization context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DifferentialSynchronizationStrategy

public DifferentialSynchronizationStrategy()
Method Detail

synchronize

public <D> void synchronize(SynchronizationContext<D> context)
                 throws SQLException
Description copied from interface: SynchronizationStrategy
Synchronizes a target database with a source database as defined by the synchronization context.

Specified by:
synchronize in interface SynchronizationStrategy
Parameters:
context - a synchronization context
Throws:
SQLException - if synchronization fails
See Also:
SynchronizationStrategy.synchronize(net.sf.hajdbc.SynchronizationContext)

getFetchSize

public int getFetchSize()
Returns:
the fetchSize.

setFetchSize

public void setFetchSize(int fetchSize)
Parameters:
fetchSize - the fetchSize to set.

getMaxBatchSize

public int getMaxBatchSize()
Returns:
Returns the maxBatchSize.

setMaxBatchSize

public void setMaxBatchSize(int maxBatchSize)
Parameters:
maxBatchSize - The maxBatchSize to set.