use of io.mycat.datasource.jdbc.datasource.DefaultConnection 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();
}
use of io.mycat.datasource.jdbc.datasource.DefaultConnection in project Mycat2 by MyCATApache.
the class CreateDatabaseSQLHandler method onPhysics.
protected void onPhysics(String sql) {
MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
JdbcConnectionManager jdbcConnectionManager = MetaClusterCurrent.wrapper(JdbcConnectionManager.class);
try (DefaultConnection connection = jdbcConnectionManager.getConnection(metadataManager.getPrototype())) {
connection.executeUpdate(sql, false);
} catch (Throwable t) {
LOGGER.warn("", t);
}
}
use of io.mycat.datasource.jdbc.datasource.DefaultConnection in project Mycat2 by MyCATApache.
the class RenameTableSQLHandler method executeOnDataNodes.
private void executeOnDataNodes(MySqlRenameTableStatement sqlStatement, JdbcConnectionManager connectionManager, Collection<Partition> partitions) {
for (Partition partition : partitions) {
MySqlRenameTableStatement each = cloneSql(sqlStatement);
String sql = each.toString();
try (DefaultConnection connection = connectionManager.getConnection(partition.getTargetName())) {
connection.executeUpdate(sql, false);
}
}
}
Aggregations