Search in sources :

Example 1 with LockService

use of io.mycat.LockService in project Mycat2 by MyCATApache.

the class DropViewSQLHandler method onExecute.

@Override
protected Future<Void> onExecute(SQLRequest<SQLDropViewStatement> request, MycatDataContext dataContext, Response response) {
    LockService lockService = MetaClusterCurrent.wrapper(LockService.class);
    SQLDropViewStatement ast = request.getAst();
    SQLExprTableSource sqlExprTableSource = ast.getTableSources().get(0);
    resolveSQLExprTableSource(sqlExprTableSource, dataContext);
    return lockService.lock(DDL_LOCK, new Supplier<Future<Void>>() {

        @Override
        public Future<Void> get() {
            String schemaName = Optional.ofNullable(sqlExprTableSource.getSchema()).orElse(dataContext.getDefaultSchema());
            schemaName = SQLUtils.normalize(schemaName);
            String viewName = SQLUtils.normalize(sqlExprTableSource.getTableName());
            try (MycatRouterConfigOps ops = ConfigUpdater.getOps()) {
                ops.removeView(schemaName, viewName);
                ops.commit();
                return response.sendOk();
            } catch (Throwable throwable) {
                return Future.failedFuture(throwable);
            }
        }
    });
}
Also used : LockService(io.mycat.LockService) SQLDropViewStatement(com.alibaba.druid.sql.ast.statement.SQLDropViewStatement) Future(io.vertx.core.Future) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource) MycatRouterConfigOps(io.mycat.config.MycatRouterConfigOps)

Aggregations

SQLDropViewStatement (com.alibaba.druid.sql.ast.statement.SQLDropViewStatement)1 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)1 LockService (io.mycat.LockService)1 MycatRouterConfigOps (io.mycat.config.MycatRouterConfigOps)1 Future (io.vertx.core.Future)1