Search in sources :

Example 1 with ColumnRequiredChange

use of org.jumpmind.db.alter.ColumnRequiredChange in project symmetric-ds by JumpMind.

the class FirebirdDdlBuilder method processTableStructureChanges.

@Override
protected void processTableStructureChanges(Database currentModel, Database desiredModel, Table sourceTable, Table targetTable, List<TableChange> changes, StringBuilder ddl) {
    // TODO: Dropping of primary keys is currently not supported because we
    // cannot determine the pk constraint names and drop them in one go
    // (We could used a stored procedure if Firebird would allow them to use
    // DDL) This will be easier once named primary keys are supported
    boolean pkColumnAdded = false;
    for (Iterator<TableChange> changeIt = changes.iterator(); changeIt.hasNext(); ) {
        TableChange change = changeIt.next();
        if (change instanceof AddColumnChange) {
            AddColumnChange addColumnChange = (AddColumnChange) change;
            // add a new one afterwards which is not supported yet
            if (addColumnChange.getNewColumn().isPrimaryKey()) {
                pkColumnAdded = true;
            } else {
                processChange(currentModel, desiredModel, addColumnChange, ddl);
                changeIt.remove();
            }
        } else if (change instanceof RemoveColumnChange) {
            RemoveColumnChange removeColumnChange = (RemoveColumnChange) change;
            // add a new one afterwards which is not supported yet
            if (!removeColumnChange.getColumn().isPrimaryKey()) {
                processChange(currentModel, desiredModel, removeColumnChange, ddl);
                changeIt.remove();
            }
        } else if (change instanceof CopyColumnValueChange) {
            CopyColumnValueChange copyColumnChange = (CopyColumnValueChange) change;
            processChange(currentModel, desiredModel, copyColumnChange, ddl);
            changeIt.remove();
        } else if (change instanceof ColumnRequiredChange) {
            processChange(currentModel, desiredModel, (ColumnRequiredChange) change, ddl);
            changeIt.remove();
        }
    }
    for (Iterator<TableChange> changeIt = changes.iterator(); changeIt.hasNext(); ) {
        TableChange change = changeIt.next();
        // i.e. none was added during this alteration
        if ((change instanceof AddPrimaryKeyChange) && !pkColumnAdded) {
            processChange(currentModel, desiredModel, (AddPrimaryKeyChange) change, ddl);
            changeIt.remove();
        }
    }
    super.processTableStructureChanges(currentModel, desiredModel, sourceTable, targetTable, changes, ddl);
}
Also used : CopyColumnValueChange(org.jumpmind.db.alter.CopyColumnValueChange) RemoveColumnChange(org.jumpmind.db.alter.RemoveColumnChange) ColumnRequiredChange(org.jumpmind.db.alter.ColumnRequiredChange) AddPrimaryKeyChange(org.jumpmind.db.alter.AddPrimaryKeyChange) AddColumnChange(org.jumpmind.db.alter.AddColumnChange) TableChange(org.jumpmind.db.alter.TableChange)

Example 2 with ColumnRequiredChange

use of org.jumpmind.db.alter.ColumnRequiredChange in project symmetric-ds by JumpMind.

the class OracleDdlBuilder method processTableStructureChanges.

@Override
protected void processTableStructureChanges(Database currentModel, Database desiredModel, Table sourceTable, Table targetTable, List<TableChange> changes, StringBuilder ddl) {
    for (Iterator<TableChange> changeIt = changes.iterator(); changeIt.hasNext(); ) {
        TableChange change = changeIt.next();
        if (change instanceof AddColumnChange) {
            AddColumnChange addColumnChange = (AddColumnChange) change;
            if (addColumnChange.getNewColumn().isRequired() && (addColumnChange.getNewColumn().getDefaultValue() == null)) {
                // we need to rebuild the full table
                return;
            }
        } else if (change instanceof ColumnSizeChange) {
            processChange(currentModel, desiredModel, (ColumnSizeChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof ColumnDefaultValueChange) {
            processChange(currentModel, desiredModel, (ColumnDefaultValueChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof ColumnRequiredChange) {
            processChange(currentModel, desiredModel, (ColumnRequiredChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof ColumnAutoIncrementChange) {
            if (processChange(currentModel, desiredModel, (ColumnAutoIncrementChange) change, ddl)) {
                changeIt.remove();
            }
        }
    }
    // First we drop primary keys as necessary
    for (Iterator<TableChange> changeIt = changes.iterator(); changeIt.hasNext(); ) {
        TableChange change = changeIt.next();
        if (change instanceof RemovePrimaryKeyChange) {
            processChange(currentModel, desiredModel, (RemovePrimaryKeyChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof PrimaryKeyChange) {
            PrimaryKeyChange pkChange = (PrimaryKeyChange) change;
            RemovePrimaryKeyChange removePkChange = new RemovePrimaryKeyChange(pkChange.getChangedTable(), pkChange.getOldPrimaryKeyColumns());
            processChange(currentModel, desiredModel, removePkChange, ddl);
        }
    }
    /*
         * Next we add/remove columns While Oracle has an ALTER TABLE MODIFY
         * statement, it is somewhat limited esp. if there is data in the table,
         * so we don't use it
         */
    for (Iterator<TableChange> changeIt = changes.iterator(); changeIt.hasNext(); ) {
        TableChange change = changeIt.next();
        if (change instanceof AddColumnChange) {
            processChange(currentModel, desiredModel, (AddColumnChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof RemoveColumnChange) {
            processChange(currentModel, desiredModel, (RemoveColumnChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof CopyColumnValueChange) {
            CopyColumnValueChange copyColumnChange = (CopyColumnValueChange) change;
            processChange(currentModel, desiredModel, copyColumnChange, ddl);
            changeIt.remove();
        }
    }
    // Finally we add primary keys
    for (Iterator<TableChange> changeIt = changes.iterator(); changeIt.hasNext(); ) {
        TableChange change = changeIt.next();
        if (change instanceof AddPrimaryKeyChange) {
            processChange(currentModel, desiredModel, (AddPrimaryKeyChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof PrimaryKeyChange) {
            PrimaryKeyChange pkChange = (PrimaryKeyChange) change;
            AddPrimaryKeyChange addPkChange = new AddPrimaryKeyChange(pkChange.getChangedTable(), pkChange.getNewPrimaryKeyColumns());
            processChange(currentModel, desiredModel, addPkChange, ddl);
            changeIt.remove();
        }
    }
    super.processTableStructureChanges(currentModel, desiredModel, sourceTable, targetTable, changes, ddl);
}
Also used : ColumnDefaultValueChange(org.jumpmind.db.alter.ColumnDefaultValueChange) CopyColumnValueChange(org.jumpmind.db.alter.CopyColumnValueChange) RemovePrimaryKeyChange(org.jumpmind.db.alter.RemovePrimaryKeyChange) AddPrimaryKeyChange(org.jumpmind.db.alter.AddPrimaryKeyChange) PrimaryKeyChange(org.jumpmind.db.alter.PrimaryKeyChange) RemovePrimaryKeyChange(org.jumpmind.db.alter.RemovePrimaryKeyChange) ColumnRequiredChange(org.jumpmind.db.alter.ColumnRequiredChange) RemoveColumnChange(org.jumpmind.db.alter.RemoveColumnChange) ColumnAutoIncrementChange(org.jumpmind.db.alter.ColumnAutoIncrementChange) ColumnSizeChange(org.jumpmind.db.alter.ColumnSizeChange) AddPrimaryKeyChange(org.jumpmind.db.alter.AddPrimaryKeyChange) AddColumnChange(org.jumpmind.db.alter.AddColumnChange) TableChange(org.jumpmind.db.alter.TableChange)

Example 3 with ColumnRequiredChange

use of org.jumpmind.db.alter.ColumnRequiredChange in project symmetric-ds by JumpMind.

the class H2DdlBuilder method processTableStructureChanges.

@Override
protected void processTableStructureChanges(Database currentModel, Database desiredModel, Table sourceTable, Table targetTable, List<TableChange> changes, StringBuilder ddl) {
    for (Iterator<TableChange> changeIt = changes.iterator(); changeIt.hasNext(); ) {
        TableChange change = changeIt.next();
        if (change instanceof AddColumnChange) {
            AddColumnChange addColumnChange = (AddColumnChange) change;
            processChange(currentModel, desiredModel, addColumnChange, ddl);
            changeIt.remove();
        } else if (change instanceof CopyColumnValueChange) {
            CopyColumnValueChange copyColumnChange = (CopyColumnValueChange) change;
            processChange(currentModel, desiredModel, copyColumnChange, ddl);
            changeIt.remove();
        } else if (change instanceof RemoveColumnChange) {
            processChange(currentModel, desiredModel, (RemoveColumnChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof ColumnDefaultValueChange) {
            ColumnDefaultValueChange defaultChange = (ColumnDefaultValueChange) change;
            defaultChange.getChangedColumn().setDefaultValue(defaultChange.getNewDefaultValue());
            writeAlterColumn(change.getChangedTable(), defaultChange.getChangedColumn(), ddl);
            changeIt.remove();
        } else if (change instanceof ColumnRequiredChange) {
            ColumnRequiredChange defaultChange = (ColumnRequiredChange) change;
            defaultChange.getChangedColumn().setRequired(!defaultChange.getChangedColumn().isRequired());
            writeAlterColumn(change.getChangedTable(), defaultChange.getChangedColumn(), ddl);
            changeIt.remove();
        } else if (change instanceof ColumnSizeChange) {
            ColumnSizeChange sizeChange = (ColumnSizeChange) change;
            sizeChange.getChangedColumn().setSizeAndScale(sizeChange.getNewSize(), sizeChange.getNewScale());
            writeAlterColumn(change.getChangedTable(), sizeChange.getChangedColumn(), ddl);
            changeIt.remove();
        } else if (change instanceof ColumnAutoIncrementChange) {
            ColumnAutoIncrementChange defaultChange = (ColumnAutoIncrementChange) change;
            defaultChange.getColumn().setAutoIncrement(!defaultChange.getColumn().isAutoIncrement());
            writeAlterColumn(change.getChangedTable(), defaultChange.getColumn(), ddl);
            changeIt.remove();
        }
    }
    super.processTableStructureChanges(currentModel, desiredModel, sourceTable, targetTable, changes, ddl);
}
Also used : CopyColumnValueChange(org.jumpmind.db.alter.CopyColumnValueChange) ColumnDefaultValueChange(org.jumpmind.db.alter.ColumnDefaultValueChange) RemoveColumnChange(org.jumpmind.db.alter.RemoveColumnChange) ColumnRequiredChange(org.jumpmind.db.alter.ColumnRequiredChange) ColumnAutoIncrementChange(org.jumpmind.db.alter.ColumnAutoIncrementChange) ColumnSizeChange(org.jumpmind.db.alter.ColumnSizeChange) AddColumnChange(org.jumpmind.db.alter.AddColumnChange) TableChange(org.jumpmind.db.alter.TableChange)

Example 4 with ColumnRequiredChange

use of org.jumpmind.db.alter.ColumnRequiredChange in project symmetric-ds by JumpMind.

the class PostgreSqlDdlBuilder method processTableStructureChanges.

@Override
protected void processTableStructureChanges(Database currentModel, Database desiredModel, Table sourceTable, Table targetTable, List<TableChange> changes, StringBuilder ddl) {
    for (Iterator<TableChange> changeIt = changes.iterator(); changeIt.hasNext(); ) {
        TableChange change = changeIt.next();
        if (change instanceof AddColumnChange) {
            AddColumnChange addColumnChange = (AddColumnChange) change;
            processChange(currentModel, desiredModel, addColumnChange, ddl);
            changeIt.remove();
        } else if (change instanceof RemoveColumnChange) {
            processChange(currentModel, desiredModel, (RemoveColumnChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof CopyColumnValueChange) {
            CopyColumnValueChange copyColumnChange = (CopyColumnValueChange) change;
            processChange(currentModel, desiredModel, copyColumnChange, ddl);
            changeIt.remove();
        } else if (change instanceof ColumnDefaultValueChange) {
            processChange(currentModel, desiredModel, (ColumnDefaultValueChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof ColumnRequiredChange) {
            processChange(currentModel, desiredModel, (ColumnRequiredChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof ColumnSizeChange) {
            processChange(currentModel, desiredModel, (ColumnSizeChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof PrimaryKeyChange) {
            processChange(currentModel, desiredModel, (PrimaryKeyChange) change, ddl);
            changeIt.remove();
        } else if (change instanceof ColumnAutoIncrementChange) {
            if (processChange(currentModel, desiredModel, (ColumnAutoIncrementChange) change, ddl)) {
                changeIt.remove();
            }
        }
    }
    super.processTableStructureChanges(currentModel, desiredModel, sourceTable, targetTable, changes, ddl);
}
Also used : CopyColumnValueChange(org.jumpmind.db.alter.CopyColumnValueChange) ColumnDefaultValueChange(org.jumpmind.db.alter.ColumnDefaultValueChange) PrimaryKeyChange(org.jumpmind.db.alter.PrimaryKeyChange) RemoveColumnChange(org.jumpmind.db.alter.RemoveColumnChange) ColumnRequiredChange(org.jumpmind.db.alter.ColumnRequiredChange) ColumnAutoIncrementChange(org.jumpmind.db.alter.ColumnAutoIncrementChange) ColumnSizeChange(org.jumpmind.db.alter.ColumnSizeChange) AddColumnChange(org.jumpmind.db.alter.AddColumnChange) TableChange(org.jumpmind.db.alter.TableChange)

Aggregations

AddColumnChange (org.jumpmind.db.alter.AddColumnChange)4 ColumnRequiredChange (org.jumpmind.db.alter.ColumnRequiredChange)4 CopyColumnValueChange (org.jumpmind.db.alter.CopyColumnValueChange)4 RemoveColumnChange (org.jumpmind.db.alter.RemoveColumnChange)4 TableChange (org.jumpmind.db.alter.TableChange)4 ColumnAutoIncrementChange (org.jumpmind.db.alter.ColumnAutoIncrementChange)3 ColumnDefaultValueChange (org.jumpmind.db.alter.ColumnDefaultValueChange)3 ColumnSizeChange (org.jumpmind.db.alter.ColumnSizeChange)3 AddPrimaryKeyChange (org.jumpmind.db.alter.AddPrimaryKeyChange)2 PrimaryKeyChange (org.jumpmind.db.alter.PrimaryKeyChange)2 RemovePrimaryKeyChange (org.jumpmind.db.alter.RemovePrimaryKeyChange)1