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);
}
}
});
}
Aggregations