parent
e134acbccb
commit
9a255aa135
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue