brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
19.63k stars 2.9k forks source link

ability to set exceptionOverride instance, not just class name #2171

Open hgschmie opened 4 months ago

hgschmie commented 4 months ago

Hi,

We have an issue with spurious messages where the server gets shut down while some test code is still running. Our test cases work fine, but this creates messages like this:

WARN com.zaxxer.hikari.pool.ProxyConnection - jdbi-template-pool (*.*) - Connection oracle.jdbc.driver.T4CConnection@4886b6bd marked as broken because of SQLSTATE(08006), ErrorCode(18730)

I know it is broken, because we just shut down the server. To suppress those messages (QE keeps pestering us about "exceptions in test cases"), I am using a simple SQLExceptionOverride implementation that, in case we are in the process of shutting down, reject eviction (which suppresses that message).

However, because I can only pass in the class name into the config, I need to use a class level field to set that state. I'd like to use an instance level field (because I might use multiple connection pools). Right now, I am using this:

public static final class ExceptionOverrider implements SQLExceptionOverride {
        private static volatile boolean CLOSED = false;

        public Override adjudicate(SQLException sqlException) {
            return CLOSED ? Override.DO_NOT_EVICT : Override.CONTINUE_EVICT;
        }
    }

and call ExceptionOverrider.CLOSED = true to change state.

but I want to use this:

public static final class ExceptionOverrider implements SQLExceptionOverride {
        private volatile boolean closed = false;

        public Override adjudicate(SQLException sqlException) {
            return closed ? Override.DO_NOT_EVICT : Override.CONTINUE_EVICT;
        }
    }

which would allow me to use multiple, independent overrider instances.

However, I can neither pass my instance into the config (It only takes a string with the class name) nor can I retrieve the instantiated object from the pool base (It is package private and there is no setter).

Is it possible to make that instance accessible (make that field public final similar to the config)?

quaff commented 4 months ago

It should be covered by https://github.com/brettwooldridge/HikariCP/pull/2133.