org.apache.commons.dbcp
Class ManagedBasicDataSource

java.lang.Object
  extended by org.apache.commons.dbcp.BasicDataSource
      extended by org.apache.commons.dbcp.ManagedBasicDataSource
All Implemented Interfaces:
Wrapper, CommonDataSource, DataSource

public class ManagedBasicDataSource
extends org.apache.commons.dbcp.BasicDataSource

Wrapper for BasicDataSource that exposes some fields and methods as a MBean.

Since:
0.1
Author:
Julien Nicoulaud

Field Summary
static String DEFAULT_MBEAN_NAME
          The default auto-generated unique name for the exposed MBean.
protected  String mBeanName
          The name under which this object is exposed to the MBean server.
 
Fields inherited from class org.apache.commons.dbcp.BasicDataSource
closed, connectionInitSqls, connectionPool, connectionProperties, dataSource, defaultAutoCommit, defaultCatalog, defaultReadOnly, defaultTransactionIsolation, driverClassLoader, driverClassName, initialSize, logWriter, maxActive, maxIdle, maxOpenPreparedStatements, maxWait, minEvictableIdleTimeMillis, minIdle, numTestsPerEvictionRun, password, poolPreparedStatements, testOnBorrow, testOnReturn, testWhileIdle, timeBetweenEvictionRunsMillis, url, username, validationQuery, validationQueryTimeout
 
Constructor Summary
ManagedBasicDataSource()
          Build a new instance of ManagedBasicDataSource and expose it as a MBean with an auto-generated unique name.
ManagedBasicDataSource(MBeanServer mBeanServer, String mBeanName)
          Build a new instance of ManagedBasicDataSource and expose it as a MBean with the specified name.
ManagedBasicDataSource(String mBeanName)
          Build a new instance of ManagedBasicDataSource and expose it as a MBean with the specified name.
 
Method Summary
protected  void exportMBean(MBeanServer mBeanServer, String name)
          Export this object as a MBean to the platform default MBean server.
 int getMaxActive()
          Get the maximum number of active connections that can be allocated at the same time.
 int getMaxIdle()
          Get the maximum number of connections that can remain idle in the pool.
 long getMaxWait()
          Get the maximum number of milliseconds that the pool will wait for a connection to be returned before throwing an exception.
 String getMBeanName()
          Get the name under which this object is exposed to the MBean server.
 int getMinIdle()
          Get the minimum number of idle connections in the pool.
 int getNumActive()
          Get the current number of active connections that have been allocated from this data source.
 int getNumIdle()
          Get the current number of idle connections that are waiting to be allocated from this data source.
 String getUrl()
          Get the JDBC connection BasicDataSource.url property.
 String getUsername()
          Get the JDBC connection BasicDataSource.username property.
 boolean isWrapperFor(Class<?> iface)
          
 void setMaxActive(int maxActive)
          Set the maximum number of active connections that can be allocated at the same time.
 void setMaxIdle(int maxIdle)
          Set the maximum number of connections that can remain idle in the pool.
 void setMaxWait(long maxWait)
          Set the maxWait property.
 void setMinIdle(int minIdle)
          Set the minimum number of idle connections in the pool.
<T> T
unwrap(Class<T> iface)
          
 
Methods inherited from class org.apache.commons.dbcp.BasicDataSource
addConnectionProperty, close, createConnectionFactory, createConnectionPool, createDataSource, createDataSourceInstance, createPoolableConnectionFactory, getConnection, getConnection, getConnectionInitSqls, getDefaultAutoCommit, getDefaultCatalog, getDefaultReadOnly, getDefaultTransactionIsolation, getDriverClassLoader, getDriverClassName, getInitialSize, getLogAbandoned, getLoginTimeout, getLogWriter, getMaxOpenPreparedStatements, getMinEvictableIdleTimeMillis, getNumTestsPerEvictionRun, getPassword, getRemoveAbandoned, getRemoveAbandonedTimeout, getTestOnBorrow, getTestOnReturn, getTestWhileIdle, getTimeBetweenEvictionRunsMillis, getValidationQuery, getValidationQueryTimeout, isAccessToUnderlyingConnectionAllowed, isClosed, isPoolPreparedStatements, log, removeConnectionProperty, setAccessToUnderlyingConnectionAllowed, setConnectionInitSqls, setConnectionProperties, setDefaultAutoCommit, setDefaultCatalog, setDefaultReadOnly, setDefaultTransactionIsolation, setDriverClassLoader, setDriverClassName, setInitialSize, setLogAbandoned, setLoginTimeout, setLogWriter, setMaxOpenPreparedStatements, setMinEvictableIdleTimeMillis, setNumTestsPerEvictionRun, setPassword, setPoolPreparedStatements, setRemoveAbandoned, setRemoveAbandonedTimeout, setTestOnBorrow, setTestOnReturn, setTestWhileIdle, setTimeBetweenEvictionRunsMillis, setUrl, setUsername, setValidationQuery, setValidationQueryTimeout, validateConnectionFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MBEAN_NAME

public static final String DEFAULT_MBEAN_NAME
The default auto-generated unique name for the exposed MBean.

See Also:
Constant Field Values

mBeanName

protected final String mBeanName
The name under which this object is exposed to the MBean server.

Constructor Detail

ManagedBasicDataSource

public ManagedBasicDataSource()
Build a new instance of ManagedBasicDataSource and expose it as a MBean with an auto-generated unique name.

See Also:
DEFAULT_MBEAN_NAME, exportMBean(MBeanServer, String)

ManagedBasicDataSource

public ManagedBasicDataSource(String mBeanName)
Build a new instance of ManagedBasicDataSource and expose it as a MBean with the specified name.

Parameters:
mBeanName - the name of the MBean to expose, should be unique accross the target application.
See Also:
DEFAULT_MBEAN_NAME, exportMBean(MBeanServer, String)

ManagedBasicDataSource

public ManagedBasicDataSource(MBeanServer mBeanServer,
                              String mBeanName)
Build a new instance of ManagedBasicDataSource and expose it as a MBean with the specified name.

Parameters:
mBeanServer -
mBeanName - the name of the MBean to expose, should be unique accross the target application.
See Also:
DEFAULT_MBEAN_NAME, exportMBean(MBeanServer, String)
Method Detail

exportMBean

protected void exportMBean(MBeanServer mBeanServer,
                           String name)
Export this object as a MBean to the platform default MBean server.

Parameters:
mBeanServer -
name - the name of the MBean to expose.

getMBeanName

public String getMBeanName()
Get the name under which this object is exposed to the MBean server.

Returns:
the MBean object name.

isWrapperFor

public boolean isWrapperFor(Class<?> iface)
                     throws SQLException

Specified by:
isWrapperFor in interface Wrapper
Overrides:
isWrapperFor in class org.apache.commons.dbcp.BasicDataSource
Throws:
SQLException

unwrap

public <T> T unwrap(Class<T> iface)
         throws SQLException

Specified by:
unwrap in interface Wrapper
Overrides:
unwrap in class org.apache.commons.dbcp.BasicDataSource
Throws:
SQLException

getNumActive

public int getNumActive()
Get the current number of active connections that have been allocated from this data source.

Overrides:
getNumActive in class org.apache.commons.dbcp.BasicDataSource
Returns:
the current number of active connections.

getNumIdle

public int getNumIdle()
Get the current number of idle connections that are waiting to be allocated from this data source.

Overrides:
getNumIdle in class org.apache.commons.dbcp.BasicDataSource
Returns:
the current number of idle connections.

getMaxActive

public int getMaxActive()
Get the maximum number of active connections that can be allocated at the same time.

A negative number means that there is no limit.

Overrides:
getMaxActive in class org.apache.commons.dbcp.BasicDataSource
Returns:
the maximum number of active connections.

setMaxActive

public void setMaxActive(int maxActive)
Set the maximum number of active connections that can be allocated at the same time. Use a negative value for no limit.

Overrides:
setMaxActive in class org.apache.commons.dbcp.BasicDataSource
Parameters:
maxActive - the new value for maxActive.
See Also:
getMaxActive()

getMaxIdle

public int getMaxIdle()
Get the maximum number of connections that can remain idle in the pool.

A negative value indicates that there is no limit.

Overrides:
getMaxIdle in class org.apache.commons.dbcp.BasicDataSource
Returns:
the maximum number of idle connections.

setMaxIdle

public void setMaxIdle(int maxIdle)
Set the maximum number of connections that can remain idle in the pool.

Overrides:
setMaxIdle in class org.apache.commons.dbcp.BasicDataSource
Parameters:
maxIdle - the new value for maxIdle.
See Also:
getMaxIdle()

getMinIdle

public int getMinIdle()
Get the minimum number of idle connections in the pool.

Overrides:
getMinIdle in class org.apache.commons.dbcp.BasicDataSource
Returns:
the minimum number of idle connections.
See Also:
GenericObjectPool.getMinIdle()

setMinIdle

public void setMinIdle(int minIdle)
Set the minimum number of idle connections in the pool.

Overrides:
setMinIdle in class org.apache.commons.dbcp.BasicDataSource
Parameters:
minIdle - the new value for minIdle.
See Also:
GenericObjectPool.setMinIdle(int)

getMaxWait

public long getMaxWait()
Get the maximum number of milliseconds that the pool will wait for a connection to be returned before throwing an exception.

A value less than or equal to zero means the pool is set to wait indefinitely.

Overrides:
getMaxWait in class org.apache.commons.dbcp.BasicDataSource
Returns:
the maxWait property value.

setMaxWait

public void setMaxWait(long maxWait)
Set the maxWait property.

Use -1 to make the pool wait indefinitely.

Overrides:
setMaxWait in class org.apache.commons.dbcp.BasicDataSource
Parameters:
maxWait - the new value for maxWait.
See Also:
getMaxWait()

getUrl

public String getUrl()
Get the JDBC connection BasicDataSource.url property.

Overrides:
getUrl in class org.apache.commons.dbcp.BasicDataSource
Returns:
the BasicDataSource.url passed to the JDBC driver to establish connections.

getUsername

public String getUsername()
Get the JDBC connection BasicDataSource.username property.

Overrides:
getUsername in class org.apache.commons.dbcp.BasicDataSource
Returns:
the BasicDataSource.username passed to the JDBC driver to establish connections.


Copyright © 2010-2013. All Rights Reserved.