From 481ea77f4053f0ad88eb1519239326a361c583d6 Mon Sep 17 00:00:00 2001 From: jasonli-improving Date: Fri, 2 Feb 2024 15:46:32 -0800 Subject: [PATCH] test current changes --- .../failover/FailoverConnectionPlugin.java | 10 ++++--- .../GenericTargetDriverDialect.java | 27 +++++++++++++++++++ .../MariadbTargetDriverDialect.java | 16 +++++++++++ .../MysqlConnectorJTargetDriverDialect.java | 8 ++++++ .../PgTargetDriverDialect.java | 8 ++++++ .../TargetDriverDialect.java | 3 +++ 6 files changed, 68 insertions(+), 4 deletions(-) diff --git a/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java b/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java index da24cc4a0..bd22791bf 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java +++ b/wrapper/src/main/java/software/amazon/jdbc/plugin/failover/FailoverConnectionPlugin.java @@ -29,6 +29,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.checkerframework.checker.nullness.qual.NonNull; +import software.amazon.awssdk.services.rds.endpoints.internal.Value.Bool; import software.amazon.jdbc.AwsWrapperProperty; import software.amazon.jdbc.HostListProviderService; import software.amazon.jdbc.HostRole; @@ -42,6 +43,9 @@ import software.amazon.jdbc.hostavailability.HostAvailability; import software.amazon.jdbc.plugin.AbstractConnectionPlugin; import software.amazon.jdbc.plugin.staledns.AuroraStaleDnsHelper; +import software.amazon.jdbc.targetdriverdialect.GenericTargetDriverDialect; +import software.amazon.jdbc.targetdriverdialect.MariadbTargetDriverDialect; +import software.amazon.jdbc.targetdriverdialect.TargetDriverDialect; import software.amazon.jdbc.util.Messages; import software.amazon.jdbc.util.RdsUrlType; import software.amazon.jdbc.util.RdsUtils; @@ -420,10 +424,8 @@ protected void updateTopology(final boolean forceUpdate) throws SQLException { */ private boolean allowedOnClosedConnection(final String methodName) { // TODO: consider to use target driver dialect - return methodName.equals(METHOD_GET_AUTO_COMMIT) - || methodName.equals(METHOD_GET_CATALOG) - || methodName.equals(METHOD_GET_SCHEMA) - || methodName.equals(METHOD_GET_TRANSACTION_ISOLATION); + TargetDriverDialect dialect = this.pluginService.getTargetDriverDialect(); + return dialect.getAllowedOnConnectionMethodNames().contains(methodName); } /** diff --git a/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/GenericTargetDriverDialect.java b/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/GenericTargetDriverDialect.java index 4b8d2402c..79f22dadb 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/GenericTargetDriverDialect.java +++ b/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/GenericTargetDriverDialect.java @@ -21,6 +21,8 @@ import java.sql.Connection; import java.sql.Driver; import java.sql.SQLException; +import java.util.Arrays; +import java.util.List; import java.util.Properties; import java.util.logging.Logger; import javax.sql.DataSource; @@ -34,6 +36,25 @@ public class GenericTargetDriverDialect implements TargetDriverDialect { private static final Logger LOGGER = Logger.getLogger(GenericTargetDriverDialect.class.getName()); + public static final String METHOD_GET_AUTO_COMMIT = "Connection.getAutoCommit"; + public static final String METHOD_GET_CATALOG = "Connection.getCatalog"; + public static final String METHOD_GET_SCHEMA = "Connection.getSchema"; + public static final String METHOD_GET_TRANSACTION_ISOLATION = "Connection.getTransactionIsolation"; + public static final String METHOD_GET_NETWORK_TIME = "Connection.getNetworkTimeout"; + public static final String METHOD_GET_METADATA = "Connection.getMetaData"; + public static final String METHOD_IS_READ_ONLY = "Connection.isReadOnly"; + public static final String METHOD_GET_HOLDABILITY = "Connection.getHoldability"; + public static final String METHOD_GET_CLIENT_INFO = "Connection.getClientInfo"; + public static final String METHOD_GET_TYPE_MAP = "Connection.getTypeMap"; + public static final String METHOD_CLEAR_WARNINGS = "Statement.clearWarnings"; + public static final String METHOD_GET_CONNECTION = "Statement.getConnection"; + public static final String METHOD_GET_FETCH_DIRECTION = "Statement.getFetchDirection"; + public static final String METHOD_GET_FETCH_SIZE = "Statement.getFetchSize"; + public static final String METHOD_GET_MAX_FIELD_SIZE = "Statement.getMaxFieldSize"; + public static final String METHOD_GET_RESULT_HOLDABILITY = "Statement.getResultSetHoldability"; + public static final String METHOD_GET_RESULT_SET_TYPE = "Statement.getResultSetType"; + public static final String METHOD_IS_CLOSED = "Statement.isClosed"; + public static final String METHOD_CLOSE_ON_COMPLETION = "Statement.isCloseOnCompletion"; @Override public boolean isDialect(Driver driver) { @@ -104,4 +125,10 @@ public boolean ping(@NonNull Connection connection) { return false; } } + + @Override + public List getAllowedOnConnectionMethodNames() { + return Arrays.asList(METHOD_GET_SCHEMA, METHOD_GET_CATALOG, + METHOD_GET_AUTO_COMMIT, METHOD_GET_TRANSACTION_ISOLATION); + } } diff --git a/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MariadbTargetDriverDialect.java b/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MariadbTargetDriverDialect.java index bd4b9bfa7..99befc288 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MariadbTargetDriverDialect.java +++ b/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MariadbTargetDriverDialect.java @@ -18,6 +18,9 @@ import java.sql.Driver; import java.sql.SQLException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.Properties; import javax.sql.DataSource; import org.checkerframework.checker.nullness.qual.NonNull; @@ -94,4 +97,17 @@ public void registerDriver() throws SQLException { final MariadbDriverHelper helper = new MariadbDriverHelper(); helper.registerDriver(); } + + @Override + public List getAllowedOnConnectionMethodNames() { + return Arrays.asList( + METHOD_GET_METADATA, + METHOD_IS_READ_ONLY, + METHOD_GET_AUTO_COMMIT, + METHOD_GET_HOLDABILITY, + METHOD_GET_CLIENT_INFO, + METHOD_GET_NETWORK_TIME, + METHOD_GET_TYPE_MAP + ); + } } diff --git a/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MysqlConnectorJTargetDriverDialect.java b/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MysqlConnectorJTargetDriverDialect.java index b5ca755c1..2c7d314d3 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MysqlConnectorJTargetDriverDialect.java +++ b/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MysqlConnectorJTargetDriverDialect.java @@ -21,6 +21,9 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.Properties; import javax.sql.DataSource; import org.checkerframework.checker.nullness.qual.NonNull; @@ -103,4 +106,9 @@ public boolean ping(@NonNull Connection connection) { return false; } } + + @Override + public List getAllowedOnConnectionMethodNames() { + return Collections.emptyList(); + } } diff --git a/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/PgTargetDriverDialect.java b/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/PgTargetDriverDialect.java index 88869015e..1bac5851a 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/PgTargetDriverDialect.java +++ b/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/PgTargetDriverDialect.java @@ -19,10 +19,13 @@ import java.sql.Driver; import java.sql.SQLException; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import javax.sql.DataSource; import org.checkerframework.checker.nullness.qual.NonNull; import software.amazon.jdbc.HostSpec; @@ -117,4 +120,9 @@ public void registerDriver() throws SQLException { final PgDriverHelper helper = new PgDriverHelper(); helper.registerDriver(); } + + @Override + public List getAllowedOnConnectionMethodNames() { + return Collections.emptyList(); + } } diff --git a/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/TargetDriverDialect.java b/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/TargetDriverDialect.java index 9a2483f2b..1a33637f6 100644 --- a/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/TargetDriverDialect.java +++ b/wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/TargetDriverDialect.java @@ -18,6 +18,7 @@ import java.sql.Connection; import java.sql.SQLException; +import java.util.List; import java.util.Properties; import javax.sql.DataSource; import org.checkerframework.checker.nullness.qual.NonNull; @@ -53,4 +54,6 @@ void prepareDataSource( * @return True, if operation is succeeded. False, otherwise. */ boolean ping(final @NonNull Connection connection); + + List getAllowedOnConnectionMethodNames(); }