use of org.jumpmind.db.alter.RemoveColumnChange in project symmetric-ds by JumpMind.
the class MySqlDdlBuilder 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) {
processChange(currentModel, desiredModel, (AddColumnChange) change, ddl);
changeIt.remove();
} else if (change instanceof ColumnAutoIncrementChange) {
/**
* This has to happen before any primary key changes because if
* a column is bring dropped as auto increment and being dropped
* from the primary key, an auto increment column can't be a non
* primary key column on mysql.
*/
try {
Column sourceColumn = ((ColumnAutoIncrementChange) change).getColumn();
Column targetColumn = (Column) sourceColumn.clone();
targetColumn.setAutoIncrement(!sourceColumn.isAutoIncrement());
processColumnChange(sourceTable, targetTable, sourceColumn, targetColumn, ddl);
changeIt.remove();
} catch (CloneNotSupportedException e) {
log.error("", e);
}
}
}
List<Column> changedColumns = new ArrayList<Column>();
// columns are present
for (Iterator<TableChange> changeIt = changes.iterator(); changeIt.hasNext(); ) {
TableChange change = changeIt.next();
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 AddPrimaryKeyChange) {
processChange(currentModel, desiredModel, (AddPrimaryKeyChange) change, ddl);
changeIt.remove();
} else if (change instanceof PrimaryKeyChange) {
processChange(currentModel, desiredModel, (PrimaryKeyChange) change, ddl);
changeIt.remove();
} else if (change instanceof RemovePrimaryKeyChange) {
processChange(currentModel, desiredModel, (RemovePrimaryKeyChange) change, ddl);
changeIt.remove();
} else if (change instanceof ColumnChange) {
/*
* we gather all changed columns because we can use the ALTER
* TABLE MODIFY COLUMN statement for them
*/
Column column = ((ColumnChange) change).getChangedColumn();
if (!changedColumns.contains(column)) {
changedColumns.add(column);
}
changeIt.remove();
}
}
for (Iterator<Column> columnIt = changedColumns.iterator(); columnIt.hasNext(); ) {
Column sourceColumn = columnIt.next();
Column targetColumn = targetTable.findColumn(sourceColumn.getName(), delimitedIdentifierModeOn);
processColumnChange(sourceTable, targetTable, sourceColumn, targetColumn, ddl);
}
}
use of org.jumpmind.db.alter.RemoveColumnChange 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);
}
Aggregations