Skip to content

Commit

Permalink
fixes#1960 allow SQLExceptionOverride to adjudicate all exceptions fo…
Browse files Browse the repository at this point in the history
…r eviction
  • Loading branch information
brettwooldridge committed Nov 2, 2024
1 parent f6efe91 commit c6d1403
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/main/java/com/zaxxer/hikari/pool/ProxyConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Set;
import java.util.concurrent.Executor;

import static com.zaxxer.hikari.SQLExceptionOverride.Override.CONTINUE_EVICT;
import static com.zaxxer.hikari.SQLExceptionOverride.Override.DO_NOT_EVICT;

/**
Expand Down Expand Up @@ -155,15 +156,14 @@ final SQLException checkException(SQLException sqle)
final var exceptionOverride = poolEntry.getPoolBase().exceptionOverride;
for (int depth = 0; delegate != ClosedConnection.CLOSED_CONNECTION && nse != null && depth < 10; depth++) {
final var sqlState = nse.getSQLState();
if (sqlState != null && sqlState.startsWith("08")
if (exceptionOverride != null && exceptionOverride.adjudicate(nse) == DO_NOT_EVICT) {
break;
}
else if (sqlState != null && sqlState.startsWith("08")
|| nse instanceof SQLTimeoutException
|| ERROR_STATES.contains(sqlState)
|| ERROR_CODES.contains(nse.getErrorCode())) {

if (exceptionOverride != null && exceptionOverride.adjudicate(nse) == DO_NOT_EVICT) {
break;
}

// broken connection
evict = true;
break;
Expand Down Expand Up @@ -544,20 +544,17 @@ private static Connection getClosedConnection()
{
InvocationHandler handler = (proxy, method, args) -> {
final String methodName = method.getName();
if ("isClosed".equals(methodName)) {
return Boolean.TRUE;
}
else if ("isValid".equals(methodName)) {
return Boolean.FALSE;
}
if ("abort".equals(methodName)) {
return Void.TYPE;
}
if ("close".equals(methodName)) {
return Void.TYPE;
}
else if ("toString".equals(methodName)) {
return ClosedConnection.class.getCanonicalName();
switch (methodName) {
case "isClosed":
return Boolean.TRUE;
case "isValid":
return Boolean.FALSE;
case "abort":
return Void.TYPE;
case "close":
return Void.TYPE;
case "toString":
return ClosedConnection.class.getCanonicalName();
}

throw new SQLException("Connection is closed");
Expand Down

0 comments on commit c6d1403

Please sign in to comment.