net.sf.hajdbc.sync
Class DifferentialSynchronizationStrategy
java.lang.Object
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:
- Drop the foreign keys on the inactive database (to avoid integrity constraint violations)
- For each database table:
- Drop the unique constraints on the table (to avoid integrity constraint violations)
- Find the primary key(s) of the table
- Query all rows in the inactive database table, sorting by the primary key(s)
- Query all rows on the active database table
- For each row in table:
- If primary key of the rows are the same, determine whether or not row needs to be updated
- Otherwise, determine whether row should be deleted, or a new row is to be inserted
- Re-create the unique constraints on the table (to avoid integrity constraint violations)
- Re-create the foreign keys on the inactive database
- Synchronize sequences
- Author:
- Paul Ferraro
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DifferentialSynchronizationStrategy
public DifferentialSynchronizationStrategy()
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.