Search in sources :

Example 1 with SQLDropProcedureStatement

use of com.alibaba.druid.sql.ast.statement.SQLDropProcedureStatement in project Mycat2 by MyCATApache.

the class SQLDropProcedureHandler method onExecute.

@Override
@SneakyThrows
protected Future<Void> onExecute(SQLRequest<SQLDropProcedureStatement> request, MycatDataContext dataContext, Response response) {
    SQLDropProcedureStatement ast = request.getAst();
    if (ast.getName() instanceof SQLIdentifierExpr) {
        String defaultSchema = dataContext.getDefaultSchema();
        if (defaultSchema != null) {
            ast.setName(new SQLPropertyExpr(defaultSchema, ((SQLIdentifierExpr) ast.getName()).getName()));
        }
    }
    if (!(ast.getName() instanceof SQLPropertyExpr)) {
        throw new IllegalArgumentException("unknown schema:");
    }
    SQLPropertyExpr pNameExpr = (SQLPropertyExpr) ast.getName();
    String schemaName = SQLUtils.normalize(pNameExpr.getOwnerName().toLowerCase());
    String pName = SQLUtils.normalize(pNameExpr.getName().toLowerCase());
    try (MycatRouterConfigOps ops = ConfigUpdater.getOps()) {
        ops.removeProcedure(schemaName, pName);
        ops.commit();
    }
    JdbcConnectionManager jdbcConnectionManager = MetaClusterCurrent.wrapper(JdbcConnectionManager.class);
    try (DefaultConnection connection = jdbcConnectionManager.getConnection(MetadataManager.getPrototype())) {
        connection.executeUpdate(ast.toString(), false);
    }
    return response.sendOk();
}
Also used : SQLDropProcedureStatement(com.alibaba.druid.sql.ast.statement.SQLDropProcedureStatement) DefaultConnection(io.mycat.datasource.jdbc.datasource.DefaultConnection) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) MycatRouterConfigOps(io.mycat.config.MycatRouterConfigOps) JdbcConnectionManager(io.mycat.datasource.jdbc.datasource.JdbcConnectionManager) SneakyThrows(lombok.SneakyThrows)

Aggregations

SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)1 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)1 SQLDropProcedureStatement (com.alibaba.druid.sql.ast.statement.SQLDropProcedureStatement)1 MycatRouterConfigOps (io.mycat.config.MycatRouterConfigOps)1 DefaultConnection (io.mycat.datasource.jdbc.datasource.DefaultConnection)1 JdbcConnectionManager (io.mycat.datasource.jdbc.datasource.JdbcConnectionManager)1 SneakyThrows (lombok.SneakyThrows)1