Java Code Examples for com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableChangeColumn

The following examples show how to use com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableChangeColumn. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: DataLink   Source File: SQLStatementHolder.java    License: Apache License 2.0 6 votes vote down vote up
private boolean isColumnRenameSql(SQLAlterTableItem item) {
    if (item instanceof SQLAlterTableRenameColumn) {
        return true;
    }

    if (item instanceof MySqlAlterTableChangeColumn) {
        MySqlAlterTableChangeColumn cc = (MySqlAlterTableChangeColumn) item;
        String oldName = cc.getColumnName().getSimpleName();
        String newName = cc.getNewColumnDefinition().getName().getSimpleName();
        if (!oldName.equalsIgnoreCase(newName)) {// 新老列名不相等时才是rename
            return true;
        }
    }

    return false;
}
 
Example 2
Source Project: DataLink   Source File: SQLStatementHolder.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isAlterAffectSync() {
    if (sqlStatement instanceof SQLAlterTableStatement) {
        SQLAlterTableStatement alterStmt = (SQLAlterTableStatement) sqlStatement;
        for (SQLAlterTableItem item : alterStmt.getItems()) {
            if ((item instanceof SQLAlterTableRenameColumn) || (item instanceof MySqlAlterTableChangeColumn)
                    || (item instanceof SQLAlterTableDropColumnItem) || (item instanceof SQLAlterTableAddColumn)
                    || (item instanceof SQLAlterTableRename) || (item instanceof SQLAlterTableAlterColumn)
                    || (item instanceof MySqlAlterTableModifyColumn) || (item instanceof MySqlAlterTableAlterColumn)
                    || (item instanceof SQLAlterTableDropIndex) || (item instanceof SQLAlterTableAddIndex)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 3
Source Project: DataLink   Source File: SQLStatementHolder.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isAlterAffectColumn() {
    if (sqlStatement instanceof SQLAlterTableStatement) {
        SQLAlterTableStatement alterStmt = (SQLAlterTableStatement) sqlStatement;
        for (SQLAlterTableItem item : alterStmt.getItems()) {
            if ((item instanceof SQLAlterTableRenameColumn) || (item instanceof MySqlAlterTableChangeColumn)
                    || (item instanceof SQLAlterTableDropColumnItem) || (item instanceof SQLAlterTableAddColumn)
                    || (item instanceof SQLAlterTableAlterColumn) || (item instanceof MySqlAlterTableModifyColumn)
                    || (item instanceof MySqlAlterTableAlterColumn)
                    ) {
                return true;
            }
        }
    }
    return false;
}
 
Example 4
Source Project: DataLink   Source File: SQLStatementHolder.java    License: Apache License 2.0 5 votes vote down vote up
private boolean containsColumnModify() {
    if (sqlStatement instanceof SQLAlterTableStatement) {
        SQLAlterTableStatement alterStmt = (SQLAlterTableStatement) sqlStatement;
        for (SQLAlterTableItem item : alterStmt.getItems()) {
            if ((item instanceof MySqlAlterTableChangeColumn) || (item instanceof SQLAlterTableAlterColumn)
                    || (item instanceof MySqlAlterTableModifyColumn)
                    || (item instanceof MySqlAlterTableAlterColumn)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 5
Source Project: dble   Source File: DruidAlterTableParser.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public SchemaConfig visitorParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt, ServerSchemaStatVisitor visitor, ServerConnection sc, boolean isExplain)
        throws SQLException {
    SQLAlterTableStatement alterTable = (SQLAlterTableStatement) stmt;
    String schemaName = schema == null ? null : schema.getName();
    SchemaInfo schemaInfo = SchemaUtil.getSchemaInfo(sc.getUser(), schemaName, alterTable.getTableSource());
    boolean support = false;
    String msg = "The DDL is not supported, sql:";
    for (SQLAlterTableItem alterItem : alterTable.getItems()) {
        if (alterItem instanceof SQLAlterTableAddColumn ||
                alterItem instanceof SQLAlterTableDropKey ||
                alterItem instanceof SQLAlterTableDropPrimaryKey) {
            support = true;
        } else if (alterItem instanceof SQLAlterTableAddIndex ||
                alterItem instanceof SQLAlterTableDropIndex) {
            support = true;
            rrs.setOnline(true);
        } else if (alterItem instanceof SQLAlterTableAddConstraint) {
            SQLConstraint constraint = ((SQLAlterTableAddConstraint) alterItem).getConstraint();
            if (constraint instanceof MySqlPrimaryKey) {
                support = true;
            }
        } else if (alterItem instanceof MySqlAlterTableChangeColumn ||
                alterItem instanceof MySqlAlterTableModifyColumn ||
                alterItem instanceof SQLAlterTableDropColumnItem) {
            List<SQLName> columnList = new ArrayList<>();
            if (alterItem instanceof MySqlAlterTableChangeColumn) {
                columnList.add(((MySqlAlterTableChangeColumn) alterItem).getColumnName());
            } else if (alterItem instanceof MySqlAlterTableModifyColumn) {
                columnList.add(((MySqlAlterTableModifyColumn) alterItem).getNewColumnDefinition().getName());
            } else if (alterItem instanceof SQLAlterTableDropColumnItem) {
                columnList = ((SQLAlterTableDropColumnItem) alterItem).getColumns();
            }
            support = !this.columnInfluenceCheck(columnList, schemaInfo.getSchemaConfig(), schemaInfo.getTable());
            if (!support) {
                msg = "The columns may be sharding keys or ER keys, are not allowed to alter sql:";
            }
        }
    }
    if (!support) {
        msg = msg + stmt;
        throw new SQLNonTransientException(msg);
    }
    String statement = RouterUtil.removeSchema(rrs.getStatement(), schemaInfo.getSchema());
    rrs.setStatement(statement);
    String noShardingNode = RouterUtil.isNoShardingDDL(schemaInfo.getSchemaConfig(), schemaInfo.getTable());
    if (noShardingNode != null) {
        RouterUtil.routeToSingleDDLNode(schemaInfo, rrs, noShardingNode);
        return schemaInfo.getSchemaConfig();
    }
    RouterUtil.routeToDDLNode(schemaInfo, rrs);
    return schemaInfo.getSchemaConfig();
}