ConnectionListener extends DefaultExecuteListener {
...
public ConnectionListener() {}
@Override
public void exception(ExecuteContext ctx) {
try {
if (ctx != null && ctx.exception() != null) {
//Proceed to check if we recieved a DataAccessException
if (ctx.exception() instanceof DataAccessException) {
DataAccessException exception = (DataAccessException) ctx.exception();
//If the error is network related discard the connection
if (isNetworkError(exception)) {
//The underlying ProxyConnection which we need to call setDiscarded is a few levels deep
Connection conn = ctx.connection();
DefaultConnection dConn = (DefaultConnection) conn;
SettingsEnabledConnection sConn = (SettingsEnabledConnection) dConn;
ProviderEnabledConnection pConn = (ProviderEnabledConnection) sConn.getDelegate();
//Get the Proxy connection handler
InvocationHandler handler = Proxy.getInvocationHandler(pConn.getDelegate());
//Get the Proxy connection
ProxyConnection proxyConnection = (ProxyConnection)
((DisposableConnectionFacade) handler).getNext();
//Discard the connection
proxyConnection.getConnection().setDiscarded(true);
}
}
}
} catch (Exception e) {
logger.error("ConnectionListener caught unexpected error", e);
}
}
I'm aware that checkConnectionOnBorrow and upping the validation interval to something shorter than the default 30 seconds will reduce the errors but I'd like to drop the connection on the first failure.
--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.