Search in sources :

Example 1 with CallbackClosure

use of org.jumpmind.db.util.CallbackClosure in project symmetric-ds by JumpMind.

the class AbstractDdlBuilder method processChanges.

/**
     * Processes the changes. The default argument performs several passes:
     * <ol>
     * <li>
     * {@link org.jumpmind.db.alter.RemoveForeignKeyChange} and
     * {@link org.jumpmind.db.alter.RemoveIndexChange} come first to allow for
     * e.g. subsequent primary key changes or column removal.</li>
     * <li>{@link org.jumpmind.db.alter.RemoveTableChange} comes after the
     * removal of foreign keys and indices.</li>
     * <li>These are all handled together:<br/>
     * {@link org.jumpmind.db.alter.RemovePrimaryKeyChange}<br/>
     * {@link org.jumpmind.db.alter.AddPrimaryKeyChange}<br/>
     * {@link org.jumpmind.db.alter.PrimaryKeyChange}<br/>
     * {@link org.jumpmind.db.alter.RemoveColumnChange}<br/>
     * {@link org.jumpmind.db.alter.AddColumnChange}<br/>
     * {@link org.jumpmind.db.alter.ColumnAutoIncrementChange} <br/>
     * {@link org.jumpmind.db.alter.ColumnDefaultValueChange} <br/>
     * {@link org.jumpmind.db.alter.ColumnRequiredChange}<br/>
     * {@link org.jumpmind.db.alter.ColumnDataTypeChange}<br/>
     * {@link org.jumpmind.db.alter.ColumnSizeChange}<br/>
     * The reason for this is that the default algorithm rebuilds the table for
     * these changes and thus their order is irrelevant.</li>
     * <li>{@link org.jumpmind.db.alter.AddTableChange}<br/>
     * needs to come after the table removal (so that tables of the same name
     * are removed) and before the addition of foreign keys etc.</li>
     * <li>{@link org.jumpmind.db.alter.AddForeignKeyChange} and
     * {@link org.jumpmind.db.alter.AddIndexChange} come last after
     * table/column/primary key additions or changes.</li>
     * </ol>
     */
@SuppressWarnings("unchecked")
protected void processChanges(Database currentModel, Database desiredModel, List<IModelChange> changes, StringBuilder ddl) {
    CallbackClosure callbackClosure = new CallbackClosure(this, "processChange", new Class[] { Database.class, Database.class, null, StringBuilder.class }, new Object[] { currentModel, desiredModel, null, ddl });
    // 1st pass: removing external constraints and indices
    applyForSelectedChanges(changes, new Class[] { RemoveForeignKeyChange.class, RemoveIndexChange.class }, callbackClosure);
    // 2nd pass: removing tables
    applyForSelectedChanges(changes, new Class[] { RemoveTableChange.class }, callbackClosure);
    // 3rd pass: changing the structure of tables
    Predicate predicate = new MultiInstanceofPredicate(new Class[] { RemovePrimaryKeyChange.class, AddPrimaryKeyChange.class, PrimaryKeyChange.class, RemoveColumnChange.class, AddColumnChange.class, ColumnAutoIncrementChange.class, ColumnDefaultValueChange.class, ColumnRequiredChange.class, ColumnDataTypeChange.class, ColumnSizeChange.class, CopyColumnValueChange.class });
    processTableStructureChanges(currentModel, desiredModel, CollectionUtils.select(changes, predicate), ddl);
    // 4th pass: adding tables
    applyForSelectedChanges(changes, new Class[] { AddTableChange.class }, callbackClosure);
    // 5th pass: adding external constraints and indices
    applyForSelectedChanges(changes, new Class[] { AddForeignKeyChange.class, AddIndexChange.class }, callbackClosure);
}
Also used : MultiInstanceofPredicate(org.jumpmind.db.util.MultiInstanceofPredicate) CallbackClosure(org.jumpmind.db.util.CallbackClosure) MultiInstanceofPredicate(org.jumpmind.db.util.MultiInstanceofPredicate) Predicate(org.apache.commons.collections.Predicate)

Aggregations

Predicate (org.apache.commons.collections.Predicate)1 CallbackClosure (org.jumpmind.db.util.CallbackClosure)1 MultiInstanceofPredicate (org.jumpmind.db.util.MultiInstanceofPredicate)1