Class JdbcDataSource

java.lang.Object
com.jsgalactic.axiom.jdbc.JdbcDataSource
All Implemented Interfaces:
AutoCloseable, Wrapper, CommonDataSource, DataSource

public final class JdbcDataSource extends Object implements DataSource, AutoCloseable
A DataSource that delegates every call to an application-owned source and records connection checkouts through the Axiom Metrics SPI.

 DataSource counted = new JdbcDataSource(applicationOwnedDataSource, options, app.metrics());
 

The delegate is never closed by this wrapper, on any path. Each returned Connection is a delegate that forwards to the real connection; the first close() on it counts one release and closes the real connection. A later close() is a no-op. The name from JdbcOptions is the only tag value on the connection series, so the series stay bounded however many connections the application opens. No SQL, URL, user, password or request value is ever recorded.

The acquired counter increases on every successful checkout. The released counter increases once per returned connection that is closed. The waited counter increases on a checkout that overlapped an outstanding checkout of this wrapper: it reports contention seen here, not the delegate's internal queue depth. The wait timer records the time spent inside the delegate's getConnection, so an application can see whether a wait was a real one. Health probes use the unwrapped source and are not counted.

Instances are thread-safe. close() never closes the delegate DataSource; it closes only wrapped connections that are still open, and only when JdbcOptions.closeConnectionsOnShutdown() is true.

  • Constructor Details

    • JdbcDataSource

      public JdbcDataSource(DataSource delegate, JdbcOptions options, Metrics metrics)
      Wraps a source with checked-out connection counters.
      Parameters:
      delegate - application-owned source, never closed by this wrapper
      options - bounds and the bounded metric name
      metrics - where the counters and timer are recorded
      Throws:
      NullPointerException - if an argument is null
  • Method Details