Skip to content

Commit 184ee2d

Browse files
authored
Include exception cause in applicable ReadWriteSplittingSQLExceptions (#415)
### By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent da878e8 commit 184ee2d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

wrapper/src/main/java/software/amazon/jdbc/plugin/readwritesplitting/ReadWriteSplittingPlugin.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ void switchConnectionIfRequired(final boolean readOnly) throws SQLException {
295295
} catch (final SQLException e) {
296296
if (!isConnectionUsable(currentConnection)) {
297297
logAndThrowException(Messages.get("ReadWriteSplittingPlugin.errorSwitchingToReader"),
298-
SqlState.CONNECTION_UNABLE_TO_CONNECT);
298+
SqlState.CONNECTION_UNABLE_TO_CONNECT, e);
299299
return;
300300
}
301301

@@ -318,7 +318,7 @@ void switchConnectionIfRequired(final boolean readOnly) throws SQLException {
318318
switchToWriterConnection(hosts);
319319
} catch (final SQLException e) {
320320
logAndThrowException(Messages.get("ReadWriteSplittingPlugin.errorSwitchingToWriter"),
321-
SqlState.CONNECTION_UNABLE_TO_CONNECT);
321+
SqlState.CONNECTION_UNABLE_TO_CONNECT, e);
322322
}
323323
}
324324
}
@@ -335,6 +335,13 @@ private void logAndThrowException(final String logMessage, final SqlState sqlSta
335335
throw new ReadWriteSplittingSQLException(logMessage, sqlState.getState());
336336
}
337337

338+
private void logAndThrowException(
339+
final String logMessage, final SqlState sqlState, final Throwable cause)
340+
throws SQLException {
341+
LOGGER.severe(logMessage);
342+
throw new ReadWriteSplittingSQLException(logMessage, sqlState.getState(), cause);
343+
}
344+
338345
private synchronized void switchToWriterConnection(
339346
final List<HostSpec> hosts)
340347
throws SQLException {

wrapper/src/test/java/integration/refactored/container/tests/ReadWriteSplittingTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import java.util.concurrent.TimeUnit;
5454
import java.util.logging.Logger;
5555
import java.util.stream.Collectors;
56-
import org.junit.jupiter.api.Disabled;
5756
import org.junit.jupiter.api.MethodOrderer;
5857
import org.junit.jupiter.api.TestMethodOrder;
5958
import org.junit.jupiter.api.TestTemplate;

0 commit comments

Comments
 (0)