Skip to content

Commit 188b827

Browse files
refactor property definitions
expose driver properties for username, password and database name fix and enable some data source integration tests rename public configuration parameter names
1 parent 799093f commit 188b827

26 files changed

+170
-175
lines changed

wrapper/src/main/java/com/amazon/awslabs/jdbc/ConnectionPropertyNames.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

wrapper/src/main/java/com/amazon/awslabs/jdbc/DataSourceConnectionProvider.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
package com.amazon.awslabs.jdbc;
1818

19-
import static com.amazon.awslabs.jdbc.ConnectionPropertyNames.DATABASE_PROPERTY_NAME;
20-
import static com.amazon.awslabs.jdbc.ConnectionPropertyNames.PASSWORD_PROPERTY_NAME;
21-
import static com.amazon.awslabs.jdbc.ConnectionPropertyNames.USER_PROPERTY_NAME;
2219
import static com.amazon.awslabs.jdbc.util.ConnectionUrlBuilder.buildUrl;
2320
import static com.amazon.awslabs.jdbc.util.StringUtils.isNullOrEmpty;
2421

@@ -90,16 +87,16 @@ public Connection connect(
9087
copy.put(this.portPropertyName, hostSpec.getPort());
9188
}
9289

93-
if (!isNullOrEmpty(this.databasePropertyName) && !isNullOrEmpty(props.getProperty(DATABASE_PROPERTY_NAME))) {
94-
copy.setProperty(this.databasePropertyName, props.getProperty(DATABASE_PROPERTY_NAME));
90+
if (!isNullOrEmpty(this.databasePropertyName) && !isNullOrEmpty(PropertyDefinition.DATABASE_NAME.getString(props))) {
91+
copy.setProperty(this.databasePropertyName, PropertyDefinition.DATABASE_NAME.getString(props));
9592
}
9693

97-
if (!isNullOrEmpty(this.userPropertyName) && !isNullOrEmpty(props.getProperty(USER_PROPERTY_NAME))) {
98-
copy.setProperty(this.userPropertyName, props.getProperty(USER_PROPERTY_NAME));
94+
if (!isNullOrEmpty(this.userPropertyName) && !isNullOrEmpty(PropertyDefinition.USER.getString(props))) {
95+
copy.setProperty(this.userPropertyName, PropertyDefinition.USER.getString(props));
9996
}
10097

101-
if (!isNullOrEmpty(this.passwordPropertyName) && !isNullOrEmpty(props.getProperty(PASSWORD_PROPERTY_NAME))) {
102-
copy.setProperty(this.passwordPropertyName, props.getProperty(PASSWORD_PROPERTY_NAME));
98+
if (!isNullOrEmpty(this.passwordPropertyName) && !isNullOrEmpty(PropertyDefinition.PASSWORD.getString(props))) {
99+
copy.setProperty(this.passwordPropertyName, PropertyDefinition.PASSWORD.getString(props));
103100
}
104101

105102
if (!isNullOrEmpty(this.urlPropertyName) && !isNullOrEmpty(props.getProperty(this.urlPropertyName))) {
@@ -120,6 +117,10 @@ public Connection connect(
120117
urlProperties));
121118
}
122119

120+
copy.remove(PropertyDefinition.DATABASE_NAME.name);
121+
copy.remove(PropertyDefinition.USER.name);
122+
copy.remove(PropertyDefinition.PASSWORD.name);
123+
123124
PropertyUtils.applyProperties(this.dataSource, copy);
124125
return this.dataSource.getConnection();
125126
}
@@ -139,18 +140,22 @@ public Connection connect(final @NonNull String url, final @NonNull Properties p
139140
copy.setProperty(this.urlPropertyName, url);
140141
}
141142

142-
if (!isNullOrEmpty(this.userPropertyName) && !isNullOrEmpty(props.getProperty(USER_PROPERTY_NAME))) {
143-
copy.put(this.userPropertyName, props.getProperty(USER_PROPERTY_NAME));
143+
if (!isNullOrEmpty(this.userPropertyName) && !isNullOrEmpty(PropertyDefinition.USER.getString(props))) {
144+
copy.put(this.userPropertyName, PropertyDefinition.USER.getString(props));
144145
}
145146

146-
if (!isNullOrEmpty(this.passwordPropertyName) && !isNullOrEmpty(props.getProperty(PASSWORD_PROPERTY_NAME))) {
147-
copy.put(this.passwordPropertyName, props.getProperty(PASSWORD_PROPERTY_NAME));
147+
if (!isNullOrEmpty(this.passwordPropertyName) && !isNullOrEmpty(PropertyDefinition.PASSWORD.getString(props))) {
148+
copy.put(this.passwordPropertyName, PropertyDefinition.PASSWORD.getString(props));
148149
}
149150

150-
if (!isNullOrEmpty(this.databasePropertyName) && !isNullOrEmpty(props.getProperty(DATABASE_PROPERTY_NAME))) {
151-
copy.put(this.databasePropertyName, props.getProperty(DATABASE_PROPERTY_NAME));
151+
if (!isNullOrEmpty(this.databasePropertyName) && !isNullOrEmpty(PropertyDefinition.DATABASE_NAME.getString(props))) {
152+
copy.put(this.databasePropertyName, PropertyDefinition.DATABASE_NAME.getString(props));
152153
}
153154

155+
copy.remove(PropertyDefinition.DATABASE_NAME.name);
156+
copy.remove(PropertyDefinition.USER.name);
157+
copy.remove(PropertyDefinition.PASSWORD.name);
158+
154159
PropertyUtils.applyProperties(this.dataSource, copy);
155160
return this.dataSource.getConnection();
156161
}

wrapper/src/main/java/com/amazon/awslabs/jdbc/Driver.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.amazon.awslabs.jdbc;
1818

19-
import static com.amazon.awslabs.jdbc.ConnectionPropertyNames.DATABASE_PROPERTY_NAME;
20-
2119
import com.amazon.awslabs.jdbc.util.DriverInfo;
2220
import com.amazon.awslabs.jdbc.util.StringUtils;
2321
import com.amazon.awslabs.jdbc.wrapper.ConnectionWrapper;
@@ -34,7 +32,7 @@
3432

3533
public class Driver implements java.sql.Driver {
3634

37-
private static final String PROTOCOL_PREFIX = "aws-proxy-jdbc:";
35+
private static final String PROTOCOL_PREFIX = "aws-jdbc-wrapper:";
3836
private static final Logger PARENT_LOGGER = Logger.getLogger("com.amazon.awslabs.jdbc");
3937
private static final Logger LOGGER = Logger.getLogger("com.amazon.awslabs.jdbc.Driver");
4038
private static @Nullable Driver registeredDriver;
@@ -131,7 +129,7 @@ public boolean acceptsURL(String url) throws SQLException {
131129
if (dPos != -1) {
132130
String database = urlServer.substring(dPos + 1);
133131
if (!database.isEmpty()) {
134-
propertiesFromUrl.setProperty(DATABASE_PROPERTY_NAME, database);
132+
PropertyDefinition.DATABASE_NAME.set(propertiesFromUrl, database);
135133
}
136134
}
137135

wrapper/src/main/java/com/amazon/awslabs/jdbc/DriverConnectionProvider.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
package com.amazon.awslabs.jdbc;
1818

19-
import static com.amazon.awslabs.jdbc.ConnectionPropertyNames.DATABASE_PROPERTY_NAME;
20-
import static com.amazon.awslabs.jdbc.ConnectionPropertyNames.PASSWORD_PROPERTY_NAME;
21-
import static com.amazon.awslabs.jdbc.ConnectionPropertyNames.USER_PROPERTY_NAME;
2219
import static com.amazon.awslabs.jdbc.util.StringUtils.isNullOrEmpty;
2320

21+
import com.amazon.awslabs.jdbc.util.PropertyUtils;
2422
import java.sql.Connection;
2523
import java.sql.SQLException;
2624
import java.util.Properties;
@@ -62,20 +60,27 @@ public Connection connect(
6260
final @NonNull Properties props)
6361
throws SQLException {
6462

65-
final String databaseName =
66-
props.getProperty(DATABASE_PROPERTY_NAME) != null ? props.getProperty(DATABASE_PROPERTY_NAME) : "";
63+
Properties copy = PropertyUtils.copyProperties(props);
64+
65+
final String databaseName = PropertyDefinition.DATABASE_NAME.getString(props) != null
66+
? PropertyDefinition.DATABASE_NAME.getString(props)
67+
: "";
6768
final StringBuilder urlBuilder = new StringBuilder();
6869
urlBuilder.append(protocol).append(hostSpec.getUrl()).append(databaseName);
6970

70-
if (!isNullOrEmpty(this.userPropertyName) && !isNullOrEmpty(props.getProperty(USER_PROPERTY_NAME))) {
71-
props.setProperty(this.userPropertyName, props.getProperty(USER_PROPERTY_NAME));
71+
if (!isNullOrEmpty(this.userPropertyName) && !isNullOrEmpty(PropertyDefinition.USER.getString(props))) {
72+
copy.setProperty(this.userPropertyName, PropertyDefinition.USER.getString(props));
7273
}
7374

74-
if (!isNullOrEmpty(this.passwordPropertyName) && !isNullOrEmpty(props.getProperty(PASSWORD_PROPERTY_NAME))) {
75-
props.setProperty(this.passwordPropertyName, props.getProperty(PASSWORD_PROPERTY_NAME));
75+
if (!isNullOrEmpty(this.passwordPropertyName) && !isNullOrEmpty(PropertyDefinition.PASSWORD.getString(props))) {
76+
copy.setProperty(this.passwordPropertyName, PropertyDefinition.PASSWORD.getString(props));
7677
}
7778

78-
return this.driver.connect(urlBuilder.toString(), props);
79+
copy.remove(PropertyDefinition.DATABASE_NAME.name);
80+
copy.remove(PropertyDefinition.USER.name);
81+
copy.remove(PropertyDefinition.PASSWORD.name);
82+
83+
return this.driver.connect(urlBuilder.toString(), copy);
7984
}
8085

8186
/**

wrapper/src/main/java/com/amazon/awslabs/jdbc/PropertyDefinition.java

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,14 @@
2626

2727
public class PropertyDefinition {
2828

29-
public static final ProxyDriverProperty CLUSTER_INSTANCE_HOST_PATTERN =
30-
new ProxyDriverProperty(
31-
"clusterInstanceHostPattern",
32-
null,
33-
"The cluster instance DNS pattern that will be used to build a complete instance endpoint. "
34-
+ "A \"?\" character in this pattern should be used as a placeholder for cluster instance names. "
35-
+ "This pattern is required to be specified for IP address or custom domain connections to AWS RDS "
36-
+ "clusters. Otherwise, if unspecified, the pattern will be automatically created for AWS RDS clusters.");
37-
38-
public static final ProxyDriverProperty ENABLE_CLUSTER_AWARE_FAILOVER =
39-
new ProxyDriverProperty(
40-
"enableClusterAwareFailover", "true",
41-
"Enable/disable cluster-aware failover logic");
42-
4329
public static final ProxyDriverProperty LOG_UNCLOSED_CONNECTIONS =
4430
new ProxyDriverProperty(
45-
"proxyDriverLogUnclosedConnections", "false",
31+
"wrapperLogUnclosedConnections", "false",
4632
"Allows the driver to track a point in the code where connection has been opened and never closed after");
4733

4834
public static final ProxyDriverProperty LOGGER_LEVEL =
4935
new ProxyDriverProperty(
50-
"proxyDriverLoggerLevel",
36+
"wrapperLoggerLevel",
5137
null,
5238
"Logger level of the driver",
5339
false,
@@ -57,21 +43,23 @@ public class PropertyDefinition {
5743

5844
public static final ProxyDriverProperty PLUGINS =
5945
new ProxyDriverProperty(
60-
"proxyDriverPlugins", null, "Comma separated list of connection plugin codes");
46+
"wrapperPlugins", null, "Comma separated list of connection plugin codes");
6147

6248
public static final ProxyDriverProperty PROFILE_NAME =
6349
new ProxyDriverProperty(
64-
"proxyDriverProfileName", null, "Driver configuration profile name");
50+
"wrapperProfileName", null, "Driver configuration profile name");
51+
52+
public static final ProxyDriverProperty USER =
53+
new ProxyDriverProperty(
54+
"wrapperUser", null, "Driver user name");
6555

66-
public static final ProxyDriverProperty USE_AWS_IAM =
56+
public static final ProxyDriverProperty PASSWORD =
6757
new ProxyDriverProperty(
68-
"useAwsIam", "false", "Set to true to use AWS IAM database authentication");
58+
"wrapperPassword", null, "Driver password");
6959

70-
public static final ProxyDriverProperty CLUSTER_ID = new ProxyDriverProperty(
71-
"clusterId", "",
72-
"A unique identifier for the cluster. "
73-
+ "Connections with the same cluster id share a cluster topology cache. "
74-
+ "If unspecified, a cluster id is automatically created for AWS RDS clusters.");
60+
public static final ProxyDriverProperty DATABASE_NAME =
61+
new ProxyDriverProperty(
62+
"wrapperDatabaseName", null, "Driver database name");
7563

7664
private static final Map<String, ProxyDriverProperty> PROPS_BY_NAME =
7765
new HashMap<String, ProxyDriverProperty>();

wrapper/src/main/java/com/amazon/awslabs/jdbc/ds/ProxyDriverDataSource.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616

1717
package com.amazon.awslabs.jdbc.ds;
1818

19-
import static com.amazon.awslabs.jdbc.ConnectionPropertyNames.DATABASE_PROPERTY_NAME;
20-
import static com.amazon.awslabs.jdbc.ConnectionPropertyNames.PASSWORD_PROPERTY_NAME;
21-
import static com.amazon.awslabs.jdbc.ConnectionPropertyNames.USER_PROPERTY_NAME;
2219
import static com.amazon.awslabs.jdbc.util.ConnectionUrlBuilder.buildUrl;
2320
import static com.amazon.awslabs.jdbc.util.ConnectionUrlParser.parsePropertiesFromUrl;
2421

2522
import com.amazon.awslabs.jdbc.DataSourceConnectionProvider;
2623
import com.amazon.awslabs.jdbc.Driver;
2724
import com.amazon.awslabs.jdbc.DriverConnectionProvider;
25+
import com.amazon.awslabs.jdbc.PropertyDefinition;
2826
import com.amazon.awslabs.jdbc.util.ConnectionUrlParser;
2927
import com.amazon.awslabs.jdbc.util.PropertyUtils;
3028
import com.amazon.awslabs.jdbc.util.SqlState;
@@ -89,11 +87,12 @@ public Connection getConnection(String username, String password) throws SQLExce
8987

9088
Properties props = PropertyUtils.copyProperties(this.targetDataSourceProperties);
9189
setCredentialProperties(props);
90+
9291
if (!isNullOrEmpty(this.targetDataSourceClassName)) {
9392
final DataSource targetDataSource = createTargetDataSource();
9493

9594
if (!isNullOrEmpty(this.databasePropertyName) && !isNullOrEmpty(props.getProperty(this.databasePropertyName))) {
96-
props.put(DATABASE_PROPERTY_NAME, props.getProperty(this.databasePropertyName));
95+
PropertyDefinition.DATABASE_NAME.set(props, props.getProperty(this.databasePropertyName));
9796
}
9897

9998
// If the url is set explicitly through setJdbcUrl or the connection properties.
@@ -143,8 +142,9 @@ public Connection getConnection(String username, String password) throws SQLExce
143142
throw new SQLException("Can't find a suitable driver for " + this.jdbcUrl);
144143
}
145144

146-
setDatabasePropertyFromUrl(props);
147145
parsePropertiesFromUrl(this.jdbcUrl, props);
146+
setCredentialProperties(props);
147+
setDatabasePropertyFromUrl(props);
148148

149149
return new ConnectionWrapper(
150150
props,
@@ -299,21 +299,21 @@ protected boolean isNullOrEmpty(final String str) {
299299

300300
private void setCredentialProperties(Properties props) {
301301
// If username was provided as a get connection parameter and a userPropertyName is set.
302-
if (!isNullOrEmpty(this.user) && !isNullOrEmpty(this.userPropertyName)) {
303-
props.setProperty(USER_PROPERTY_NAME, this.user);
302+
if (!isNullOrEmpty(this.user)) {
303+
PropertyDefinition.USER.set(props, this.user);
304304

305305
// If username was provided in targetDataSourceProperties and a userPropertyName is set.
306306
} else if (!isNullOrEmpty(this.userPropertyName) && !isNullOrEmpty(props.getProperty(this.userPropertyName))) {
307-
props.setProperty(USER_PROPERTY_NAME, props.getProperty(this.userPropertyName));
307+
PropertyDefinition.USER.set(props, props.getProperty(this.userPropertyName));
308308
this.user = props.getProperty(this.userPropertyName);
309309
}
310310

311-
if (!isNullOrEmpty(this.password) && !isNullOrEmpty(this.passwordPropertyName)) {
312-
props.setProperty(PASSWORD_PROPERTY_NAME, this.password);
311+
if (!isNullOrEmpty(this.password)) {
312+
PropertyDefinition.PASSWORD.set(props, this.password);
313313

314314
} else if (!isNullOrEmpty(this.passwordPropertyName)
315315
&& !isNullOrEmpty(props.getProperty(this.passwordPropertyName))) {
316-
props.setProperty(PASSWORD_PROPERTY_NAME, props.getProperty(this.passwordPropertyName));
316+
PropertyDefinition.PASSWORD.set(props, props.getProperty(this.passwordPropertyName));
317317
this.password = props.getProperty(this.passwordPropertyName);
318318
}
319319
}
@@ -329,20 +329,20 @@ private DataSource createTargetDataSource() throws SQLException {
329329
private void setDatabasePropertyFromUrl(Properties props) {
330330
final String databaseName = ConnectionUrlParser.parseDatabaseFromUrl(this.jdbcUrl);
331331
if (!isNullOrEmpty(databaseName)) {
332-
props.setProperty(DATABASE_PROPERTY_NAME, databaseName);
332+
PropertyDefinition.DATABASE_NAME.set(props, databaseName);
333333
}
334334
}
335335

336336
private void setCredentialPropertiesFromUrl(Properties props) {
337337
final String userFromUrl = ConnectionUrlParser.parseUserFromUrl(this.jdbcUrl, this.userPropertyName);
338338
if (isNullOrEmpty(this.user) && !isNullOrEmpty(userFromUrl)) {
339-
props.setProperty(USER_PROPERTY_NAME, userFromUrl);
339+
PropertyDefinition.USER.set(props, userFromUrl);
340340
this.user = userFromUrl;
341341
}
342342

343343
final String passwordFromUrl = ConnectionUrlParser.parsePasswordFromUrl(this.jdbcUrl, this.passwordPropertyName);
344344
if (isNullOrEmpty(this.password) && !isNullOrEmpty(passwordFromUrl)) {
345-
props.setProperty(PASSWORD_PROPERTY_NAME, passwordFromUrl);
345+
PropertyDefinition.PASSWORD.set(props, passwordFromUrl);
346346
this.password = passwordFromUrl;
347347
}
348348
}

wrapper/src/main/java/com/amazon/awslabs/jdbc/hostlistprovider/AuroraHostListProvider.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ public class AuroraHostListProvider implements HostListProvider, DynamicHostList
5555
"Cluster topology refresh rate in millis. "
5656
+ "The cached topology for the cluster will be invalidated after the specified time, "
5757
+ "after which it will be updated during the next interaction with the connection.");
58+
59+
public static final ProxyDriverProperty CLUSTER_ID = new ProxyDriverProperty(
60+
"clusterId", "",
61+
"A unique identifier for the cluster. "
62+
+ "Connections with the same cluster id share a cluster topology cache. "
63+
+ "If unspecified, a cluster id is automatically created for AWS RDS clusters.");
64+
65+
public static final ProxyDriverProperty CLUSTER_INSTANCE_HOST_PATTERN =
66+
new ProxyDriverProperty(
67+
"clusterInstanceHostPattern",
68+
null,
69+
"The cluster instance DNS pattern that will be used to build a complete instance endpoint. "
70+
+ "A \"?\" character in this pattern should be used as a placeholder for cluster instance names. "
71+
+ "This pattern is required to be specified for IP address or custom domain connections to AWS RDS "
72+
+ "clusters. Otherwise, if unspecified, the pattern will be automatically created for AWS RDS clusters.");
73+
5874
static final String PG_RETRIEVE_TOPOLOGY_SQL =
5975
"SELECT SERVER_ID, SESSION_ID FROM aurora_replica_status() "
6076
// filter out nodes that haven't been updated in the last 5 minutes
@@ -109,14 +125,14 @@ public AuroraHostListProvider(
109125
this.originalUrl = originalUrl;
110126
this.clusterId = UUID.randomUUID().toString();
111127
this.refreshRateInMilliseconds = CLUSTER_TOPOLOGY_REFRESH_RATE_MS.getInteger(properties);
112-
this.clusterInstanceTemplate = PropertyDefinition.CLUSTER_INSTANCE_HOST_PATTERN.get(this.properties) == null
128+
this.clusterInstanceTemplate = CLUSTER_INSTANCE_HOST_PATTERN.get(this.properties) == null
113129
? new HostSpec(rdsHelper.getRdsInstanceHostPattern(originalUrl))
114-
: new HostSpec(PropertyDefinition.CLUSTER_INSTANCE_HOST_PATTERN.getString(this.properties));
130+
: new HostSpec(CLUSTER_INSTANCE_HOST_PATTERN.getString(this.properties));
115131
validateHostPatternSetting(this.clusterInstanceTemplate.getHost());
116132

117133
this.rdsUrlType = rdsHelper.identifyRdsType(originalUrl);
118134

119-
final String clusterIdSetting = PropertyDefinition.CLUSTER_ID.get(this.properties);
135+
final String clusterIdSetting = CLUSTER_ID.get(this.properties);
120136
if (!StringUtils.isNullOrEmpty(clusterIdSetting)) {
121137
this.clusterId = clusterIdSetting;
122138
} else if (rdsUrlType == RdsUrlType.RDS_PROXY) {

wrapper/src/main/java/com/amazon/awslabs/jdbc/plugin/DataCacheConnectionPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class DataCacheConnectionPlugin extends AbstractConnectionPlugin {
6060
"PreparedStatement.execute", "PreparedStatement.executeQuery",
6161
"CallableStatement.execute", "CallableStatement.executeQuery")));
6262

63-
protected static final ProxyDriverProperty DATA_CACHE_TRIGGER_CONDITION = new ProxyDriverProperty(
63+
public static final ProxyDriverProperty DATA_CACHE_TRIGGER_CONDITION = new ProxyDriverProperty(
6464
"dataCacheTriggerCondition", "false",
6565
"A regular expression that, if it's matched, allows the plugin to cache SQL results.");
6666

0 commit comments

Comments
 (0)