Class DataSource

java.lang.Object
org.apache.tomcat.jdbc.pool.DataSourceProxy
org.apache.tomcat.jdbc.pool.DataSource
All Implemented Interfaces:
Wrapper, MBeanRegistration, CommonDataSource, ConnectionPoolDataSource, DataSource, ConnectionPoolMBean, PoolConfiguration
Direct Known Subclasses:
XADataSource

A DataSource that can be instantiated through IoC and implements the DataSource interface since the DataSourceProxy is used as a generic proxy. The DataSource simply wraps a ConnectionPool in order to provide a standard interface to the user.
  • Field Details

    • oname

      protected volatile ObjectName oname
      The JMX ObjectName for the connection pool MBean. The handle is checked, cleared and released only under this data source's monitor.
  • Constructor Details

    • DataSource

      public DataSource()
      Constructor for reflection only. A default set of pool properties will be created.
    • DataSource

      public DataSource(PoolConfiguration poolProperties)
      Constructs a DataSource object wrapping a connection
      Parameters:
      poolProperties - The pool properties
  • Method Details

    • close

      public void close(boolean all)
      Unregisters the connection pool MBean before closing the pool, so a dead pool does not keep reporting stale statistics under a live object name (and does not pin the closed pool, its credentials and its JDBC driver class loader in the MBean server).
      Close the connection pool. If a pool creation is in flight, this method does not wait for it - the driver connects of the creation's initial pre-load can block for an unbounded, uninterruptible time against a hung database - it marks this data source closed and returns: the creation observes the closure at its publication step and closes the pool it built instead of publishing it.
      Overrides:
      close in class DataSourceProxy
      Parameters:
      all - if true close all connections, otherwise only idle ones
    • postDeregister

      public void postDeregister()
      Unregisters the underlying connection pool mbean.
      Specified by:
      postDeregister in interface MBeanRegistration
    • postRegister

      public void postRegister(Boolean registrationDone)
      Releases the pool MBean that preRegister(MBeanServer, ObjectName) published when the MBean server did not complete this DataSource's own registration. Per the MBeanRegistration contract a false registrationDone means that the registration phase failed, and after a failed registration the server does not call postDeregister(): this callback is the only chance to undo that side effect. Leaving the pool MBean registered would keep a pool nobody manages reporting statistics and notifications, and would pin the pool - with its properties, its credentials and its JDBC driver class loader - in the MBean server.
      Specified by:
      postRegister in interface MBeanRegistration
    • preDeregister

      public void preDeregister() throws Exception
      no-op
      Specified by:
      preDeregister in interface MBeanRegistration
      Throws:
      Exception
    • preRegister

      public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
      If the connection pool MBean exists, it will be registered during this operation.
      Specified by:
      preRegister in interface MBeanRegistration
      Throws:
      Exception
    • createObjectName

      public ObjectName createObjectName(ObjectName original) throws MalformedObjectNameException
      Creates the ObjectName for the ConnectionPoolMBean object to be registered
      Parameters:
      original - the ObjectName for the DataSource
      Returns:
      the ObjectName for the ConnectionPoolMBean
      Throws:
      MalformedObjectNameException - Invalid object name
    • registerJmx

      protected void registerJmx()
      Registers the ConnectionPoolMBean under a unique name based on the ObjectName for the DataSource. A pool that has not been created yet (or was already closed) has no MBean to publish; the registration is then skipped rather than failing, since the caller of preRegister(MBeanServer, ObjectName) must not see an exception over pool-side lifecycle state. A publish the MBean server refused - because the name is already in use by another MBean, for instance - is likewise not this pool's registration.
    • unregisterJmx

      protected void unregisterJmx(ObjectName name)
      Unregisters the ConnectionPoolMBean published under the given name. The name is the registration handle captured by the caller, which holds this data source's monitor: the handle is checked, cleared and released as one step there, so it never reaches this method twice and a name this data source never published is never released.
      Parameters:
      name - the ObjectName the pool MBean was published under, or null to release nothing