fix(dameng): bound DBMS_OUTPUT connection setup

Closes #5849
This commit is contained in:
t8y2 committed 2026-08-11 14:11:11 +08:00
1 parent 85313e9c62
commit 0c6c1fada2
2 files changed
+34 -4

No files matched your search

@@ -32,6 +32,7 @@ import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLNonTransientConnectionException;
import java.sql.SQLRecoverableException;
import java.sql.SQLSyntaxErrorException;
import java.sql.SQLTimeoutException;
import java.sql.SQLTransientConnectionException;
import java.sql.SQLXML;
import java.sql.Statement;
@@ -48,6 +49,7 @@ import java.util.Set;
public final class DamengAgent extends AbstractJdbcAgent {
private static final String AGENT_VERSION = "9999.06.04.1-fix-default";
private static final int DBMS_OUTPUT_ENABLE_TIMEOUT_SECS = 5;
private static final String DAMENG_CLASSIFIED_OBJECT_TYPE_SQL =
"CASE WHEN o.OBJECT_TYPE = 'MATERIALIZED VIEW' OR (o.OBJECT_TYPE = 'VIEW' AND mv.MVIEW_NAME IS NOT NULL) "
+ "THEN 'MATERIALIZED_VIEW' ELSE o.OBJECT_TYPE END";
@@ -110,6 +112,7 @@ public final class DamengAgent extends AbstractJdbcAgent {
@Override
protected void afterPhysicalConnect(ConnectParams params, Connection connection) throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.setQueryTimeout(DBMS_OUTPUT_ENABLE_TIMEOUT_SECS);
statement.execute("BEGIN DBMS_OUTPUT.ENABLE(1000000); END;");
} catch (SQLException error) {
if (!isIgnorableDbmsOutputError(error)) {
@@ -131,7 +134,9 @@ public final class DamengAgent extends AbstractJdbcAgent {
for (Throwable current = error; current != null; current = current.getCause()) {
if (current instanceof SQLException sqlError) {
for (SQLException candidate = sqlError; candidate != null; candidate = candidate.getNextException()) {
if (candidate instanceof SQLFeatureNotSupportedException || candidate instanceof SQLSyntaxErrorException) {
if (candidate instanceof SQLFeatureNotSupportedException
|| candidate instanceof SQLSyntaxErrorException
|| candidate instanceof SQLTimeoutException) {
return true;
}
String sqlState = candidate.getSQLState();
@@ -18,6 +18,7 @@ import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLTimeoutException;
import java.sql.SQLTransientConnectionException;
import java.sql.Statement;
import java.util.ArrayList;
@@ -61,10 +62,12 @@ class DamengAgentTest extends JdbcFakeExecutionBehaviorTest {
@Test
void physicalConnectionsEnableDbmsOutputWithoutChangingUserSql() throws Exception {
List<String> executedSql = new ArrayList<>();
List<Integer> queryTimeouts = new ArrayList<>();
DamengAgent agent = new DamengAgent();
agent.afterPhysicalConnect(null, printMessageConnection(null, executedSql));
agent.afterPhysicalConnect(null, printMessageConnection(null, executedSql, queryTimeouts));
assertEquals(List.of(5), queryTimeouts);
assertEquals(List.of("BEGIN DBMS_OUTPUT.ENABLE(1000000); END;"), executedSql);
}
@@ -82,6 +85,16 @@ class DamengAgentTest extends JdbcFakeExecutionBehaviorTest {
));
}
@Test
void physicalConnectionsIgnoreTimedOutDbmsOutputInitialization() {
DamengAgent agent = new DamengAgent();
assertDoesNotThrow(() -> agent.afterPhysicalConnect(
null,
failingDbmsOutputConnection(new SQLTimeoutException("DBMS_OUTPUT enable timed out"))
));
}
@Test
void physicalConnectionsPropagateConnectionFailures() {
DamengAgent agent = new DamengAgent();
@@ -361,16 +374,25 @@ class DamengAgentTest extends JdbcFakeExecutionBehaviorTest {
}
private static Connection printMessageConnection(String printMessage, List<String> executedSql) {
return statementConnection(printMessage, executedSql, null);
return printMessageConnection(printMessage, executedSql, new ArrayList<>());
}
private static Connection printMessageConnection(
String printMessage,
List<String> executedSql,
List<Integer> queryTimeouts
) {
return statementConnection(printMessage, executedSql, queryTimeouts, null);
}
private static Connection failingDbmsOutputConnection(SQLException failure) {
return statementConnection(null, new ArrayList<>(), failure);
return statementConnection(null, new ArrayList<>(), new ArrayList<>(), failure);
}
private static Connection statementConnection(
String printMessage,
List<String> executedSql,
List<Integer> queryTimeouts,
SQLException executeFailure
) {
InvocationHandler statementHandler = (Object unused, Method method, Object[] args) -> {
@@ -381,6 +403,9 @@ class DamengAgentTest extends JdbcFakeExecutionBehaviorTest {
}
executedSql.add((String) args[0]);
return false;
case "setQueryTimeout":
queryTimeouts.add((Integer) args[0]);
return null;
case "getPrintMsg":
return printMessage;
case "getUpdateCount":