Skip to content

Commit a5d2733

Browse files
authored
Remove mysql-connector-j library dependency for MariaDb (#1287)
1 parent 21b4853 commit a5d2733

15 files changed

+141
-25
lines changed

wrapper/src/main/java/software/amazon/jdbc/PluginServiceImpl.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -653,11 +653,16 @@ public void releaseResources() {
653653
}
654654

655655
@Override
656-
public boolean isNetworkException(final Throwable throwable) {
656+
public boolean isNetworkException(Throwable throwable) {
657+
return this.isNetworkException(throwable, this.targetDriverDialect);
658+
}
659+
660+
@Override
661+
public boolean isNetworkException(final Throwable throwable, @Nullable TargetDriverDialect targetDriverDialect) {
657662
if (this.exceptionHandler != null) {
658-
return this.exceptionHandler.isNetworkException(throwable);
663+
return this.exceptionHandler.isNetworkException(throwable, targetDriverDialect);
659664
}
660-
return this.exceptionManager.isNetworkException(this.dialect, throwable);
665+
return this.exceptionManager.isNetworkException(this.dialect, throwable, targetDriverDialect);
661666
}
662667

663668
@Override
@@ -669,11 +674,16 @@ public boolean isNetworkException(final String sqlState) {
669674
}
670675

671676
@Override
672-
public boolean isLoginException(final Throwable throwable) {
677+
public boolean isLoginException(Throwable throwable) {
678+
return this.isLoginException(throwable, this.targetDriverDialect);
679+
}
680+
681+
@Override
682+
public boolean isLoginException(final Throwable throwable, @Nullable TargetDriverDialect targetDriverDialect) {
673683
if (this.exceptionHandler != null) {
674-
return this.exceptionHandler.isLoginException(throwable);
684+
return this.exceptionHandler.isLoginException(throwable, targetDriverDialect);
675685
}
676-
return this.exceptionManager.isLoginException(this.dialect, throwable);
686+
return this.exceptionManager.isLoginException(this.dialect, throwable, targetDriverDialect);
677687
}
678688

679689
@Override

wrapper/src/main/java/software/amazon/jdbc/exceptions/AbstractPgExceptionHandler.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,32 @@
1818

1919
import java.sql.SQLException;
2020
import java.util.List;
21+
import org.checkerframework.checker.nullness.qual.Nullable;
22+
import software.amazon.jdbc.targetdriverdialect.TargetDriverDialect;
23+
import software.amazon.jdbc.util.StringUtils;
2124

2225
public abstract class AbstractPgExceptionHandler implements ExceptionHandler {
2326
public abstract List<String> getNetworkErrors();
2427

2528
public abstract List<String> getAccessErrors();
2629

2730
@Override
28-
public boolean isNetworkException(final Throwable throwable) {
31+
public boolean isNetworkException(Throwable throwable) {
32+
return this.isNetworkException(throwable, null);
33+
}
34+
35+
@Override
36+
public boolean isNetworkException(final Throwable throwable, @Nullable TargetDriverDialect targetDriverDialect) {
2937
Throwable exception = throwable;
3038

3139
while (exception != null) {
3240
if (exception instanceof SQLException) {
3341
return isNetworkException(((SQLException) exception).getSQLState());
42+
} else if (targetDriverDialect != null) {
43+
String sqlState = targetDriverDialect.getSQLState(throwable);
44+
if (!StringUtils.isNullOrEmpty(sqlState)) {
45+
return isNetworkException(sqlState);
46+
}
3447
}
3548

3649
exception = exception.getCause();
@@ -56,6 +69,11 @@ public boolean isNetworkException(final String sqlState) {
5669

5770
@Override
5871
public boolean isLoginException(final Throwable throwable) {
72+
return this.isLoginException(throwable, null);
73+
}
74+
75+
@Override
76+
public boolean isLoginException(final Throwable throwable, @Nullable TargetDriverDialect targetDriverDialect) {
5977
Throwable exception = throwable;
6078

6179
while (exception != null) {
@@ -66,6 +84,8 @@ public boolean isLoginException(final Throwable throwable) {
6684
String sqlState = null;
6785
if (exception instanceof SQLException) {
6886
sqlState = ((SQLException) exception).getSQLState();
87+
} else if (targetDriverDialect != null) {
88+
sqlState = targetDriverDialect.getSQLState(throwable);
6989
}
7090

7191
if (isLoginException(sqlState)) {

wrapper/src/main/java/software/amazon/jdbc/exceptions/ExceptionHandler.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,32 @@
1616

1717
package software.amazon.jdbc.exceptions;
1818

19+
import org.checkerframework.checker.nullness.qual.Nullable;
20+
import software.amazon.jdbc.targetdriverdialect.TargetDriverDialect;
21+
1922
public interface ExceptionHandler {
2023

24+
/**
25+
* The method determines whether provided throwable is about any network issues.
26+
*
27+
* @deprecated Use similar method below that accepts throwable and target driver dialect.
28+
*/
29+
@Deprecated()
2130
boolean isNetworkException(Throwable throwable);
2231

32+
boolean isNetworkException(Throwable throwable, @Nullable TargetDriverDialect targetDriverDialect);
33+
2334
boolean isNetworkException(String sqlState);
2435

2536
boolean isLoginException(String sqlState);
2637

38+
/**
39+
* The method determines whether provided throwable is about any login or authentication issues.
40+
*
41+
* @deprecated Use similar method below that accepts throwable and target driver dialect.
42+
*/
43+
@Deprecated()
2744
boolean isLoginException(Throwable throwable);
45+
46+
boolean isLoginException(Throwable throwable, @Nullable TargetDriverDialect targetDriverDialect);
2847
}

wrapper/src/main/java/software/amazon/jdbc/exceptions/ExceptionManager.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import software.amazon.jdbc.Driver;
2020
import software.amazon.jdbc.dialect.Dialect;
21+
import software.amazon.jdbc.targetdriverdialect.TargetDriverDialect;
2122

2223
public class ExceptionManager {
2324

@@ -41,19 +42,21 @@ public static void resetCustomHandler() {
4142
Driver.resetCustomExceptionHandler();
4243
}
4344

44-
public boolean isLoginException(final Dialect dialect, final Throwable throwable) {
45+
public boolean isLoginException(
46+
final Dialect dialect, final Throwable throwable, final TargetDriverDialect targetDriverDialect) {
4547
final ExceptionHandler handler = getHandler(dialect);
46-
return handler.isLoginException(throwable);
48+
return handler.isLoginException(throwable, targetDriverDialect);
4749
}
4850

4951
public boolean isLoginException(final Dialect dialect, final String sqlState) {
5052
final ExceptionHandler handler = getHandler(dialect);
5153
return handler.isLoginException(sqlState);
5254
}
5355

54-
public boolean isNetworkException(final Dialect dialect, final Throwable throwable) {
56+
public boolean isNetworkException(
57+
final Dialect dialect, final Throwable throwable, final TargetDriverDialect targetDriverDialect) {
5558
final ExceptionHandler handler = getHandler(dialect);
56-
return handler.isNetworkException(throwable);
59+
return handler.isNetworkException(throwable, targetDriverDialect);
5760
}
5861

5962
public boolean isNetworkException(final Dialect dialect, final String sqlState) {

wrapper/src/main/java/software/amazon/jdbc/exceptions/GenericExceptionHandler.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import java.sql.SQLException;
2020
import java.util.Arrays;
2121
import java.util.List;
22+
import org.checkerframework.checker.nullness.qual.Nullable;
23+
import software.amazon.jdbc.targetdriverdialect.TargetDriverDialect;
24+
import software.amazon.jdbc.util.StringUtils;
2225

2326
public class GenericExceptionHandler implements ExceptionHandler {
2427

@@ -36,12 +39,22 @@ public class GenericExceptionHandler implements ExceptionHandler {
3639
);
3740

3841
@Override
39-
public boolean isNetworkException(final Throwable throwable) {
42+
public boolean isNetworkException(Throwable throwable) {
43+
return this.isNetworkException(throwable, null);
44+
}
45+
46+
@Override
47+
public boolean isNetworkException(final Throwable throwable, @Nullable TargetDriverDialect targetDriverDialect) {
4048
Throwable exception = throwable;
4149

4250
while (exception != null) {
4351
if (exception instanceof SQLException) {
4452
return isNetworkException(((SQLException) exception).getSQLState());
53+
} else if (targetDriverDialect != null) {
54+
String sqlState = targetDriverDialect.getSQLState(throwable);
55+
if (!StringUtils.isNullOrEmpty(sqlState)) {
56+
return isNetworkException(sqlState);
57+
}
4558
}
4659

4760
exception = exception.getCause();
@@ -66,7 +79,12 @@ public boolean isNetworkException(final String sqlState) {
6679
}
6780

6881
@Override
69-
public boolean isLoginException(final Throwable throwable) {
82+
public boolean isLoginException(Throwable throwable) {
83+
return this.isLoginException(throwable, null);
84+
}
85+
86+
@Override
87+
public boolean isLoginException(final Throwable throwable, TargetDriverDialect targetDriverDialect) {
7088
Throwable exception = throwable;
7189

7290
while (exception != null) {
@@ -77,6 +95,8 @@ public boolean isLoginException(final Throwable throwable) {
7795
String sqlState = null;
7896
if (exception instanceof SQLException) {
7997
sqlState = ((SQLException) exception).getSQLState();
98+
} else if (targetDriverDialect != null) {
99+
sqlState = targetDriverDialect.getSQLState(throwable);
80100
}
81101

82102
if (isLoginException(sqlState)) {

wrapper/src/main/java/software/amazon/jdbc/exceptions/MultiAzDbClusterPgExceptionHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package software.amazon.jdbc.exceptions;
1818

19-
import java.sql.SQLException;
2019
import java.util.Arrays;
2120
import java.util.Collections;
2221
import java.util.List;

wrapper/src/main/java/software/amazon/jdbc/exceptions/MySQLExceptionHandler.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
package software.amazon.jdbc.exceptions;
1818

19-
import com.mysql.cj.exceptions.CJException;
2019
import java.sql.SQLException;
20+
import org.checkerframework.checker.nullness.qual.Nullable;
21+
import software.amazon.jdbc.targetdriverdialect.TargetDriverDialect;
22+
import software.amazon.jdbc.util.StringUtils;
2123

2224
public class MySQLExceptionHandler implements ExceptionHandler {
2325
public static final String SQLSTATE_ACCESS_ERROR = "28000";
@@ -26,7 +28,12 @@ public class MySQLExceptionHandler implements ExceptionHandler {
2628
"setNetworkTimeout cannot be called on a closed connection";
2729

2830
@Override
29-
public boolean isNetworkException(final Throwable throwable) {
31+
public boolean isNetworkException(Throwable throwable) {
32+
return this.isNetworkException(throwable, null);
33+
}
34+
35+
@Override
36+
public boolean isNetworkException(final Throwable throwable, @Nullable TargetDriverDialect targetDriverDialect) {
3037
Throwable exception = throwable;
3138

3239
while (exception != null) {
@@ -44,8 +51,11 @@ public boolean isNetworkException(final Throwable throwable) {
4451
if (isNetworkException(sqlException.getSQLState()) || isHikariMariaDbNetworkException(sqlException)) {
4552
return true;
4653
}
47-
} else if (exception instanceof CJException) {
48-
return isNetworkException(((CJException) exception).getSQLState());
54+
} else if (targetDriverDialect != null) {
55+
String sqlState = targetDriverDialect.getSQLState(throwable);
56+
if (!StringUtils.isNullOrEmpty(sqlState)) {
57+
return isNetworkException(sqlState);
58+
}
4959
}
5060

5161
exception = exception.getCause();
@@ -64,7 +74,12 @@ public boolean isNetworkException(final String sqlState) {
6474
}
6575

6676
@Override
67-
public boolean isLoginException(final Throwable throwable) {
77+
public boolean isLoginException(Throwable throwable) {
78+
return this.isLoginException(throwable, null);
79+
}
80+
81+
@Override
82+
public boolean isLoginException(final Throwable throwable, @Nullable TargetDriverDialect targetDriverDialect) {
6883
Throwable exception = throwable;
6984

7085
while (exception != null) {
@@ -75,8 +90,8 @@ public boolean isLoginException(final Throwable throwable) {
7590
String sqlState = null;
7691
if (exception instanceof SQLException) {
7792
sqlState = ((SQLException) exception).getSQLState();
78-
} else if (exception instanceof CJException) {
79-
sqlState = ((CJException) exception).getSQLState();
93+
} else if (targetDriverDialect != null) {
94+
sqlState = targetDriverDialect.getSQLState(throwable);
8095
}
8196

8297
if (isLoginException(sqlState)) {

wrapper/src/main/java/software/amazon/jdbc/plugin/AuroraInitialConnectionStrategyPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private Connection getVerifiedWriterConnection(
228228

229229
} catch (SQLException ex) {
230230
this.closeConnection(writerCandidateConn);
231-
if (this.pluginService.isLoginException(ex)) {
231+
if (this.pluginService.isLoginException(ex, this.pluginService.getTargetDriverDialect())) {
232232
throw WrapperUtils.wrapExceptionIfNeeded(SQLException.class, ex);
233233
} else {
234234
if (writerCandidate != null) {
@@ -322,7 +322,7 @@ private Connection getVerifiedReaderConnection(
322322

323323
} catch (SQLException ex) {
324324
this.closeConnection(readerCandidateConn);
325-
if (this.pluginService.isLoginException(ex)) {
325+
if (this.pluginService.isLoginException(ex, this.pluginService.getTargetDriverDialect())) {
326326
throw WrapperUtils.wrapExceptionIfNeeded(SQLException.class, ex);
327327
} else {
328328
if (readerCandidate != null) {

wrapper/src/main/java/software/amazon/jdbc/plugin/AwsSecretsManagerConnectionPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ private Connection connectInternal(HostSpec hostSpec, Properties props,
202202
return connectFunc.call();
203203

204204
} catch (final SQLException exception) {
205-
if (this.pluginService.isLoginException(exception) && !secretWasFetched) {
205+
if (this.pluginService.isLoginException(exception, this.pluginService.getTargetDriverDialect())
206+
&& !secretWasFetched) {
206207
// Login unsuccessful with cached credentials
207208
// Try to re-fetch credentials and try again
208209

wrapper/src/main/java/software/amazon/jdbc/plugin/iam/IamAuthConnectionPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ private Connection connectInternal(String driverProtocol, HostSpec hostSpec, Pro
180180
"IamAuthConnectionPlugin.connectException",
181181
new Object[] {exception}));
182182

183-
if (!this.pluginService.isLoginException(exception) || !isCachedToken) {
183+
if (!this.pluginService.isLoginException(exception, this.pluginService.getTargetDriverDialect())
184+
|| !isCachedToken) {
184185
throw exception;
185186
}
186187

0 commit comments

Comments
 (0)