use of io.mycat.datasource.jdbc.datasource.JdbcConnectionManager 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.JdbcConnectionManager in project Mycat2 by MyCATApache.
the class DropIndexSQLHandler method onExecute.
@Override
protected Future<Void> onExecute(SQLRequest<SQLDropIndexStatement> request, MycatDataContext dataContext, Response response) {
LockService lockService = MetaClusterCurrent.wrapper(LockService.class);
return lockService.lock(DDL_LOCK, () -> {
try {
SQLDropIndexStatement sqlDropIndexStatement = request.getAst();
sqlDropIndexStatement.setIfExists(true);
String indexName = SQLUtils.normalize(sqlDropIndexStatement.getIndexName().toString());
resolveSQLExprTableSource(sqlDropIndexStatement.getTableName(), dataContext);
SQLExprTableSource tableSource = sqlDropIndexStatement.getTableName();
String schema = SQLUtils.normalize(tableSource.getSchema());
String tableName = SQLUtils.normalize(tableSource.getTableName());
MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
JdbcConnectionManager jdbcConnectionManager = MetaClusterCurrent.wrapper(JdbcConnectionManager.class);
TableHandler table = metadataManager.getTable(schema, tableName);
MySqlCreateTableStatement sqlStatement = (MySqlCreateTableStatement) SQLUtils.parseSingleMysqlStatement(table.getCreateTableSQL());
boolean updateShardingTable = false;
updateShardingTable = isUpdateShardingTable(indexName, sqlStatement, updateShardingTable);
if (!updateShardingTable) {
Set<Partition> partitions = getDataNodes(table);
try {
executeOnDataNodes(sqlDropIndexStatement, jdbcConnectionManager, partitions, tableSource);
} catch (Throwable e) {
LOGGER.error("", e);
}
}
// List<MySqlTableIndex> mysqlIndexes = sqlStatement.getMysqlIndexes();
// mysqlIndexes.stream().filter(i->SQLUtils.nameEquals(sqlDropIndexStatement.getIndexName(),i.getName())).findFirst()
// .ifPresent(c->mysqlIndexes.remove(c));
sqlStatement.apply(sqlDropIndexStatement);
CreateTableSQLHandler.INSTANCE.createTable(ImmutableMap.of(), schema, tableName, sqlStatement);
return response.sendOk();
} catch (Throwable throwable) {
return Future.failedFuture(throwable);
}
});
}
Aggregations