Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(jdbc): enable Phoenix auto-commit

t8y29a255aa1352b
diff --git a/plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java b/plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java
index 2bdd33e22a..3b943dee3a 100644
--- a/plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java
+++ b/plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java
@@ -519,10 +519,27 @@ public final class DbxJdbcPlugin {
applyOracleProperties(connection, properties);
}
sharedConnection = DriverManager.getConnection(url, properties);
+ configurePhoenixAutoCommit(connection, url, sharedConnection);
sharedConnectionKey = key;
return sharedConnection;
}
+ private static void configurePhoenixAutoCommit(JsonNode connection, String url, Connection jdbcConnection)
+ throws SQLException {
+ if (!isPhoenixConnection(connection, url) || jdbcConnection.getAutoCommit()) {
+ return;
+ }
+ jdbcConnection.setAutoCommit(true);
+ }
+
+ private static boolean isPhoenixConnection(JsonNode connection, String url) {
+ if (urlMatchesPrefix(url, "jdbc:phoenix:")) {
+ return true;
+ }
+ String driverClass = optionalText(connection, "jdbc_driver_class");
+ return driverClass != null && driverClass.equalsIgnoreCase("org.apache.phoenix.jdbc.PhoenixDriver");
+ }
+
private static void applyJdbcxExtensionSecurity(JsonNode connection, String url, Properties properties) {
if (isJdbcxUrl(url) && !jdbcxHighPrivilegeExtensionsEnabled(connection)) {
properties.setProperty(JDBCX_EXTENSION_WHITELIST_PROPERTY, JDBCX_SAFE_EXTENSION_WHITELIST);
diff --git a/plugins/jdbc/src/test/java/app/dbx/jdbc/DbxJdbcPluginTest.java b/plugins/jdbc/src/test/java/app/dbx/jdbc/DbxJdbcPluginTest.java
index e2a617ecd0..b3567f3221 100644
--- a/plugins/jdbc/src/test/java/app/dbx/jdbc/DbxJdbcPluginTest.java
+++ b/plugins/jdbc/src/test/java/app/dbx/jdbc/DbxJdbcPluginTest.java
@@ -522,6 +522,69 @@ final class DbxJdbcPluginTest {
assertFalse(properties.containsKey("connectTimeout"));
}
+ @Test
+ void phoenixConnectionsEnableAutoCommitWhenDriverDefaultsToManualTransactions() throws Exception {
+ Method method = DbxJdbcPlugin.class.getDeclaredMethod(
+ "configurePhoenixAutoCommit",
+ JsonNode.class,
+ String.class,
+ Connection.class
+ );
+ method.setAccessible(true);
+ List<String> calls = new ArrayList<>();
+ JsonNode connection = MAPPER.readTree("""
+ {
+ "connection_string": "jdbc:phoenix:localhost"
+ }
+ """);
+
+ method.invoke(null, connection, "jdbc:phoenix:localhost", pagedQueryConnection(calls, false));
+
+ assertEquals(List.of("getAutoCommit", "setAutoCommit:true"), calls);
+ }
+
+ @Test
+ void phoenixAutoCommitConfigurationSkipsNonPhoenixConnections() throws Exception {
+ Method method = DbxJdbcPlugin.class.getDeclaredMethod(
+ "configurePhoenixAutoCommit",
+ JsonNode.class,
+ String.class,
+ Connection.class
+ );
+ method.setAccessible(true);
+ List<String> calls = new ArrayList<>();
+ JsonNode connection = MAPPER.readTree("""
+ {
+ "connection_string": "jdbc:h2:mem:dbx"
+ }
+ """);
+
+ method.invoke(null, connection, "jdbc:h2:mem:dbx", pagedQueryConnection(calls, false));
+
+ assertEquals(List.of(), calls);
+ }
+
+ @Test
+ void phoenixAutoCommitConfigurationDoesNotResetExistingAutoCommit() throws Exception {
+ Method method = DbxJdbcPlugin.class.getDeclaredMethod(
+ "configurePhoenixAutoCommit",
+ JsonNode.class,
+ String.class,
+ Connection.class
+ );
+ method.setAccessible(true);
+ List<String> calls = new ArrayList<>();
+ JsonNode connection = MAPPER.readTree("""
+ {
+ "jdbc_driver_class": "org.apache.phoenix.jdbc.PhoenixDriver"
+ }
+ """);
+
+ method.invoke(null, connection, "jdbc:custom:phoenix", pagedQueryConnection(calls, true));
+
+ assertEquals(List.of("getAutoCommit"), calls);
+ }
+
@Test
void mysqlPagedQueriesEnableConnectorCursorFetchingByDefault() throws Exception {
Method method = DbxJdbcPlugin.class.getDeclaredMethod(