提交 8acef7b9 authored 作者: Thomas Mueller's avatar Thomas Mueller

Source code formatting.

上级 7ac42788
...@@ -89,83 +89,83 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -89,83 +89,83 @@ public class AlterTableAlterColumn extends SchemaCommand {
} }
} }
switch (type) { switch (type) {
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_NOT_NULL: { case CommandInterface.ALTER_TABLE_ALTER_COLUMN_NOT_NULL: {
if (!oldColumn.isNullable()) { if (!oldColumn.isNullable()) {
// no change // no change
break;
}
checkNoNullValues();
oldColumn.setNullable(false);
db.update(session, table);
break; break;
} }
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_NULL: { checkNoNullValues();
if (oldColumn.isNullable()) { oldColumn.setNullable(false);
// no change db.update(session, table);
break; break;
} }
checkNullable(); case CommandInterface.ALTER_TABLE_ALTER_COLUMN_NULL: {
oldColumn.setNullable(true); if (oldColumn.isNullable()) {
db.update(session, table); // no change
break; break;
} }
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_DEFAULT: { checkNullable();
checkDefaultReferencesTable(defaultExpression); oldColumn.setNullable(true);
oldColumn.setSequence(null); db.update(session, table);
oldColumn.setDefaultExpression(session, defaultExpression); break;
removeSequence(sequence); }
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_DEFAULT: {
checkDefaultReferencesTable(defaultExpression);
oldColumn.setSequence(null);
oldColumn.setDefaultExpression(session, defaultExpression);
removeSequence(sequence);
db.update(session, table);
break;
}
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE: {
// if the change is only increasing the precision, then we don't
// need to copy the table because the length is only a constraint,
// and does not affect the storage structure.
if (oldColumn.isWideningConversion(newColumn)) {
convertAutoIncrementColumn(newColumn);
oldColumn.copy(newColumn);
db.update(session, table); db.update(session, table);
break; } else {
} oldColumn.setSequence(null);
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE: { oldColumn.setDefaultExpression(session, null);
// if the change is only increasing the precision, then we don't oldColumn.setConvertNullToDefault(false);
// need to copy the table because the length is only a constraint, if (oldColumn.isNullable() && !newColumn.isNullable()) {
// and does not affect the storage structure. checkNoNullValues();
if (oldColumn.isWideningConversion(newColumn)) { } else if (!oldColumn.isNullable() && newColumn.isNullable()) {
convertAutoIncrementColumn(newColumn); checkNullable();
oldColumn.copy(newColumn);
db.update(session, table);
} else {
oldColumn.setSequence(null);
oldColumn.setDefaultExpression(session, null);
oldColumn.setConvertNullToDefault(false);
if (oldColumn.isNullable() && !newColumn.isNullable()) {
checkNoNullValues();
} else if (!oldColumn.isNullable() && newColumn.isNullable()) {
checkNullable();
}
convertAutoIncrementColumn(newColumn);
copyData();
}
break;
}
case CommandInterface.ALTER_TABLE_ADD_COLUMN: {
// ifNotExists only supported for single column add
if (ifNotExists && columnsToAdd.size() == 1 && table.doesColumnExist(columnsToAdd.get(0).getName())) {
break;
}
for (Column column : columnsToAdd) {
convertAutoIncrementColumn(column);
} }
convertAutoIncrementColumn(newColumn);
copyData(); copyData();
break;
} }
case CommandInterface.ALTER_TABLE_DROP_COLUMN: { break;
if (table.getColumns().length == 1) { }
throw DbException.get(ErrorCode.CANNOT_DROP_LAST_COLUMN, oldColumn.getSQL()); case CommandInterface.ALTER_TABLE_ADD_COLUMN: {
} // ifNotExists only supported for single column add
table.dropSingleColumnConstraintsAndIndexes(session, oldColumn); if (ifNotExists && columnsToAdd.size() == 1 && table.doesColumnExist(columnsToAdd.get(0).getName())) {
copyData();
break; break;
} }
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_SELECTIVITY: { for (Column column : columnsToAdd) {
int value = newSelectivity.optimize(session).getValue(session).getInt(); convertAutoIncrementColumn(column);
oldColumn.setSelectivity(value);
db.update(session, table);
break;
} }
default: copyData();
DbException.throwInternalError("type=" + type); break;
}
case CommandInterface.ALTER_TABLE_DROP_COLUMN: {
if (table.getColumns().length == 1) {
throw DbException.get(ErrorCode.CANNOT_DROP_LAST_COLUMN, oldColumn.getSQL());
}
table.dropSingleColumnConstraintsAndIndexes(session, oldColumn);
copyData();
break;
}
case CommandInterface.ALTER_TABLE_ALTER_COLUMN_SELECTIVITY: {
int value = newSelectivity.optimize(session).getValue(session).getInt();
oldColumn.setSelectivity(value);
db.update(session, table);
break;
}
default:
DbException.throwInternalError("type=" + type);
} }
return 0; return 0;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论