DataSource (Apache Tomcat 10.1.48 API Documentation)
Description: declaration: package: org.apache.tomcat.jdbc.pool, class: DataSource

# 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`

public class DataSource extends DataSourceProxy implements DataSource, MBeanRegistration, ConnectionPoolMBean, ConnectionPoolDataSource
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 Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected ObjectName`
  `oname`

  ### Fields inherited from class DataSourceProxy

  `pool, poolProperties`

  ### Fields inherited from interface PoolConfiguration

  `PKG_PREFIX`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DataSource()`
  Constructor for reflection only.
  `DataSource(PoolConfiguration poolProperties)`
  Constructs a DataSource object wrapping a connection

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ObjectName`
  `createObjectName(ObjectName original)`
  Creates the ObjectName for the ConnectionPoolMBean object to be registered
  `void`
  `postDeregister()`
  Unregisters the underlying connection pool mbean.
  `void`
  `postRegister(Boolean registrationDone)`
  no-op
  `void`
  `preDeregister()`
  no-op
  `ObjectName`
  `preRegister(MBeanServer server, ObjectName name)`
  If the connection pool MBean exists, it will be registered during this operation.
  `protected void`
  `registerJmx()`
  Registers the ConnectionPoolMBean under a unique name based on the ObjectName for the DataSource
  `protected void`
  `unregisterJmx()`

  ### Methods inherited from class DataSourceProxy

  `checkAbandoned, checkIdle, close, close, createPool, getAbandonWhenPercentageFull, getActive, getBorrowedCount, getCommitOnReturn, getConnection, getConnection, getConnectionAsync, getConnectionProperties, getCreatedCount, getDataSource, getDataSourceJNDI, getDbProperties, getDefaultAutoCommit, getDefaultCatalog, getDefaultReadOnly, getDefaultTransactionIsolation, getDriverClassName, getIdle, getInitialSize, getInitSQL, getJdbcInterceptors, getJdbcInterceptorsAsArray, getLoginTimeout, getLogValidationErrors, getLogWriter, getMaxActive, getMaxAge, getMaxIdle, getMaxWait, getMinEvictableIdleTimeMillis, getMinIdle, getName, getNumActive, getNumIdle, getNumTestsPerEvictionRun, getParentLogger, getPassword, getPool, getPooledConnection, getPooledConnection, getPoolName, getPoolProperties, getPoolSize, getPropagateInterruptState, getReconnectedCount, getReleasedCount, getReleasedIdleCount, getRemoveAbandonedCount, getRemoveAbandonedTimeout, getReturnedCount, getRollbackOnReturn, getSize, getSuspectTimeout, getTimeBetweenEvictionRunsMillis, getUrl, getUseDisposableConnectionFacade, getUseLock, getUsername, getUseStatementFacade, getValidationInterval, getValidationQuery, getValidationQueryTimeout, getValidator, getValidatorClassName, getWaitCount, getXAConnection, getXAConnection, isAccessToUnderlyingConnectionAllowed, isAlternateUsernameAllowed, isDefaultAutoCommit, isDefaultReadOnly, isFairQueue, isIgnoreExceptionOnPreLoad, isJmxEnabled, isLogAbandoned, isPoolSweeperEnabled, isRemoveAbandoned, isTestOnBorrow, isTestOnConnect, isTestOnReturn, isTestWhileIdle, isUseEquals, isWrapperFor, purge, purgeOnReturn, resetStats, setAbandonWhenPercentageFull, setAccessToUnderlyingConnectionAllowed, setAlternateUsernameAllowed, setCommitOnReturn, setConnectionProperties, setDataSource, setDataSourceJNDI, setDbProperties, setDefaultAutoCommit, setDefaultCatalog, setDefaultReadOnly, setDefaultTransactionIsolation, setDriverClassName, setFairQueue, setIgnoreExceptionOnPreLoad, setInitialSize, setInitSQL, setJdbcInterceptors, setJmxEnabled, setLogAbandoned, setLoginTimeout, setLogValidationErrors, setLogWriter, setMaxActive, setMaxAge, setMaxIdle, setMaxWait, setMinEvictableIdleTimeMillis, setMinIdle, setName, setNumTestsPerEvictionRun, setPassword, setPoolProperties, setPropagateInterruptState, setRemoveAbandoned, setRemoveAbandonedTimeout, setRollbackOnReturn, setSuspectTimeout, setTestOnBorrow, setTestOnConnect, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRunsMillis, setUrl, setUseDisposableConnectionFacade, setUseEquals, setUseLock, setUsername, setUseStatementFacade, setValidationInterval, setValidationQuery, setValidationQueryTimeout, setValidator, setValidatorClassName, testIdle, toString, unwrap`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface CommonDataSource

  `createShardingKeyBuilder, getParentLogger`

  ### Methods inherited from interface ConnectionPoolDataSource

  `createPooledConnectionBuilder, getLoginTimeout, getLogWriter, getPooledConnection, getPooledConnection, setLoginTimeout, setLogWriter`

  ### Methods inherited from interface ConnectionPoolMBean

  `checkAbandoned, checkIdle, getActive, getBorrowedCount, getCreatedCount, getIdle, getNumActive, getNumIdle, getReconnectedCount, getReleasedCount, getReleasedIdleCount, getRemoveAbandonedCount, getReturnedCount, getSize, getWaitCount, purge, purgeOnReturn, resetStats, testIdle`

  ### Methods inherited from interface DataSource

  `createConnectionBuilder, getConnection, getConnection, getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter`

  ### Methods inherited from interface PoolConfiguration

  `getAbandonWhenPercentageFull, getCommitOnReturn, getConnectionProperties, getDataSource, getDataSourceJNDI, getDbProperties, getDefaultAutoCommit, getDefaultCatalog, getDefaultReadOnly, getDefaultTransactionIsolation, getDriverClassName, getInitialSize, getInitSQL, getJdbcInterceptors, getJdbcInterceptorsAsArray, getLogValidationErrors, getMaxActive, getMaxAge, getMaxIdle, getMaxWait, getMinEvictableIdleTimeMillis, getMinIdle, getName, getNumTestsPerEvictionRun, getPassword, getPoolName, getPropagateInterruptState, getRemoveAbandonedTimeout, getRollbackOnReturn, getSuspectTimeout, getTimeBetweenEvictionRunsMillis, getUrl, getUseDisposableConnectionFacade, getUseLock, getUsername, getUseStatementFacade, getValidationInterval, getValidationQuery, getValidationQueryTimeout, getValidator, getValidatorClassName, isAccessToUnderlyingConnectionAllowed, isAlternateUsernameAllowed, isDefaultAutoCommit, isDefaultReadOnly, isFairQueue, isIgnoreExceptionOnPreLoad, isJmxEnabled, isLogAbandoned, isPoolSweeperEnabled, isRemoveAbandoned, isTestOnBorrow, isTestOnConnect, isTestOnReturn, isTestWhileIdle, isUseEquals, setAbandonWhenPercentageFull, setAccessToUnderlyingConnectionAllowed, setAlternateUsernameAllowed, setCommitOnReturn, setConnectionProperties, setDataSource, setDataSourceJNDI, setDbProperties, setDefaultAutoCommit, setDefaultCatalog, setDefaultReadOnly, setDefaultTransactionIsolation, setDriverClassName, setFairQueue, setIgnoreExceptionOnPreLoad, setInitialSize, setInitSQL, setJdbcInterceptors, setJmxEnabled, setLogAbandoned, setLogValidationErrors, setMaxActive, setMaxAge, setMaxIdle, setMaxWait, setMinEvictableIdleTimeMillis, setMinIdle, setName, setNumTestsPerEvictionRun, setPassword, setPropagateInterruptState, setRemoveAbandoned, setRemoveAbandonedTimeout, setRollbackOnReturn, setSuspectTimeout, setTestOnBorrow, setTestOnConnect, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRunsMillis, setUrl, setUseDisposableConnectionFacade, setUseEquals, setUseLock, setUsername, setUseStatementFacade, setValidationInterval, setValidationQuery, setValidationQueryTimeout, setValidator, setValidatorClassName`

  ### Methods inherited from interface Wrapper

  `isWrapperFor, unwrap`

- ## Field Details

  - ### oname

    protected volatile ObjectName oname

- ## 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

  - ### postDeregister

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

  - ### postRegister

    public void postRegister(Boolean registrationDone)
    no-op
    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

  - ### unregisterJmx

    protected void unregisterJmx()