Skip to content

Commit

Permalink
test current changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonli-improving committed Feb 2, 2024
1 parent 2387494 commit 481ea77
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -104,4 +125,10 @@ public boolean ping(@NonNull Connection connection) {
return false;
}
}

@Override
public List<String> getAllowedOnConnectionMethodNames() {
return Arrays.asList(METHOD_GET_SCHEMA, METHOD_GET_CATALOG,
METHOD_GET_AUTO_COMMIT, METHOD_GET_TRANSACTION_ISOLATION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,4 +97,17 @@ public void registerDriver() throws SQLException {
final MariadbDriverHelper helper = new MariadbDriverHelper();
helper.registerDriver();
}

@Override
public List<String> 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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,4 +106,9 @@ public boolean ping(@NonNull Connection connection) {
return false;
}
}

@Override
public List<String> getAllowedOnConnectionMethodNames() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,4 +120,9 @@ public void registerDriver() throws SQLException {
final PgDriverHelper helper = new PgDriverHelper();
helper.registerDriver();
}

@Override
public List<String> getAllowedOnConnectionMethodNames() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,4 +54,6 @@ void prepareDataSource(
* @return True, if operation is succeeded. False, otherwise.
*/
boolean ping(final @NonNull Connection connection);

List<String> getAllowedOnConnectionMethodNames();
}

0 comments on commit 481ea77

Please sign in to comment.