Class DataSourceProxy

java.lang.Object
org.apache.tomcat.jdbc.pool.DataSourceProxy
All Implemented Interfaces:
PoolConfiguration
Direct Known Subclasses:
DataSource

public class DataSourceProxy extends Object implements PoolConfiguration
The data source base of the pool: it delegates every configuration property to the PoolConfiguration it holds and implements the DataSource accessors on top of a lazily created ConnectionPool. The class doubles as the data source's own JMX/bean surface, which is why the public getters and setters here are the attribute surface a container publishes.
  • Field Details

    • pool

      protected volatile ConnectionPool pool
      The underlying connection pool.
    • poolProperties

      protected volatile PoolConfiguration poolProperties
      The pool configuration properties.
  • Constructor Details

    • DataSourceProxy

      public DataSourceProxy()
      Construct a DataSourceProxy with default pool properties.
    • DataSourceProxy

      public DataSourceProxy(PoolConfiguration poolProperties)
      Construct a DataSourceProxy with the given pool configuration.
      Parameters:
      poolProperties - The pool configuration properties
  • Method Details

    • isWrapperFor

      public boolean isWrapperFor(Class<?> iface) throws SQLException
      Check if this proxy implements, or wraps an instance of, the given interface. The configured DataSource, if any, is checked as the wrapped object.

      Has to match signature in DataSource.

      Parameters:
      iface - The interface to check
      Returns:
      true if this proxy implements the interface or wraps an object that does
      Throws:
      SQLException - if the wrapped data source throws one
    • unwrap

      public <T> T unwrap(Class<T> iface) throws SQLException
      Unwrap the proxy to the given interface. The configured DataSource, if any, is checked as the wrapped object.

      Has to match signature in DataSource

      Type Parameters:
      T - The interface type
      Parameters:
      iface - The interface to unwrap to
      Returns:
      an object that implements the interface
      Throws:
      SQLException - if no object implementing the interface is found
    • getConnection

      public Connection getConnection(String username, String password) throws SQLException
      Get a database connection. DataSource.getConnection()
      Parameters:
      username - The user name
      password - The password
      Returns:
      the connection
      Throws:
      SQLException - Connection error, or this data source has been closed
    • getPoolProperties

      public PoolConfiguration getPoolProperties()
      Return the pool configuration properties.
      Returns:
      the pool configuration
    • createPool

      public ConnectionPool createPool() throws SQLException
      Sets up the connection pool, by creating a pooling driver. The reference is taken from the volatile field with a single read, so that the borrow paths which use this method as their single point of access cannot observe a null that a concurrent close(boolean) published after they saw the field set. The result is never null: it is either the pool that is in use or this method fails with an SQLException.
      Returns:
      the connection pool
      Throws:
      SQLException - Error creating pool, or if this data source has been closed
    • getConnection

      public Connection getConnection() throws SQLException
      Get a database connection. DataSource.getConnection()
      Returns:
      the connection
      Throws:
      SQLException - Connection error, or this data source has been closed
    • getConnectionAsync

      public Future<Connection> getConnectionAsync() throws SQLException
      Retrieves a connection future: the pool's synchronous borrow is invoked first with no wait, and when a connection cannot be handed out immediately the returned future completes once one becomes available.
      Returns:
      a Future containing a reference to the connection when it becomes available
      Throws:
      SQLException - Connection error, or this data source has been closed
    • getXAConnection

      public XAConnection getXAConnection() throws SQLException
      Get a database connection. XADataSource.getXAConnection()
      Returns:
      the connection
      Throws:
      SQLException - Connection error
    • getXAConnection

      public XAConnection getXAConnection(String username, String password) throws SQLException
      Parameters:
      username - The user name
      password - The password
      Returns:
      the connection
      Throws:
      SQLException - Connection error
    • getPooledConnection

      public PooledConnection getPooledConnection() throws SQLException
      Get a database connection. DataSource.getConnection()
      Returns:
      the connection
      Throws:
      SQLException - Connection error
    • getPooledConnection

      public PooledConnection getPooledConnection(String username, String password) throws SQLException
      Get a database connection. DataSource.getConnection(String,String)
      Parameters:
      username - The user name
      password - The password
      Returns:
      the connection
      Throws:
      SQLException - Connection error
    • getPool

      public ConnectionPool getPool()
      Return the underlying connection pool, creating it if necessary.
      Returns:
      the connection pool, or null if creation failed or this data source has been closed
    • close

      public void close()
      Close the connection pool, returning connections to the database. The closure is terminal: later borrow or pool creation attempts on this data source fail with an SQLException instead of recreating the pool.
    • close

      public void close(boolean all)
      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. The same reason keeps the teardown outside the monitor: the physical disconnect of every pooled session is as unbounded against a hung database as the connect is, and it must not park the paths that need the monitor meanwhile - a later borrow's publication step, or the container's JMX lifecycle callbacks.
      Parameters:
      all - if true close all connections, otherwise only idle ones
    • takePoolForClose

      protected ConnectionPool takePoolForClose()
      Sets the terminal closed flag and takes the published pool, as one step under this data source's monitor. The check-and-publish race this closes with is told at pCreatePool()'s publication step, which takes the same monitor: whichever of the two runs first wins. The closed flag makes the closure terminal for the pool creation paths as well: a closed data source no longer resurrects its pool on the next borrow or statistics access.
      Returns:
      the pool that must now be torn down, or null when nothing was published (yet)
    • closePool

      protected void closePool(ConnectionPool p, boolean all)
      Tears down the pool that takePoolForClose() handed over, outside this data source's monitor: a physical disconnect against a hung database is unbounded and uninterruptible, and a parked teardown must not park the later borrows or lifecycle callbacks that need that monitor. A failure of the teardown is logged, not propagated: the closure already happened when the flag was set, and one failing session must not stop the rest from being disconnected or hide the closure from the caller.
      Parameters:
      p - the pool to close, or null to close nothing
      all - if true close all connections, otherwise only idle ones
    • getPoolSize

      public int getPoolSize()
      Return the current number of connections in the pool. The pool is not created by this call: before the pool has been created, and after it has been closed, this returns 0 even though the configuration asks for more connections. See getSize() for the reading that creates the pool when necessary.
      Returns:
      the pool size, or 0 while no pool instance exists
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPoolName

      public String getPoolName()
      Description copied from interface: PoolConfiguration
      Returns the name of the connection pool. This is the same value as returned by PoolConfiguration.getName().
      Specified by:
      getPoolName in interface PoolConfiguration
      Returns:
      the pool name
    • setPoolProperties

      public void setPoolProperties(PoolConfiguration poolProperties)
      Replaces the configuration this data source hands out. A pool that already exists keeps the configuration it was built from; only a pool created afterwards uses the replacement. The one thing the replacement reaches on a running pool is its background maintenance, which is judged from this class's current configuration.
      Parameters:
      poolProperties - The new pool configuration
    • setDriverClassName

      public void setDriverClassName(String driverClassName)
      Description copied from interface: PoolConfiguration
      The fully qualified Java class name of the JDBC driver to be used. The driver has to be accessible from the same classloader as tomcat-jdbc.jar
      Specified by:
      setDriverClassName in interface PoolConfiguration
      Parameters:
      driverClassName - a fully qualified Java class name of a Driver implementation.
    • setInitialSize

      public void setInitialSize(int initialSize)
      Description copied from interface: PoolConfiguration
      Set the number of connections that will be established when the connection pool is started. Default value is 10. If this value exceeds PoolConfiguration.setMaxActive(int) it will automatically be lowered.
      Specified by:
      setInitialSize in interface PoolConfiguration
      Parameters:
      initialSize - the number of connections to be established.
    • setInitSQL

      public void setInitSQL(String initSQL)
      Description copied from interface: PoolConfiguration
      A custom query to be run when a connection is first created. The default value is null. This query only runs once per connection, and that is when a new connection is established to the database. If this value is non null, it will replace the validation query during connection creation.

      The query runs while the pool is initializing the freshly established session, and the pool terminates the transaction it executes into by commit, so its effects - a data change or a session setting - persist for the lifetime of the connection even when the pool runs with auto commit off. A validation query follows the opposite rule and terminates an open transaction by rollback, so a health check never commits application work. A pool configured with a custom Validator does not run this query at all: the validator replaces the validation itself.

      Specified by:
      setInitSQL in interface PoolConfiguration
      Parameters:
      initSQL - the init SQL used to run against the DB or null if no query should be executed
    • setLogAbandoned

      public void setLogAbandoned(boolean logAbandoned)
      Description copied from interface: PoolConfiguration
      boolean flag to set if stack traces should be logged for application code which abandoned a Connection. Logging of abandoned Connections adds overhead for every Connection borrow because a stack trace has to be generated. The default value is false.
      Specified by:
      setLogAbandoned in interface PoolConfiguration
      Parameters:
      logAbandoned - set to true if stack traces should be recorded when getConnection() is called.
    • setMaxActive

      public void setMaxActive(int maxActive)
      Description copied from interface: PoolConfiguration
      The maximum number of active connections that can be allocated from this pool at the same time. The default value is 100
      Specified by:
      setMaxActive in interface PoolConfiguration
      Parameters:
      maxActive - hard limit for number of managed connections by this pool
    • setMaxIdle

      public void setMaxIdle(int maxIdle)
      Description copied from interface: PoolConfiguration
      The maximum number of connections that should be kept in the idle pool if PoolConfiguration.isPoolSweeperEnabled() returns false. If PoolConfiguration.isPoolSweeperEnabled() returns true, then the idle pool can grow up to PoolConfiguration.getMaxActive() and will be shrunk according to PoolConfiguration.getMinEvictableIdleTimeMillis() setting. Default value is PoolConfiguration.getMaxActive() (100 with the default configuration)
      Specified by:
      setMaxIdle in interface PoolConfiguration
      Parameters:
      maxIdle - the maximum size of the idle pool
    • setMaxWait

      public void setMaxWait(int maxWait)
      Description copied from interface: PoolConfiguration
      The maximum number of milliseconds that the pool will wait (when there are no available connections and the PoolConfiguration.getMaxActive() has been reached) for a connection to be returned before throwing an exception. A value less than or equal to zero makes the pool wait indefinitely for a connection to be returned instead of timing out. Default value is 30000 (30 seconds)
      Specified by:
      setMaxWait in interface PoolConfiguration
      Parameters:
      maxWait - the maximum number of milliseconds to wait.
    • setMinEvictableIdleTimeMillis

      public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis)
      Description copied from interface: PoolConfiguration
      The minimum amount of time an object must sit idle in the pool before it is eligible for eviction. The default value is 60000 (60 seconds).
      Specified by:
      setMinEvictableIdleTimeMillis in interface PoolConfiguration
      Parameters:
      minEvictableIdleTimeMillis - the number of milliseconds a connection must be idle to be eligible for eviction.
    • setMinIdle

      public void setMinIdle(int minIdle)
      Description copied from interface: PoolConfiguration
      The minimum number of established connections that should be kept in the pool at all times. The connection pool can shrink below this number if validation queries fail and connections get closed. The default is the value PoolConfiguration.getInitialSize() had when this configuration was constructed; changing initialSize later does not move it, so set this explicitly to change the floor (also see PoolConfiguration.setTestWhileIdle(boolean)). The eviction run normally keeps the total number of connections in the pool - idle plus busy - at or above this value, hence the number of actual connections can be between PoolConfiguration.getMinIdle() and somewhere between PoolConfiguration.getMaxIdle() and PoolConfiguration.getMaxActive(). A connection left over from an earlier pool generation is released regardless, so an explicit idle check after a purge can take the pool below the floor.
      Specified by:
      setMinIdle in interface PoolConfiguration
      Parameters:
      minIdle - the minimum number of idle or established connections
    • setNumTestsPerEvictionRun

      public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
      Description copied from interface: PoolConfiguration
      Property not used
      Specified by:
      setNumTestsPerEvictionRun in interface PoolConfiguration
      Parameters:
      numTestsPerEvictionRun - parameter ignored.
    • setPassword

      public void setPassword(String password)
      Sets the password used to establish connections with. The pool configuration keeps the matching database property in step, so a null password also removes it. Connections that are already established keep the credential they connected with until they leave the pool.
      Specified by:
      setPassword in interface PoolConfiguration
      Parameters:
      password - the password, or null to take the credential away
      See Also:
    • setRemoveAbandoned

      public void setRemoveAbandoned(boolean removeAbandoned)
      Description copied from interface: PoolConfiguration
      boolean flag to remove abandoned connections if they exceed the removeAbandonedTimeout. If set to true a connection is considered abandoned and eligible for removal if it has been in use longer than the PoolConfiguration.getRemoveAbandonedTimeout() and the condition for PoolConfiguration.getAbandonWhenPercentageFull() is met. Setting this to true can recover db connections from applications that fail to close a connection. See also PoolConfiguration.isLogAbandoned() The default value is false.
      Specified by:
      setRemoveAbandoned in interface PoolConfiguration
      Parameters:
      removeAbandoned - set to true if abandoned connections can be closed and expelled out of the pool
    • setRemoveAbandonedTimeout

      public void setRemoveAbandonedTimeout(int removeAbandonedTimeout)
      Description copied from interface: PoolConfiguration
      The time in seconds before a connection can be considered abandoned. The timer can be reset upon queries using an interceptor.
      Specified by:
      setRemoveAbandonedTimeout in interface PoolConfiguration
      Parameters:
      removeAbandonedTimeout - the time in seconds before a used connection can be considered abandoned
      See Also:
    • setTestOnBorrow

      public void setTestOnBorrow(boolean testOnBorrow)
      Description copied from interface: PoolConfiguration
      The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, a reconnection of the same pooled connection is attempted and validated again; if that also fails, the object is dropped from the pool and the borrow fails with an SQLException. NOTE - if no validationQuery is set, Connection.isValid(int) is used to validate the connection. Default value is false In order to have a more efficient validation, see PoolConfiguration.setValidationInterval(long)
      Specified by:
      setTestOnBorrow in interface PoolConfiguration
      Parameters:
      testOnBorrow - set to true if validation should take place before a connection is handed out to the application
      See Also:
    • setTestOnConnect

      public void setTestOnConnect(boolean testOnConnect)
      Description copied from interface: PoolConfiguration
      Set to true if we should run the validation query when connecting to the database for the first time on a connection. Normally this is always set to false, unless one wants to use the validationQuery as an init query. Setting an PoolConfiguration.setInitSQL(String) will override this setting, as the init SQL will be used instead of the validation query
      Specified by:
      setTestOnConnect in interface PoolConfiguration
      Parameters:
      testOnConnect - set to true if we should run the validation query upon connect
    • setTestOnReturn

      public void setTestOnReturn(boolean testOnReturn)
      Description copied from interface: PoolConfiguration
      The indication of whether objects will be validated after being returned to the pool. If the object fails to validate, it will be dropped from the pool. NOTE - if no validationQuery is set, Connection.isValid(int) is used to validate the connection. Default value is false In order to have a more efficient validation, see PoolConfiguration.setValidationInterval(long)
      Specified by:
      setTestOnReturn in interface PoolConfiguration
      Parameters:
      testOnReturn - true if validation should take place after a connection is returned to the pool
      See Also:
    • setTestWhileIdle

      public void setTestWhileIdle(boolean testWhileIdle)
      Description copied from interface: PoolConfiguration
      Set to true if query validation should take place while the connection is idle.
      Specified by:
      setTestWhileIdle in interface PoolConfiguration
      Parameters:
      testWhileIdle - true if validation should take place during idle checks
      See Also:
    • setTimeBetweenEvictionRunsMillis

      public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis)
      Description copied from interface: PoolConfiguration
      The number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing. This value should not be set under 1 second. It dictates how often we check for idle, abandoned connections, and how often we validate idle connection and resize the idle pool. The default value is 5000 (5 seconds)
      Specified by:
      setTimeBetweenEvictionRunsMillis in interface PoolConfiguration
      Parameters:
      timeBetweenEvictionRunsMillis - the sleep time in between validations in milliseconds
    • setUrl

      public void setUrl(String url)
      Description copied from interface: PoolConfiguration
      Sets the URL used to connect to the database
      Specified by:
      setUrl in interface PoolConfiguration
      Parameters:
      url - the configured URL for this connection pool
      See Also:
    • setUsername

      public void setUsername(String username)
      Sets the user name used to establish connections with. The value goes to the pool configuration, which - as PoolConfiguration.setUsername(String) promises - keeps the user entry of the database properties the driver is given in step with it, and takes that entry away as well for a null user name.

      Only connections established from now on, as setPassword(String) explains: a pooled connection reconnects with the credential it first connected with.

      Specified by:
      setUsername in interface PoolConfiguration
      Parameters:
      username - the user name, or null to take the credential away
      See Also:
    • setValidationInterval

      public void setValidationInterval(long validationInterval)
      Description copied from interface: PoolConfiguration
      avoid excess validation, only run validation at most at this frequency - time in milliseconds. If a connection is due for validation, but has been validated previously within this interval, it will not be validated again. The default value is 3000 (3 seconds).
      Specified by:
      setValidationInterval in interface PoolConfiguration
      Parameters:
      validationInterval - the validation interval in milliseconds
    • setValidationQuery

      public void setValidationQuery(String validationQuery)
      Description copied from interface: PoolConfiguration
      The SQL query that will be used to validate connections from this pool before returning them to the caller or pool. If specified, this query does not have to return any data, it just can't throw an SQLException. The default value is null. A blank query is stored as the unset value: a configuration surface that cannot express null is written empty to mean "no statement", and no statement can be blank. Example values are SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server)
      Specified by:
      setValidationQuery in interface PoolConfiguration
      Parameters:
      validationQuery - the query used for validation, or null or a blank string if no validation query is set
    • setValidatorClassName

      public void setValidatorClassName(String className)
      Description copied from interface: PoolConfiguration
      Set the name for an optional validator class which will be used in place of test queries. If set to null, standard validation will be used.
      Specified by:
      setValidatorClassName in interface PoolConfiguration
      Parameters:
      className - the name of the optional validator class
    • setValidationQueryTimeout

      public void setValidationQueryTimeout(int validationQueryTimeout)
      Description copied from interface: PoolConfiguration
      The timeout in seconds before a connection validation queries fail. A value less than or equal to zero will disable this feature. Defaults to -1.
      Specified by:
      setValidationQueryTimeout in interface PoolConfiguration
      Parameters:
      validationQueryTimeout - The timeout value
    • setJdbcInterceptors

      public void setJdbcInterceptors(String interceptors)
      Description copied from interface: PoolConfiguration
      A semicolon separated list of classnames extending JdbcInterceptor class. These interceptors will be inserted as an interceptor into the chain of operations on a java.sql.Connection object. Example interceptors are StatementFinalizer to close all used statements during the session. ResetAbandonedTimer resets the timer upon any activity on the connection, upon any statement execution and upon any read of a result set, whether the operation succeeded or failed. ConnectionState caches the auto commit, read only, transaction isolation and catalog settings to avoid round trips to the DB. The default value is null.
      Specified by:
      setJdbcInterceptors in interface PoolConfiguration
      Parameters:
      interceptors - the interceptors that are used for connections. Example format: 'ConnectionState(useEquals=true,fast=yes);ResetAbandonedTimer'
    • setJmxEnabled

      public void setJmxEnabled(boolean enabled)
      Sets whether JMX is enabled, before the pool is created. Whether the pool registers an MBean is decided when the pool is created, so a write after that point is rejected rather than stored without effect, matching the pool MBean's own setter. A closed data source is rejected as well: it can never create a pool again, so a write there would be stored without any possible effect.
      Specified by:
      setJmxEnabled in interface PoolConfiguration
      Parameters:
      enabled - whether JMX is enabled
      Throws:
      UnsupportedOperationException - if the pool has already been created or this data source has been closed
    • setFairQueue

      public void setFairQueue(boolean fairQueue)
      Description copied from interface: PoolConfiguration
      Set to true if you wish that calls to getConnection should be treated fairly in a true FIFO fashion. This uses the FairBlockingQueue implementation for the list of the idle connections. The default value is true. This flag is required when you want to use asynchronous connection retrieval.
      Specified by:
      setFairQueue in interface PoolConfiguration
      Parameters:
      fairQueue - true to use a fair queue
    • setUseLock

      public void setUseLock(boolean useLock)
      Description copied from interface: PoolConfiguration
      Set to true if a lock should be used when operations are performed on the connection object. Should be set to false unless you plan to have a background thread of your own doing idle and abandon checking such as JMX clients. If the pool sweeper is enabled, then the lock will automatically be used regardless of this setting.
      Specified by:
      setUseLock in interface PoolConfiguration
      Parameters:
      useLock - set to true if a lock should be used on connection operations
    • setDefaultCatalog

      public void setDefaultCatalog(String catalog)
      Description copied from interface: PoolConfiguration
      If non null, during connection creation the method Connection.setCatalog(String) will be called with the set value. When the ConnectionState interceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.
      Specified by:
      setDefaultCatalog in interface PoolConfiguration
      Parameters:
      catalog - null if not set and accepting the driver default.
    • setDefaultAutoCommit

      public void setDefaultAutoCommit(Boolean autocommit)
      Description copied from interface: PoolConfiguration
      The default auto-commit state of connections created by this pool. If not set (null), default is JDBC driver default (If set to null then the Connection.setAutoCommit(boolean) method will not be called.) When the ConnectionState interceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.
      Specified by:
      setDefaultAutoCommit in interface PoolConfiguration
      Parameters:
      autocommit - default auto commit setting, null is Driver default.
    • setDefaultTransactionIsolation

      public void setDefaultTransactionIsolation(int defaultTransactionIsolation)
      Description copied from interface: PoolConfiguration
      If set to DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION the method Connection.setTransactionIsolation(int) will not be called during connection creation. Otherwise the method will be called with the isolation level set by this property. When the ConnectionState interceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it (see PoolConfiguration.getDefaultTransactionIsolation() for the refused-level exception).
      Specified by:
      setDefaultTransactionIsolation in interface PoolConfiguration
      Parameters:
      defaultTransactionIsolation - a value of Connection.TRANSACTION_NONE, Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_READ_UNCOMMITTED, Connection.TRANSACTION_REPEATABLE_READ, Connection.TRANSACTION_SERIALIZABLE or DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION The last value will not be set on the connection.
    • setConnectionProperties

      public void setConnectionProperties(String properties)
      Description copied from interface: PoolConfiguration
      The properties that will be passed into Driver.connect(String, Properties) method. Username and password do not need to be stored here, they will be passed into the properties right before the connection is established.

      Re-setting the string re-applies it: the pairs the previous value of the string contributed are removed from the driver properties before the new ones are parsed in, so a reconfigure that drops a pair really stops sending it, while entries contributed from elsewhere - the explicitly passed user and password among them - are kept. A null value clears the string and takes its contributed pairs with it.

      Specified by:
      setConnectionProperties in interface PoolConfiguration
      Parameters:
      properties - properties - Format of the string is [propertyName=property;]* Example: prop1=value1;prop2=value2, may be null
    • setUseEquals

      public void setUseEquals(boolean useEquals)
      Description copied from interface: PoolConfiguration
      Set to true if you wish the ProxyConnection class to use String.equals instead of == when comparing method names. This property does not apply to added interceptors as those are configured individually. The default value is true.
      Specified by:
      setUseEquals in interface PoolConfiguration
      Parameters:
      useEquals - set to true if the pool should use String.equals(Object) instead of == when comparing method names on Connection methods
    • getParentLogger

      public Logger getParentLogger() throws SQLFeatureNotSupportedException
      Returns:
      no return value
      Throws:
      SQLFeatureNotSupportedException - Unsupported
    • getLogWriter

      public PrintWriter getLogWriter() throws SQLException
      Returns:
      null
      Throws:
      SQLException - No exception
    • setLogWriter

      public void setLogWriter(PrintWriter out) throws SQLException
      Parameters:
      out - Ignored
      Throws:
      SQLException - No exception
    • getLoginTimeout

      public int getLoginTimeout()
      The pool's borrow wait timeout, PoolConfiguration.getMaxWait(), expressed in whole seconds: DataSource.getLoginTimeout() is mapped onto that property rather than ignored. A sub-second maxWait therefore reads back as zero, and so does a negative one, which the pool reads as "wait indefinitely"; a negative login timeout is not a legal JDBC value.
      Returns:
      the timeout in whole seconds, never negative
    • setLoginTimeout

      public void setLoginTimeout(int i)
      Reconfigures the pool's borrow wait timeout: DataSource.setLoginTimeout(int) is mapped onto PoolConfiguration.setMaxWait(int) as 1000 * i milliseconds, with the seconds-to-milliseconds conversion of an int seconds value. A seconds value too large to be represented in milliseconds is clamped to the largest representable timeout rather than wrapped. A negative value is rejected, since the pool reads a non-positive wait as "wait indefinitely".
      Parameters:
      i - The timeout in seconds
      Throws:
      IllegalArgumentException - if the timeout is negative
    • getSuspectTimeout

      public int getSuspectTimeout()
      Description copied from interface: PoolConfiguration
      Returns the time in seconds to pass before a connection is marked an abandoned suspect. Any value lesser than or equal to 0 means the check is disabled.
      Specified by:
      getSuspectTimeout in interface PoolConfiguration
      Returns:
      Returns the time in seconds to pass before a connection is marked an abandoned suspect.
    • setSuspectTimeout

      public void setSuspectTimeout(int seconds)
      Description copied from interface: PoolConfiguration
      Similar to PoolConfiguration.setRemoveAbandonedTimeout(int) but instead of treating the connection as abandoned, and potentially closing the connection, this simply logs the warning if PoolConfiguration.isLogAbandoned() returns true. If this value is equal or less than 0, no suspect checking will be performed. Suspect checking only takes place if the timeout value is larger than 0 and the connection was not abandoned or if abandon check is disabled. If a connection is suspect a WARN message gets logged and a JMX notification gets sent once.
      Specified by:
      setSuspectTimeout in interface PoolConfiguration
      Parameters:
      seconds - - the amount of time in seconds that has to pass before a connection is marked suspect.
    • getIdle

      public int getIdle()
      If the pool has not been created, it will be created during this call.
      Returns:
      the number of established but idle connections
    • getNumIdle

      public int getNumIdle()
      Returns:
      the number of established but idle connections
    • checkAbandoned

      public void checkAbandoned()
      Forces an abandon check on the connection pool. If connections that have been abandoned exists, they will be closed during this run
    • checkIdle

      public void checkIdle()
      Forces a check for resizing of the idle connections
    • getActive

      public int getActive()
      Returns the number of connections currently in use by the application.
      Returns:
      number of connections in use by the application
    • getNumActive

      public int getNumActive()
      Returns the number of connections currently in use by the application.
      Returns:
      number of active connections
    • getWaitCount

      public int getWaitCount()
      Returns the number of threads currently waiting for a connection from the pool.
      Returns:
      number of waiting threads
    • getSize

      public int getSize()
      Returns the current total number of connections in the pool. If the pool has not been created, it will be created during this call, and a data source that has been closed throws RuntimeException. See getPoolSize() for the reading that never creates the pool and answers 0 while none exists.
      Returns:
      current pool size
    • testIdle

      public void testIdle()
      Performs a validation on idle connections.

      Note: this operation is safe with concurrent traffic and with a closing pool even when the per-connection lock is disabled (sweeper switched off and PoolProperties.getUseLock() returning false), as described on ConnectionPool.testAllIdle().

    • getBorrowedCount

      public long getBorrowedCount()
      The total number of connections borrowed from this pool.
      Returns:
      the borrowed connection count
    • getReturnedCount

      public long getReturnedCount()
      The total number of connections returned to this pool.
      Returns:
      the returned connection count
    • getCreatedCount

      public long getCreatedCount()
      The total number of connections created by this pool.
      Returns:
      the created connection count
    • getReleasedCount

      public long getReleasedCount()
      The total number of connections released from this pool.
      Returns:
      the released connection count
    • getReconnectedCount

      public long getReconnectedCount()
      The total number of connections reconnected by this pool.
      Returns:
      the reconnected connection count
    • getRemoveAbandonedCount

      public long getRemoveAbandonedCount()
      The total number of connections released by remove abandoned.
      Returns:
      the PoolCleaner removed abandoned connection count
    • getReleasedIdleCount

      public long getReleasedIdleCount()
      The total number of connections released by eviction.
      Returns:
      the PoolCleaner evicted idle connection count
    • resetStats

      public void resetStats()
      reset the statistics of this pool.
    • getConnectionProperties

      public String getConnectionProperties()
      Returns the connection properties with any credential they carry masked out, so the data source's own bean/JMX surface does not expose a password in cleartext. The write is not masked: setConnectionProperties(String) takes the string as it is meant to reach the driver. Use getPoolProperties() for the raw value. The connection properties that will be sent to the JDBC driver when establishing new connections. Format of the string is [propertyName=property;]
      NOTE - The "user" and "password" properties will be passed explicitly, so they do not need to be included here. The default value is null.
      Specified by:
      getConnectionProperties in interface PoolConfiguration
      Returns:
      the connection properties
    • getDbProperties

      public Properties getDbProperties()
      Returns a copy of the database properties with the credential entries removed. A credential entry is one whose key is password, pass or pwd, ignoring case and surrounding whitespace. This object doubles as its own JMX/bean surface and setPassword(String) puts the password into the database properties, so returning them as they are would expose the plaintext password through a getter while getPassword() is explicitly masked - the same protection the pool's own MBean (ConnectionPool.getDbProperties()) already applies. A configuration whose database properties are null - a state setPassword(String) and setUsername(String) document as supported - has nothing to mask, so this returns null. Returns the database properties that are passed into the Driver.connect(String, Properties) method.
      Specified by:
      getDbProperties in interface PoolConfiguration
      Returns:
      database properties that are passed into the Driver.connect(String, Properties) method, or null when the configuration has none
    • getDefaultCatalog

      public String getDefaultCatalog()
      Description copied from interface: PoolConfiguration
      If non null, during connection creation the method Connection.setCatalog(String) will be called with the set value. When the ConnectionState interceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.
      Specified by:
      getDefaultCatalog in interface PoolConfiguration
      Returns:
      the default catalog, null if not set and accepting the driver default.
    • getDefaultTransactionIsolation

      public int getDefaultTransactionIsolation()
      Description copied from interface: PoolConfiguration
      Returns the default transaction isolation level. If set to DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION the method Connection.setTransactionIsolation(int) will not be called during connection creation. When the ConnectionState interceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it; a level the driver refuses on a session is the one documented exception to that enforcement - the session stays in service and that level is not retried on it.
      Specified by:
      getDefaultTransactionIsolation in interface PoolConfiguration
      Returns:
      driver transaction isolation level, or -1 DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION if not set.
    • getDriverClassName

      public String getDriverClassName()
      Description copied from interface: PoolConfiguration
      The fully qualified Java class name of the JDBC driver to be used. The driver has to be accessible from the same classloader as tomcat-jdbc.jar
      Specified by:
      getDriverClassName in interface PoolConfiguration
      Returns:
      fully qualified JDBC driver name.
    • getInitialSize

      public int getInitialSize()
      Description copied from interface: PoolConfiguration
      Returns the number of connections that will be established when the connection pool is started. Default value is 10
      Specified by:
      getInitialSize in interface PoolConfiguration
      Returns:
      number of connections to be started when pool is started
    • getInitSQL

      public String getInitSQL()
      Description copied from interface: PoolConfiguration
      A custom query to be run when a connection is first created. The default value is null. This query only runs once per connection, and that is when a new connection is established to the database. If this value is non null, it will replace the validation query during connection creation.

      The query runs while the pool is initializing the freshly established session, and the pool terminates the transaction it executes into by commit, so its effects - a data change or a session setting - persist for the lifetime of the connection even when the pool runs with auto commit off. A validation query follows the opposite rule and terminates an open transaction by rollback, so a health check never commits application work. A pool configured with a custom Validator does not run this query at all: the validator replaces the validation itself.

      Specified by:
      getInitSQL in interface PoolConfiguration
      Returns:
      the init SQL used to run against the DB or null if not set
    • getJdbcInterceptors

      public String getJdbcInterceptors()
      Returns the interceptor configuration with any credential its definitions carry masked out, so the data source's own bean/JMX surface does not expose a password in cleartext. Use getPoolProperties() for the raw value. A semicolon separated list of classnames extending JdbcInterceptor class. These interceptors will be inserted as an interceptor into the chain of operations on a java.sql.Connection object. Example interceptors are StatementFinalizer to close all used statements during the session. ResetAbandonedTimer resets the timer upon any activity on the connection, upon any statement execution and upon any read of a result set, whether the operation succeeded or failed. ConnectionState caches the auto commit, read only, transaction isolation and catalog settings to avoid round trips to the DB. The default value is null.
      Specified by:
      getJdbcInterceptors in interface PoolConfiguration
      Returns:
      the interceptors that are used for connections. Example format: 'ConnectionState(useEquals=true,fast=yes);ResetAbandonedTimer'
    • getMaxActive

      public int getMaxActive()
      Description copied from interface: PoolConfiguration
      The maximum number of active connections that can be allocated from this pool at the same time. The default value is 100
      Specified by:
      getMaxActive in interface PoolConfiguration
      Returns:
      the maximum number of connections used by this pool
    • getMaxIdle

      public int getMaxIdle()
      Description copied from interface: PoolConfiguration
      The maximum number of connections that should be kept in the idle pool if PoolConfiguration.isPoolSweeperEnabled() returns false. If PoolConfiguration.isPoolSweeperEnabled() returns true, then the idle pool can grow up to PoolConfiguration.getMaxActive() and will be shrunk according to PoolConfiguration.getMinEvictableIdleTimeMillis() setting. Default value is PoolConfiguration.getMaxActive() (100 with the default configuration)
      Specified by:
      getMaxIdle in interface PoolConfiguration
      Returns:
      the maximum number of idle connections.
    • getMaxWait

      public int getMaxWait()
      Description copied from interface: PoolConfiguration
      The maximum number of milliseconds that the pool will wait (when there are no available connections and the PoolConfiguration.getMaxActive() has been reached) for a connection to be returned before throwing an exception. A value less than or equal to zero makes the pool wait indefinitely for a connection to be returned instead of timing out. Default value is 30000 (30 seconds)
      Specified by:
      getMaxWait in interface PoolConfiguration
      Returns:
      the number of milliseconds to wait for a connection to become available if the pool is maxed out.
    • getMinEvictableIdleTimeMillis

      public int getMinEvictableIdleTimeMillis()
      Description copied from interface: PoolConfiguration
      The minimum amount of time an object must sit idle in the pool before it is eligible for eviction. The default value is 60000 (60 seconds).
      Specified by:
      getMinEvictableIdleTimeMillis in interface PoolConfiguration
      Returns:
      the minimum amount of idle time in milliseconds before a connection is considered idle and eligible for eviction.
    • getMinIdle

      public int getMinIdle()
      Description copied from interface: PoolConfiguration
      The minimum number of established connections that should be kept in the pool at all times. The connection pool can shrink below this number if validation queries fail and connections get closed. The default is the value PoolConfiguration.getInitialSize() had when this configuration was constructed; changing initialSize later does not move it, so set this explicitly to change the floor (also see PoolConfiguration.setTestWhileIdle(boolean)). The eviction run normally keeps the total number of connections in the pool - idle plus busy - at or above this value, hence the number of actual connections can be between PoolConfiguration.getMinIdle() and somewhere between PoolConfiguration.getMaxIdle() and PoolConfiguration.getMaxActive(). A connection left over from an earlier pool generation is released regardless, so an explicit idle check after a purge can take the pool below the floor.
      Specified by:
      getMinIdle in interface PoolConfiguration
      Returns:
      the minimum number of idle or established connections
    • getMaxAge

      public long getMaxAge()
      Description copied from interface: PoolConfiguration
      Time in milliseconds to keep this connection before reconnecting. When a connection is idle, returned to the pool or borrowed from the pool, the pool will check to see if the ((now - time-when-connected) > maxAge) has been reached, and if so, it reconnects. Note that the age of idle connections will only be checked if PoolConfiguration.getTimeBetweenEvictionRunsMillis() returns a value greater than 0. The default value is 0, which implies that connections will be left open and no age checks will be done. This is a useful setting for database sessions that leak memory as it ensures that the session will have a finite life span.
      Specified by:
      getMaxAge in interface PoolConfiguration
      Returns:
      the time in milliseconds a connection will be open for when used
    • getName

      public String getName()
      Description copied from interface: PoolConfiguration
      Returns the name of the connection pool. Tomcat gives every pool it manages a name of its own. By default a name unique within this class loader is assigned; it is a counter, so it is unique but predictable, not random. Two class loaders that each load this module can therefore produce the same default name, which the pool's statistics and JMX registration treat as the same name: give pools that must coexist a name of their own. A duplicate name among live pools is reported as an error by the query reporting interceptors.
      Specified by:
      getName in interface PoolConfiguration
      Returns:
      the name of the pool, unique within this class loader by default
    • getNumTestsPerEvictionRun

      public int getNumTestsPerEvictionRun()
      Description copied from interface: PoolConfiguration
      Property not used
      Specified by:
      getNumTestsPerEvictionRun in interface PoolConfiguration
      Returns:
      the stored value, which the pool never reads
    • getPassword

      public String getPassword()
      Description copied from interface: PoolConfiguration
      Returns the password used when establishing connections to the database. Some implementations mask the value - the DataSourceProxy and the JMX bean return a placeholder instead of the password so that it cannot be read out through JMX - so a consumer of this contract must not treat the returned string as the configured password.
      Specified by:
      getPassword in interface PoolConfiguration
      Returns:
      DOES NOT RETURN THE PASSWORD, IT WOULD SHOW UP IN JMX
    • getRemoveAbandonedTimeout

      public int getRemoveAbandonedTimeout()
      Description copied from interface: PoolConfiguration
      The time in seconds before a connection can be considered abandoned. The timer can be reset upon queries using an interceptor.
      Specified by:
      getRemoveAbandonedTimeout in interface PoolConfiguration
      Returns:
      the time in seconds before a used connection can be considered abandoned
      See Also:
    • getTimeBetweenEvictionRunsMillis

      public int getTimeBetweenEvictionRunsMillis()
      Description copied from interface: PoolConfiguration
      The number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing. This value should not be set under 1 second. It dictates how often we check for idle, abandoned connections, and how often we validate idle connection and resize the idle pool. The default value is 5000 (5 seconds)
      Specified by:
      getTimeBetweenEvictionRunsMillis in interface PoolConfiguration
      Returns:
      the sleep time in between validations in milliseconds
    • getUrl

      public String getUrl()
      Returns the JDBC URL with any credential it carries masked out, so the data source's own bean/JMX surface does not expose a password in cleartext. The write is not masked: setUrl(String) takes the URL as it is meant to reach the driver. Use getPoolProperties() for the raw value. The URL used to connect to the database
      Specified by:
      getUrl in interface PoolConfiguration
      Returns:
      the configured URL for this connection pool
      See Also:
    • getUsername

      public String getUsername()
      Description copied from interface: PoolConfiguration
      Returns the username used to establish the connection with
      Specified by:
      getUsername in interface PoolConfiguration
      Returns:
      the username used to establish the connection with
    • getValidationInterval

      public long getValidationInterval()
      Description copied from interface: PoolConfiguration
      avoid excess validation, only run validation at most at this frequency - time in milliseconds. If a connection is due for validation, but has been validated previously within this interval, it will not be validated again. The default value is 3000 (3 seconds).
      Specified by:
      getValidationInterval in interface PoolConfiguration
      Returns:
      the validation interval in milliseconds
    • getValidationQuery

      public String getValidationQuery()
      Description copied from interface: PoolConfiguration
      The SQL query that will be used to validate connections from this pool before returning them to the caller or pool. If specified, this query does not have to return any data, it just can't throw an SQLException. The default value is null. A blank query means the unset value: no statement, the built-in Connection.isValid(int) check runs instead. Example values are SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server)
      Specified by:
      getValidationQuery in interface PoolConfiguration
      Returns:
      the query used for validation or null if no validation is performed
    • getValidationQueryTimeout

      public int getValidationQueryTimeout()
      Description copied from interface: PoolConfiguration
      The timeout in seconds before a connection validation queries fail. A value less than or equal to zero will disable this feature. Defaults to -1.
      Specified by:
      getValidationQueryTimeout in interface PoolConfiguration
      Returns:
      the timeout value in seconds
    • getValidatorClassName

      public String getValidatorClassName()
      Description copied from interface: PoolConfiguration
      Return the name of the optional validator class - may be null.
      Specified by:
      getValidatorClassName in interface PoolConfiguration
      Returns:
      the name of the optional validator class - may be null
    • getValidator

      public Validator getValidator()
      Description copied from interface: PoolConfiguration
      Returns the validator object used for connection validation. May be null if the pool is using a standard validation query instead.
      Specified by:
      getValidator in interface PoolConfiguration
      Returns:
      the optional validator object - may be null
    • setValidator

      public void setValidator(Validator validator)
      Description copied from interface: PoolConfiguration
      Sets the validator object If this is a non null object, it will be used as a validator instead of the validationQuery If this is null, remove the usage of the validator.
      Specified by:
      setValidator in interface PoolConfiguration
      Parameters:
      validator - The validator object
    • isAccessToUnderlyingConnectionAllowed

      public boolean isAccessToUnderlyingConnectionAllowed()
      Description copied from interface: PoolConfiguration
      Property not used. Access is always allowed. Access can be achieved by calling unwrap on the pooled connection. see DataSource interface or call getConnection through reflection or cast the object as PooledConnection
      Specified by:
      isAccessToUnderlyingConnectionAllowed in interface PoolConfiguration
      Returns:
      true
    • isDefaultAutoCommit

      public Boolean isDefaultAutoCommit()
      Description copied from interface: PoolConfiguration
      The default auto-commit state of connections created by this pool. If not set (null), default is JDBC driver default (If set to null then the Connection.setAutoCommit(boolean) method will not be called.) When the ConnectionState interceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.
      Specified by:
      isDefaultAutoCommit in interface PoolConfiguration
      Returns:
      the default auto commit setting, null is Driver default.
    • isDefaultReadOnly

      public Boolean isDefaultReadOnly()
      Description copied from interface: PoolConfiguration
      If non null, during connection creation the method Connection.setReadOnly(boolean) will be called with the set value. When the ConnectionState interceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.
      Specified by:
      isDefaultReadOnly in interface PoolConfiguration
      Returns:
      null if not set and accepting the driver default otherwise the read only value
    • isLogAbandoned

      public boolean isLogAbandoned()
      Description copied from interface: PoolConfiguration
      boolean flag to set if stack traces should be logged for application code which abandoned a Connection. Logging of abandoned Connections adds overhead for every Connection borrow because a stack trace has to be generated. The default value is false.
      Specified by:
      isLogAbandoned in interface PoolConfiguration
      Returns:
      true if the connection pool logs stack traces when connections are borrowed from the pool.
    • isPoolSweeperEnabled

      public boolean isPoolSweeperEnabled()
      Description copied from interface: PoolConfiguration
      Returns true if the pool sweeper is enabled for the connection pool. The pool sweeper is enabled if any settings that require async intervention in the pool are turned on. Implementations are expected to run the background maintenance whenever boolean timer = getTimeBetweenEvictionRunsMillis()>0; boolean result = timer && (isRemoveAbandoned() && getRemoveAbandonedTimeout()>0); result = result || (timer && getSuspectTimeout()>0); result = result || (timer && isTestWhileIdle()); result = result || (timer && getMinEvictableIdleTimeMillis()>0); result = result || (timer && getMaxAge()>0); return result; so enabling the maintenance when any one of these triggers is turned on satisfies the contract. With the defaults shipped by PoolProperties the sweeper is enabled. When it runs, the background cleaner thread checks for abandoned connections when PoolConfiguration.isRemoveAbandoned() is set, marks and reports connections that exceeded PoolConfiguration.getSuspectTimeout(), evicts idle connections towards PoolConfiguration.getMinIdle(), validates idle connections when PoolConfiguration.isTestWhileIdle() is set and reconnects idle connections that exceeded PoolConfiguration.getMaxAge(). While the sweeper is enabled, the pool also takes the per-connection lock when borrowing and returning connections (the same lock PoolConfiguration.getUseLock() forces on) and returned connections are kept beyond PoolConfiguration.getMaxIdle(), letting the idle pool grow towards PoolConfiguration.getMaxActive() as the cleaner trims it.
      Specified by:
      isPoolSweeperEnabled in interface PoolConfiguration
      Returns:
      true if a background thread is or will be enabled for this pool
    • isRemoveAbandoned

      public boolean isRemoveAbandoned()
      Description copied from interface: PoolConfiguration
      boolean flag to remove abandoned connections if they exceed the removeAbandonedTimeout. If set to true a connection is considered abandoned and eligible for removal if it has been in use longer than the PoolConfiguration.getRemoveAbandonedTimeout() and the condition for PoolConfiguration.getAbandonWhenPercentageFull() is met. Setting this to true can recover db connections from applications that fail to close a connection. See also PoolConfiguration.isLogAbandoned() The default value is false.
      Specified by:
      isRemoveAbandoned in interface PoolConfiguration
      Returns:
      true if abandoned connections can be closed and expelled out of the pool
    • getAbandonWhenPercentageFull

      public int getAbandonWhenPercentageFull()
      Description copied from interface: PoolConfiguration
      Connections that have been abandoned (timed out) won't get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull. The value should be between 0-100. The default value is 0, which implies that connections are eligible for closure as soon as removeAbandonedTimeout has been reached.
      Specified by:
      getAbandonWhenPercentageFull in interface PoolConfiguration
      Returns:
      percentage - a value between 0 and 100 to indicate when connections that have been abandoned/timed out are considered abandoned
    • isTestOnBorrow

      public boolean isTestOnBorrow()
      Description copied from interface: PoolConfiguration
      The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, a reconnection of the same pooled connection is attempted and validated again; if that also fails, the object is dropped from the pool and the borrow fails with an SQLException. NOTE - if no validationQuery is set, Connection.isValid(int) is used to validate the connection. Default value is false In order to have a more efficient validation, see PoolConfiguration.setValidationInterval(long)
      Specified by:
      isTestOnBorrow in interface PoolConfiguration
      Returns:
      true if the connection is to be validated upon borrowing a connection from the pool
      See Also:
    • isTestOnConnect

      public boolean isTestOnConnect()
      Description copied from interface: PoolConfiguration
      Returns true if we should run the validation query when connecting to the database for the first time on a connection. Normally this is always set to false, unless one wants to use the validationQuery as an init query.
      Specified by:
      isTestOnConnect in interface PoolConfiguration
      Returns:
      true if we should run the validation query upon connect
    • isTestOnReturn

      public boolean isTestOnReturn()
      Description copied from interface: PoolConfiguration
      The indication of whether objects will be validated after being returned to the pool. If the object fails to validate, it will be dropped from the pool. NOTE - if no validationQuery is set, Connection.isValid(int) is used to validate the connection. Default value is false In order to have a more efficient validation, see PoolConfiguration.setValidationInterval(long)
      Specified by:
      isTestOnReturn in interface PoolConfiguration
      Returns:
      true if validation should take place after a connection is returned to the pool
      See Also:
    • isTestWhileIdle

      public boolean isTestWhileIdle()
      Description copied from interface: PoolConfiguration
      Set to true if query validation should take place while the connection is idle.
      Specified by:
      isTestWhileIdle in interface PoolConfiguration
      Returns:
      true if validation should take place during idle checks
      See Also:
    • getDefaultAutoCommit

      public Boolean getDefaultAutoCommit()
      Description copied from interface: PoolConfiguration
      The default auto-commit state of connections created by this pool. If not set (null), default is JDBC driver default (If set to null then the Connection.setAutoCommit(boolean) method will not be called.) When the ConnectionState interceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.
      Specified by:
      getDefaultAutoCommit in interface PoolConfiguration
      Returns:
      the default auto commit setting, null is Driver default.
    • getDefaultReadOnly

      public Boolean getDefaultReadOnly()
      Description copied from interface: PoolConfiguration
      If non null, during connection creation the method Connection.setReadOnly(boolean) will be called with the set value. When the ConnectionState interceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.
      Specified by:
      getDefaultReadOnly in interface PoolConfiguration
      Returns:
      null if not set and accepting the driver default otherwise the read only value
    • getJdbcInterceptorsAsArray

      public PoolProperties.InterceptorDefinition[] getJdbcInterceptorsAsArray()
      Returns the parsed interceptor definitions with their credential values masked, the display counterpart of getJdbcInterceptors(). This object doubles as its own JMX/bean surface, so the raw definitions - which carry the pairs the pool builds its interceptor chains from - stay reachable only through getPoolProperties(). The copy is also defensive: it shares no definition, property or array slot with the live configuration, so a caller cannot mutate the chain a later connection will build. Returns the PoolConfiguration.getJdbcInterceptors() as an array of objects with properties and the classes.
      Specified by:
      getJdbcInterceptorsAsArray in interface PoolConfiguration
      Returns:
      an array of interceptors that have been configured
    • getUseLock

      public boolean getUseLock()
      Description copied from interface: PoolConfiguration
      Return true if a lock should be used when operations are performed on the connection object. Should be set to false unless you plan to have a background thread of your own doing idle and abandon checking such as JMX clients. If the pool sweeper is enabled, then the lock will automatically be used regardless of this setting.
      Specified by:
      getUseLock in interface PoolConfiguration
      Returns:
      true if a lock is used.
    • isFairQueue

      public boolean isFairQueue()
      Description copied from interface: PoolConfiguration
      Returns true if a fair queue is being used by the connection pool
      Specified by:
      isFairQueue in interface PoolConfiguration
      Returns:
      true if a fair waiting queue is being used
    • isJmxEnabled

      public boolean isJmxEnabled()
      Description copied from interface: PoolConfiguration
      If set to true, the connection pool creates a ConnectionPoolMBean object that can be registered with JMX to receive notifications and state about the pool. The ConnectionPool object doesn't register itself, as there is no way to keep a static non changing ObjectName across JVM restarts.
      Specified by:
      isJmxEnabled in interface PoolConfiguration
      Returns:
      true if the mbean object will be created upon startup.
    • isUseEquals

      public boolean isUseEquals()
      Description copied from interface: PoolConfiguration
      Set to true if you wish the ProxyConnection class to use String.equals instead of == when comparing method names. This property does not apply to added interceptors as those are configured individually. The default value is true.
      Specified by:
      isUseEquals in interface PoolConfiguration
      Returns:
      true if pool uses String.equals(Object) instead of == when comparing method names on Connection methods
    • setAbandonWhenPercentageFull

      public void setAbandonWhenPercentageFull(int percentage)
      Description copied from interface: PoolConfiguration
      Connections that have been abandoned (timed out) won't get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull. The value should be between 0-100. The default value is 0, which implies that connections are eligible for closure as soon as removeAbandonedTimeout has been reached.
      Specified by:
      setAbandonWhenPercentageFull in interface PoolConfiguration
      Parameters:
      percentage - a value between 0 and 100 to indicate when connections that have been abandoned/timed out are considered abandoned
    • setAccessToUnderlyingConnectionAllowed

      public void setAccessToUnderlyingConnectionAllowed(boolean accessToUnderlyingConnectionAllowed)
      Description copied from interface: PoolConfiguration
      No-op
      Specified by:
      setAccessToUnderlyingConnectionAllowed in interface PoolConfiguration
      Parameters:
      accessToUnderlyingConnectionAllowed - parameter ignored
    • setDbProperties

      public void setDbProperties(Properties dbProperties)
      Replaces the live database properties with the given set. The write is not masked, and it replaces the whole collection: a read-modify-write of the masked getDbProperties() view hands back a set with the password removed and takes that credential away from the live configuration. Use setPassword(String) and setUsername(String) to change the credentials, as getDbProperties() describes.
      Specified by:
      setDbProperties in interface PoolConfiguration
      Parameters:
      dbProperties - the replacement database properties
    • setDefaultReadOnly

      public void setDefaultReadOnly(Boolean defaultReadOnly)
      Description copied from interface: PoolConfiguration
      If non null, during connection creation the method Connection.setReadOnly(boolean) will be called with the set value. When the ConnectionState interceptor is configured, it applies this setting on every borrow rather than at connection creation, and re-applies it whenever a borrower has changed it.
      Specified by:
      setDefaultReadOnly in interface PoolConfiguration
      Parameters:
      defaultReadOnly - null if not set and accepting the driver default.
    • setMaxAge

      public void setMaxAge(long maxAge)
      Description copied from interface: PoolConfiguration
      Time in milliseconds to keep this connection before reconnecting. When a connection is idle, returned to the pool or borrowed from the pool, the pool will check to see if the ((now - time-when-connected) > maxAge) has been reached, and if so, it reconnects. Note that the age of idle connections will only be checked if PoolConfiguration.getTimeBetweenEvictionRunsMillis() returns a value greater than 0. The default value is 0, which implies that connections will be left open and no age checks will be done. This is a useful setting for database sessions that leak memory as it ensures that the session will have a finite life span.
      Specified by:
      setMaxAge in interface PoolConfiguration
      Parameters:
      maxAge - the time in milliseconds a connection will be open for when used
    • setName

      public void setName(String name)
      Description copied from interface: PoolConfiguration
      Sets the name of the connection pool
      Specified by:
      setName in interface PoolConfiguration
      Parameters:
      name - the name of the pool, unique among the live pools that share its statistics and JMX space
    • setDataSource

      public void setDataSource(Object ds)
      Description copied from interface: PoolConfiguration
      Injects a datasource that will be used to retrieve/create connections. If a data source is set, the PoolConfiguration.getUrl() and PoolConfiguration.getDriverClassName() methods are ignored and not used by the pool. If the PoolConfiguration.getUsername() and PoolConfiguration.getPassword() values are set, the method DataSource.getConnection(String, String) method will be called instead of the DataSource.getConnection() method. If the data source implements XADataSource the methods XADataSource.getXAConnection() and XADataSource.getXAConnection(String,String) will be invoked. If it implements ConnectionPoolDataSource the methods ConnectionPoolDataSource.getPooledConnection() and ConnectionPoolDataSource.getPooledConnection(String,String) will be invoked instead.
      Specified by:
      setDataSource in interface PoolConfiguration
      Parameters:
      ds - the DataSource to be used for creating connections to be pooled.
    • getDataSource

      public Object getDataSource()
      Description copied from interface: PoolConfiguration
      Returns a datasource, if one exists that is being used to create connections. This method will return null if the pool is using a Driver
      Specified by:
      getDataSource in interface PoolConfiguration
      Returns:
      the backing object - a DataSource, XADataSource or ConnectionPoolDataSource - used for creating connections to be pooled, or null if a Driver is used.
    • setDataSourceJNDI

      public void setDataSourceJNDI(String jndiDS)
      Description copied from interface: PoolConfiguration
      Configures a JNDI name for the backing data source. Instead of injecting the object through PoolConfiguration.setDataSource(Object), this names it. The name is resolved by DataSourceFactory, which looks it up when the pool is created through the factory and JNDI path and injects the found object through PoolConfiguration.setDataSource(Object); after that lookup, PoolConfiguration.getDataSource() does not return null. Nothing else performs the lookup: set on a pool configured programmatically, the property never becomes a data source and the pool keeps connecting through the driver properties.
      Specified by:
      setDataSourceJNDI in interface PoolConfiguration
      Parameters:
      jndiDS - the JNDI name of the data source to wrap
    • getDataSourceJNDI

      public String getDataSourceJNDI()
      Description copied from interface: PoolConfiguration
      Returns the JNDI string configured for data source usage.
      Specified by:
      getDataSourceJNDI in interface PoolConfiguration
      Returns:
      the JNDI string or null if not set
    • isAlternateUsernameAllowed

      public boolean isAlternateUsernameAllowed()
      Description copied from interface: PoolConfiguration
      Returns true if the call getConnection(username,password) is allowed. This is used for when the pool is used by an application accessing multiple schemas. There is a performance impact turning this option on.
      Specified by:
      isAlternateUsernameAllowed in interface PoolConfiguration
      Returns:
      true if getConnection(username,password) is honored, false if it is ignored.
    • setAlternateUsernameAllowed

      public void setAlternateUsernameAllowed(boolean alternateUsernameAllowed)
      Description copied from interface: PoolConfiguration
      Set to true if the call getConnection(username,password) is allowed and honored. This is used for when the pool is used by an application accessing multiple schemas. There is a performance impact turning this option on, even when not used due to username checks.
      Specified by:
      setAlternateUsernameAllowed in interface PoolConfiguration
      Parameters:
      alternateUsernameAllowed - - set true if getConnection(username,password) is honored, false if it is to be ignored.
    • setCommitOnReturn

      public void setCommitOnReturn(boolean commitOnReturn)
      Description copied from interface: PoolConfiguration
      Set to true if you want the connection pool to commit any pending transaction when a connection is returned. The default value is false, as this could result in committing data. This parameter is ignored if PoolConfiguration.setRollbackOnReturn(boolean) is also set to true. The commit is only performed when the returned connection is actually in a transaction.
      Specified by:
      setCommitOnReturn in interface PoolConfiguration
      Parameters:
      commitOnReturn - set to true if the pool should call Connection.commit() when a connection is returned to the pool. Default is false
    • getCommitOnReturn

      public boolean getCommitOnReturn()
      Description copied from interface: PoolConfiguration
      Returns whether the pool commits any pending transaction when a connection is returned. See PoolConfiguration.setCommitOnReturn(boolean) for details.
      Specified by:
      getCommitOnReturn in interface PoolConfiguration
      Returns:
      true if the pool should commit when a connection is returned to it
    • setRollbackOnReturn

      public void setRollbackOnReturn(boolean rollbackOnReturn)
      Description copied from interface: PoolConfiguration
      Set to true if you want the connection pool to rollback any pending transaction when a connection is returned. The default value is false, as this could result in discarding data the application has not committed. The rollback is only performed when the returned connection is actually in a transaction.
      Specified by:
      setRollbackOnReturn in interface PoolConfiguration
      Parameters:
      rollbackOnReturn - set to true if the pool should call Connection.rollback() when a connection is returned to the pool. Default is false
    • getRollbackOnReturn

      public boolean getRollbackOnReturn()
      Description copied from interface: PoolConfiguration
      Returns whether the pool rolls back any pending transaction when a connection is returned. See PoolConfiguration.setRollbackOnReturn(boolean) for details.
      Specified by:
      getRollbackOnReturn in interface PoolConfiguration
      Returns:
      true if the pool should rollback when a connection is returned to it
    • setUseDisposableConnectionFacade

      @Deprecated public void setUseDisposableConnectionFacade(boolean useDisposableConnectionFacade)
      Deprecated.
      The disposable connection facade is always used, so this property no longer has any effect.
      Stores the value of the deprecated useDisposableConnectionFacade property. The pool always wraps the connection handle in a facade that disallows use of the connection after Connection.close() has been called, whatever value is stored here.
      Specified by:
      setUseDisposableConnectionFacade in interface PoolConfiguration
      Parameters:
      useDisposableConnectionFacade - the configured value, retained but without effect
    • getUseDisposableConnectionFacade

      @Deprecated public boolean getUseDisposableConnectionFacade()
      Deprecated.
      The disposable connection facade is always used, so this property no longer has any effect.
      Returns the value stored for the deprecated useDisposableConnectionFacade property. The pool always wraps the connection handle in a facade that disallows use of the connection after Connection.close() has been called, whatever value is returned here.
      Specified by:
      getUseDisposableConnectionFacade in interface PoolConfiguration
      Returns:
      the configured value, retained but without effect
    • setLogValidationErrors

      public void setLogValidationErrors(boolean logValidationErrors)
      Description copied from interface: PoolConfiguration
      Set to true if you wish that errors from validation should be logged as error messages.
      Specified by:
      setLogValidationErrors in interface PoolConfiguration
      Parameters:
      logValidationErrors - set to true to log validation errors
    • getLogValidationErrors

      public boolean getLogValidationErrors()
      Description copied from interface: PoolConfiguration
      Returns true if errors that happen during validation will be logged
      Specified by:
      getLogValidationErrors in interface PoolConfiguration
      Returns:
      true if errors that happen during validation will be logged
    • getPropagateInterruptState

      public boolean getPropagateInterruptState()
      Description copied from interface: PoolConfiguration
      Returns true if the pool is configured to propagate interrupt state of a thread. A thread waiting for a connection, can have its wait interrupted, and by default will clear the interrupt flag and throw a SQLException reporting the interrupted wait, with the InterruptedException as its cause.
      Specified by:
      getPropagateInterruptState in interface PoolConfiguration
      Returns:
      true if the pool is configured to propagate and not clear the thread interrupt state
    • setPropagateInterruptState

      public void setPropagateInterruptState(boolean propagateInterruptState)
      Description copied from interface: PoolConfiguration
      Configure the pool to propagate interrupt state for interrupted threads waiting for a connection A thread waiting for a connection, can have its wait interrupted, and by default will clear the interrupt flag and throw a SQLException reporting the interrupted wait, with the InterruptedException as its cause. If set to true, this behavior will change, while the SQLException is still thrown, the threads interrupted state is still set.
      Specified by:
      setPropagateInterruptState in interface PoolConfiguration
      Parameters:
      propagateInterruptState - - set to true to not clear, but propagate, a threads interrupted state.
    • isIgnoreExceptionOnPreLoad

      public boolean isIgnoreExceptionOnPreLoad()
      Description copied from interface: PoolConfiguration
      Returns whether exceptions during connection creation at pool initialization should be ignored. See PoolConfiguration.setIgnoreExceptionOnPreLoad(boolean) for details.
      Specified by:
      isIgnoreExceptionOnPreLoad in interface PoolConfiguration
      Returns:
      true to ignore exceptions during pre-load
    • setIgnoreExceptionOnPreLoad

      public void setIgnoreExceptionOnPreLoad(boolean ignoreExceptionOnPreLoad)
      Description copied from interface: PoolConfiguration
      Set to true if you want to ignore error of connection creation while initializing the pool. Set to false if you want to fail the initialization of the pool by throwing exception.
      Specified by:
      setIgnoreExceptionOnPreLoad in interface PoolConfiguration
      Parameters:
      ignoreExceptionOnPreLoad - set to true if you want to ignore error of connection creation while initializing the pool.
    • getUseStatementFacade

      @Deprecated public boolean getUseStatementFacade()
      Deprecated.
      The statement facade is always used, so this property no longer has any effect.
      Returns the value stored for the deprecated useStatementFacade property. The pool always wraps the statements it hands out - and the result sets read from them - in a facade, whatever value is returned here.
      Specified by:
      getUseStatementFacade in interface PoolConfiguration
      Returns:
      the configured value, retained but without effect
    • setUseStatementFacade

      @Deprecated public void setUseStatementFacade(boolean useStatementFacade)
      Deprecated.
      The statement facade is always used, so this property no longer has any effect.
      Stores the value of the deprecated useStatementFacade property. The pool always wraps the statements it hands out - and the result sets read from them - in a facade, whatever value is stored here. That facade answers equals(), hashCode() and toString() on closed statements, answers Statement.getConnection() with the pooled connection the statement was created from, and stops the statement and its result sets from working once that connection has been returned to the pool.
      Specified by:
      setUseStatementFacade in interface PoolConfiguration
      Parameters:
      useStatementFacade - the configured value, retained but without effect
    • purge

      public void purge()
      Purge all connections from the pool.
    • purgeOnReturn

      public void purgeOnReturn()
      Enable purging of connections on return to the pool.