Skip to content

Commit 7f06bff

Browse files
code review
1 parent e4cb64c commit 7f06bff

File tree

6 files changed

+32
-13
lines changed

6 files changed

+32
-13
lines changed

benchmarks/src/jmh/java/software/amazon/jdbc/benchmarks/PluginBenchmarks.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,15 @@ public static void main(String[] args) throws RunnerException {
9898
}
9999

100100
@Setup(Level.Iteration)
101+
@SuppressWarnings("deprecation")
101102
public void setUpIteration() throws Exception {
102103
closeable = MockitoAnnotations.openMocks(this);
103104
when(mockConnectionPluginManager.connect(any(), any(), any(Properties.class), anyBoolean()))
104105
.thenReturn(mockConnection);
105106
when(mockConnectionPluginManager.execute(
106107
any(), any(), any(), eq("Connection.createStatement"), any(), any()))
107108
.thenReturn(mockStatement);
109+
108110
when(mockConnectionProvider.connect(anyString(), any(Properties.class))).thenReturn(
109111
mockConnection);
110112
when(mockConnectionProvider.connect(anyString(), any(Dialect.class), any(HostSpec.class), any(Properties.class)))

wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MariadbDataSourceHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class MariadbDataSourceHelper {
3434
Logger.getLogger(MariadbDataSourceHelper.class.getName());
3535

3636
private static final String LOGIN_TIMEOUT = "loginTimeout";
37+
private static final String DS_CLASS_NAME = MariaDbDataSource.class.getName();
3738

3839
public void prepareDataSource(
3940
final @NonNull DataSource dataSource,
@@ -44,7 +45,7 @@ public void prepareDataSource(
4445
if (!(dataSource instanceof MariaDbDataSource)) {
4546
throw new SQLException(Messages.get(
4647
"TargetDriverDialectManager.unexpectedClass",
47-
new Object[] {"org.mariadb.jdbc.MariaDbDataSource", dataSource.getClass().getName()}));
48+
new Object[] { DS_CLASS_NAME, dataSource.getClass().getName() }));
4849
}
4950

5051
final MariaDbDataSource mariaDbDataSource = (MariaDbDataSource) dataSource;

wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MariadbTargetDriverDialect.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@
2828
public class MariadbTargetDriverDialect extends GenericTargetDriverDialect {
2929

3030
private static final String PERMIT_MYSQL_SCHEME = "permitMysqlScheme";
31+
private static final String DRIVER_CLASS_NAME = org.mariadb.jdbc.Driver.class.getName();
32+
private static final String DS_CLASS_NAME = org.mariadb.jdbc.MariaDbDataSource.class.getName();
33+
private static final String CP_DS_CLASS_NAME =
34+
org.mariadb.jdbc.MariaDbPoolDataSource.class.getName();
3135

3236
@Override
3337
public boolean isDialect(Driver driver) {
34-
return "org.mariadb.jdbc.Driver".equals(driver.getClass().getName());
38+
return DRIVER_CLASS_NAME.equals(driver.getClass().getName());
3539
}
3640

3741
@Override
3842
public boolean isDialect(String dataSourceClass) {
39-
return "org.mariadb.jdbc.MariaDbDataSource".equals(dataSourceClass)
40-
|| "org.mariadb.jdbc.MariaDbPoolDataSource".equals(dataSourceClass);
43+
return DS_CLASS_NAME.equals(dataSourceClass)
44+
|| CP_DS_CLASS_NAME.equals(dataSourceClass);
4145
}
4246

4347
@Override

wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MysqlConnectorJTargetDriverDialect.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@
2626

2727
public class MysqlConnectorJTargetDriverDialect extends GenericTargetDriverDialect {
2828

29+
private static final String DRIVER_CLASS_NAME = com.mysql.cj.jdbc.Driver.class.getName();
30+
private static final String DS_CLASS_NAME = com.mysql.cj.jdbc.MysqlDataSource.class.getName();
31+
private static final String CP_DS_CLASS_NAME =
32+
com.mysql.cj.jdbc.MysqlConnectionPoolDataSource.class.getName();
33+
2934
@Override
3035
public boolean isDialect(Driver driver) {
31-
return "com.mysql.cj.jdbc.Driver".equals(driver.getClass().getName());
36+
return DRIVER_CLASS_NAME.equals(driver.getClass().getName());
3237
}
3338

3439
@Override
3540
public boolean isDialect(String dataSourceClass) {
36-
return "com.mysql.cj.jdbc.MysqlDataSource".equals(dataSourceClass)
37-
|| "com.mysql.cj.jdbc.MysqlConnectionPoolDataSource".equals(dataSourceClass);
41+
return DS_CLASS_NAME.equals(dataSourceClass)
42+
|| CP_DS_CLASS_NAME.equals(dataSourceClass);
3843
}
3944

4045
@Override

wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/PgDataSourceHelper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public class PgDataSourceHelper {
3030

3131
public void prepareDataSource(
3232
final @NonNull DataSource dataSource,
33-
final @NonNull String protocol,
3433
final @NonNull HostSpec hostSpec,
3534
final @NonNull Properties props) throws SQLException {
3635

wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/PgTargetDriverDialect.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,22 @@
2929

3030
public class PgTargetDriverDialect extends GenericTargetDriverDialect {
3131

32+
private static final String DRIVER_CLASS_NAME = org.postgresql.Driver.class.getName();
33+
private static final String SIMPLE_DS_CLASS_NAME =
34+
org.postgresql.ds.PGSimpleDataSource.class.getName();
35+
private static final String POOLING_DS_CLASS_NAME =
36+
org.postgresql.ds.PGPoolingDataSource.class.getName();
37+
private static final String CP_DS_CLASS_NAME =
38+
org.postgresql.ds.PGConnectionPoolDataSource.class.getName();
39+
3240
private static final Set<String> dataSourceClassMap = new HashSet<>(Arrays.asList(
33-
"org.postgresql.ds.PGSimpleDataSource",
34-
"org.postgresql.ds.PGPoolingDataSource",
35-
"org.postgresql.ds.PGConnectionPoolDataSource"));
41+
SIMPLE_DS_CLASS_NAME,
42+
POOLING_DS_CLASS_NAME,
43+
CP_DS_CLASS_NAME));
3644

3745
@Override
3846
public boolean isDialect(Driver driver) {
39-
return "org.postgresql.Driver".equals(driver.getClass().getName());
47+
return DRIVER_CLASS_NAME.equals(driver.getClass().getName());
4048
}
4149

4250
@Override
@@ -58,6 +66,6 @@ public void prepareDataSource(
5866
// The logic is isolated to a separated class since it uses
5967
// direct reference to org.postgresql.ds.common.BaseDataSource
6068
final PgDataSourceHelper helper = new PgDataSourceHelper();
61-
helper.prepareDataSource(dataSource, protocol, hostSpec, props);
69+
helper.prepareDataSource(dataSource, hostSpec, props);
6270
}
6371
}

0 commit comments

Comments
 (0)