com.alibaba.druid.pool
Class DruidDataSource

java.lang.Object
  extended by com.alibaba.druid.pool.WrapperAdapter
      extended by com.alibaba.druid.pool.DruidAbstractDataSource
          extended by com.alibaba.druid.pool.DruidDataSource
All Implemented Interfaces:
DruidAbstractDataSourceMBean, DruidDataSourceMBean, ManagedDataSource, DataSourceProxy, Closeable, Serializable, Cloneable, Wrapper, Referenceable, CommonDataSource, ConnectionPoolDataSource, DataSource
Direct Known Subclasses:
DruidXADataSource

public class DruidDataSource
extends DruidAbstractDataSource
implements DruidDataSourceMBean, ManagedDataSource, Referenceable, Closeable, Cloneable, ConnectionPoolDataSource

Author:
ljw, wenshao
See Also:
Serialized Form

Nested Class Summary
 class DruidDataSource.CreateConnectionThread
           
 class DruidDataSource.DestroyConnectionThread
           
 
Field Summary
 
Fields inherited from class com.alibaba.druid.pool.DruidAbstractDataSource
DEFAULT_INITIAL_SIZE, DEFAULT_MAX_ACTIVE_SIZE, DEFAULT_MAX_IDLE, DEFAULT_MAX_WAIT, DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, DEFAULT_MIN_IDLE, DEFAULT_NUM_TESTS_PER_EVICTION_RUN, DEFAULT_TEST_ON_BORROW, DEFAULT_TEST_ON_RETURN, DEFAULT_TIME_BETWEEN_CONNECT_ERROR_MILLIS, DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, DEFAULT_VALIDATION_QUERY, DEFAULT_WHILE_IDLE
 
Constructor Summary
DruidDataSource()
           
DruidDataSource(boolean fairLock)
           
 
Method Summary
 void clearStatementCache()
           
 Object clone()
           
 DruidDataSource cloneDruidDataSource()
           
 void close()
          close datasource
 void discardConnection(Connection realConnection)
          抛弃连接,不进行回收,而是抛弃
 String dump()
           
 int getActiveCount()
           
 int getActivePeak()
           
 Date getActivePeakTime()
           
 long getCloseCount()
           
 long getConnectCount()
           
 long getConnectErrorCount()
           
 DruidPooledConnection getConnection()
           
 DruidPooledConnection getConnection(long maxWaitMillis)
           
 Connection getConnection(String username, String password)
           
 DruidPooledConnection getConnectionDirect(long maxWaitMillis)
           
 long getCreateCount()
           
 JdbcDataSourceStat getDataSourceStat()
           
 long getDestroyCount()
           
 long getDiscardCount()
           
 long getErrorCount()
           
 List<String> getFilterClassNames()
           
 String getInitStackTrace()
           
 Lock getLock()
           
 int getLockQueueLength()
           
 long getNotEmptySignalCount()
           
 long getNotEmptyWaitCount()
           
 long getNotEmptyWaitMillis()
           
 long getNotEmptyWaitNanos()
           
 int getNotEmptyWaitThreadCount()
           
 int getNotEmptyWaitThreadPeak()
           
 PooledConnection getPooledConnection()
           
 PooledConnection getPooledConnection(String user, String password)
           
 List<Map<String,Object>> getPoolingConnectionInfo()
           
 int getPoolingCount()
           
 int getPoolingPeak()
           
 Date getPoolingPeakTime()
           
 String getProperties()
           
 int getRawDriverMajorVersion()
           
 int getRawDriverMinorVersion()
           
 long getRecycleCount()
           
 Reference getReference()
           
 long getRemoveAbandonedCount()
           
 JdbcSqlStat getSqlStat(int sqlId)
           
 JdbcSqlStat getSqlStat(long sqlId)
           
 Map<String,JdbcSqlStat> getSqlStatMap()
           
 Map<String,Object> getStatData()
           
 Map<String,Object> getStatDataForMBean()
           
 String getVersion()
           
 int getWaitThreadCount()
           
 void handleConnectionException(DruidPooledConnection pooledConnection, Throwable t)
           
 void init()
           
 boolean isBusy()
           
 boolean isEnable()
           
 boolean isInited()
           
 boolean isResetStatEnable()
           
 void logTransaction(TransactionInfo info)
           
 int removeAbandoned()
           
 void resetStat()
           
 void restart()
           
 void setConnectProperties(Properties properties)
           
 void setEnable(boolean enable)
           
 void setMaxActive(int maxActive)
           
 void setPoolPreparedStatements(boolean value)
           
 void setResetStatEnable(boolean resetStatEnable)
           
 void shrink()
           
 void shrink(boolean checkTime)
           
 String toString()
           
 
Methods inherited from class com.alibaba.druid.pool.DruidAbstractDataSource
addConnectionProperty, closePreapredStatement, createConnectionId, createPhysicalConnection, createPhysicalConnection, createResultSetId, createStatementId, createTransactionId, decrementCachedPreparedStatementCount, getActiveConnections, getActiveConnectionStackTrace, getCachedPreparedStatementAccessCount, getCachedPreparedStatementCount, getCachedPreparedStatementDeleteCount, getCachedPreparedStatementHitCount, getCachedPreparedStatementMissCount, getClosedPreparedStatementCount, getCommitCount, getCompositeData, getConnectionErrorRetryAttempts, getConnectionInitSqls, getConnectProperties, getCreatedTime, getCreateErrorCount, getCreateTimespanMillis, getCreateTimespanNano, getDbType, getDefaultCatalog, getDefaultReadOnly, getDefaultTransactionIsolation, getDriver, getDriverClassLoader, getDriverClassName, getDriverMajorVersion, getDriverMinorVersion, getDupCloseCount, getExceptionSorter, getExceptionSorterClassName, getExecuteCount, getFilterClasses, getID, getInitialSize, getLastCreateError, getLastCreateErrorTime, getLastCreateErrorTimeMillis, getLastError, getLastErrorTime, getLastErrorTimeMillis, getLoginTimeout, getLogWriter, getMaxActive, getMaxIdle, getMaxOpenPreparedStatements, getMaxPoolPreparedStatementPerConnectionSize, getMaxWait, getMaxWaitThreadCount, getMinEvictableIdleTimeMillis, getMinIdle, getName, getNumTestsPerEvictionRun, getObjectName, getParentLogger, getPassword, getPasswordCallback, getPreparedStatementCount, getProxyFilters, getQueryTimeout, getRawDriver, getRawJdbcUrl, getRemoveAbandonedTimeout, getRemoveAbandonedTimeoutMillis, getRollbackCount, getStartTransactionCount, getTimeBetweenConnectErrorMillis, getTimeBetweenEvictionRunsMillis, getTransactionHistogram, getTransactionHistogramRanges, getTransactionHistogramValues, getTransactionQueryTimeout, getTransactionThresholdMillis, getUrl, getUserCallback, getUsername, getValidationQuery, getValidationQueryTimeout, getValidConnectionChecker, getValidConnectionCheckerClassName, incrementCachedPreparedStatementCount, incrementCachedPreparedStatementDeleteCount, incrementCachedPreparedStatementHitCount, incrementCachedPreparedStatementMissCount, incrementClosedPreparedStatementCount, incrementCommitCount, incrementDupCloseCount, incrementExecuteCount, incrementPreparedStatementCount, incrementRollbackCount, incrementStartTransactionCount, initPhysicalConnection, isAccessToUnderlyingConnectionAllowed, isBreakAfterAcquireFailure, isDefaultAutoCommit, isDupCloseLogEnable, isLogAbandoned, isOracle, isPoolPreparedStatements, isRemoveAbandoned, isSharePreparedStatements, isTestOnBorrow, isTestOnReturn, isTestWhileIdle, isUseOracleImplicitCache, isUseUnfairLock, setAccessToUnderlyingConnectionAllowed, setBreakAfterAcquireFailure, setConnectionErrorRetryAttempts, setConnectionInitSqls, setConnectionProperties, setDbType, setDefaultAutoCommit, setDefaultCatalog, setDefaultReadOnly, setDefaultTransactionIsolation, setDriver, setDriverClassLoader, setDriverClassName, setDupCloseLogEnable, setExceptionSorter, setExceptionSorter, setExceptionSorterClassName, setFilters, setInitialSize, setLogAbandoned, setLoginTimeout, setLogWriter, setMaxIdle, setMaxOpenPreparedStatements, setMaxPoolPreparedStatementPerConnectionSize, setMaxWait, setMaxWaitThreadCount, setMinEvictableIdleTimeMillis, setMinIdle, setName, setNumTestsPerEvictionRun, setObjectName, setOracle, setPassword, setPasswordCallback, setPasswordCallbackClassName, setProxyFilters, setQueryTimeout, setRemoveAbandoned, setRemoveAbandonedTimeout, setRemoveAbandonedTimeoutMillis, setSharePreparedStatements, setTestOnBorrow, setTestOnReturn, setTestWhileIdle, setTimeBetweenConnectErrorMillis, setTimeBetweenEvictionRunsMillis, setTransactionQueryTimeout, setTransactionThresholdMillis, setUrl, setUseOracleImplicitCache, setUserCallback, setUsername, setUseUnfairLock, setValidationQuery, setValidationQueryTimeout, setValidConnectionChecker, setValidConnectionCheckerClassName, validateConnection
 
Methods inherited from class com.alibaba.druid.pool.WrapperAdapter
isWrapperFor, unwrap
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.alibaba.druid.pool.DruidDataSourceMBean
getObjectName
 
Methods inherited from interface com.alibaba.druid.pool.DruidAbstractDataSourceMBean
getActiveConnectionStackTrace, getCachedPreparedStatementAccessCount, getCachedPreparedStatementCount, getCachedPreparedStatementDeleteCount, getCachedPreparedStatementHitCount, getCachedPreparedStatementMissCount, getClosedPreparedStatementCount, getCommitCount, getConnectionErrorRetryAttempts, getCreatedTime, getCreateErrorCount, getCreateTimespanMillis, getDbType, getDefaultCatalog, getDefaultReadOnly, getDefaultTransactionIsolation, getDriverClassName, getDriverMajorVersion, getDriverMinorVersion, getDupCloseCount, getExceptionSorterClassName, getInitialSize, getLoginTimeout, getMaxActive, getMaxIdle, getMaxOpenPreparedStatements, getMaxPoolPreparedStatementPerConnectionSize, getMaxWait, getMaxWaitThreadCount, getMinEvictableIdleTimeMillis, getMinIdle, getName, getPreparedStatementCount, getQueryTimeout, getRemoveAbandonedTimeoutMillis, getRollbackCount, getStartTransactionCount, getTimeBetweenConnectErrorMillis, getTimeBetweenEvictionRunsMillis, getTransactionHistogramValues, getTransactionQueryTimeout, getTransactionThresholdMillis, getUrl, getUsername, getValidationQuery, getValidationQueryTimeout, getValidConnectionCheckerClassName, isBreakAfterAcquireFailure, isDefaultAutoCommit, isLogAbandoned, isPoolPreparedStatements, isRemoveAbandoned, isSharePreparedStatements, isTestOnBorrow, isTestOnReturn, isTestWhileIdle, isUseOracleImplicitCache, setLogAbandoned, setMaxPoolPreparedStatementPerConnectionSize, setTestOnBorrow, setTestWhileIdle, setTransactionThresholdMillis, setUseOracleImplicitCache
 
Methods inherited from interface com.alibaba.druid.pool.ManagedDataSource
getObjectName, setObjectName
 
Methods inherited from interface javax.sql.CommonDataSource
getLoginTimeout, getLogWriter, setLoginTimeout, setLogWriter
 
Methods inherited from interface java.sql.Wrapper
isWrapperFor, unwrap
 

Constructor Detail

DruidDataSource

public DruidDataSource()

DruidDataSource

public DruidDataSource(boolean fairLock)
Method Detail

getInitStackTrace

public String getInitStackTrace()

isResetStatEnable

public boolean isResetStatEnable()
Specified by:
isResetStatEnable in interface DruidDataSourceMBean

setResetStatEnable

public void setResetStatEnable(boolean resetStatEnable)
Specified by:
setResetStatEnable in interface DruidDataSourceMBean

getDiscardCount

public long getDiscardCount()
Specified by:
getDiscardCount in interface DruidDataSourceMBean

restart

public void restart()

resetStat

public void resetStat()
Specified by:
resetStat in interface DruidDataSourceMBean

isEnable

public boolean isEnable()
Specified by:
isEnable in interface DruidDataSourceMBean
Specified by:
isEnable in interface ManagedDataSource

setEnable

public void setEnable(boolean enable)
Specified by:
setEnable in interface ManagedDataSource

setPoolPreparedStatements

public void setPoolPreparedStatements(boolean value)
Specified by:
setPoolPreparedStatements in interface DruidDataSourceMBean
Specified by:
setPoolPreparedStatements in class DruidAbstractDataSource

setMaxActive

public void setMaxActive(int maxActive)
Specified by:
setMaxActive in interface DruidAbstractDataSourceMBean
Specified by:
setMaxActive in class DruidAbstractDataSource

setConnectProperties

public void setConnectProperties(Properties properties)
Specified by:
setConnectProperties in class DruidAbstractDataSource

isInited

public boolean isInited()

init

public void init()
          throws SQLException
Throws:
SQLException

getConnection

public DruidPooledConnection getConnection()
                                    throws SQLException
Specified by:
getConnection in interface DataSource
Throws:
SQLException

getConnection

public DruidPooledConnection getConnection(long maxWaitMillis)
                                    throws SQLException
Throws:
SQLException

getPooledConnection

public PooledConnection getPooledConnection()
                                     throws SQLException
Specified by:
getPooledConnection in interface ConnectionPoolDataSource
Throws:
SQLException

getPooledConnection

public PooledConnection getPooledConnection(String user,
                                            String password)
                                     throws SQLException
Specified by:
getPooledConnection in interface ConnectionPoolDataSource
Throws:
SQLException

getConnectionDirect

public DruidPooledConnection getConnectionDirect(long maxWaitMillis)
                                          throws SQLException
Throws:
SQLException

discardConnection

public void discardConnection(Connection realConnection)
抛弃连接,不进行回收,而是抛弃

Specified by:
discardConnection in class DruidAbstractDataSource
Parameters:
realConnection -
Throws:
SQLException

handleConnectionException

public void handleConnectionException(DruidPooledConnection pooledConnection,
                                      Throwable t)
                               throws SQLException
Specified by:
handleConnectionException in class DruidAbstractDataSource
Throws:
SQLException

clearStatementCache

public void clearStatementCache()
                         throws SQLException
Specified by:
clearStatementCache in interface DruidDataSourceMBean
Throws:
SQLException

close

public void close()
close datasource

Specified by:
close in interface Closeable

getConnection

public Connection getConnection(String username,
                                String password)
                         throws SQLException
Specified by:
getConnection in interface DataSource
Throws:
SQLException

getCreateCount

public long getCreateCount()
Specified by:
getCreateCount in interface DruidAbstractDataSourceMBean

getDestroyCount

public long getDestroyCount()
Specified by:
getDestroyCount in interface DruidAbstractDataSourceMBean

getConnectCount

public long getConnectCount()
Specified by:
getConnectCount in interface DruidAbstractDataSourceMBean

getCloseCount

public long getCloseCount()
Specified by:
getCloseCount in interface DruidAbstractDataSourceMBean

getConnectErrorCount

public long getConnectErrorCount()
Specified by:
getConnectErrorCount in interface DruidAbstractDataSourceMBean

getPoolingCount

public int getPoolingCount()
Specified by:
getPoolingCount in interface DruidAbstractDataSourceMBean

getPoolingPeak

public int getPoolingPeak()
Specified by:
getPoolingPeak in interface DruidDataSourceMBean

getPoolingPeakTime

public Date getPoolingPeakTime()
Specified by:
getPoolingPeakTime in interface DruidDataSourceMBean

getRecycleCount

public long getRecycleCount()
Specified by:
getRecycleCount in interface DruidAbstractDataSourceMBean

getActiveCount

public int getActiveCount()
Specified by:
getActiveCount in interface DruidAbstractDataSourceMBean

isBusy

public boolean isBusy()

getRemoveAbandonedCount

public long getRemoveAbandonedCount()
Specified by:
getRemoveAbandonedCount in interface DruidAbstractDataSourceMBean

removeAbandoned

public int removeAbandoned()
Specified by:
removeAbandoned in interface DruidDataSourceMBean

getReference

public Reference getReference()
                       throws NamingException
Specified by:
getReference in interface Referenceable
Throws:
NamingException

getFilterClassNames

public List<String> getFilterClassNames()
Specified by:
getFilterClassNames in interface DruidAbstractDataSourceMBean

getRawDriverMajorVersion

public int getRawDriverMajorVersion()
Specified by:
getRawDriverMajorVersion in interface DruidAbstractDataSourceMBean
Specified by:
getRawDriverMajorVersion in class DruidAbstractDataSource

getRawDriverMinorVersion

public int getRawDriverMinorVersion()
Specified by:
getRawDriverMinorVersion in interface DruidAbstractDataSourceMBean
Specified by:
getRawDriverMinorVersion in class DruidAbstractDataSource

getProperties

public String getProperties()
Specified by:
getProperties in interface DruidAbstractDataSourceMBean
Specified by:
getProperties in class DruidAbstractDataSource

shrink

public void shrink()
Specified by:
shrink in interface DruidDataSourceMBean

shrink

public void shrink(boolean checkTime)

getWaitThreadCount

public int getWaitThreadCount()
Specified by:
getWaitThreadCount in interface DruidDataSourceMBean

getNotEmptyWaitCount

public long getNotEmptyWaitCount()
Specified by:
getNotEmptyWaitCount in interface DruidDataSourceMBean

getNotEmptyWaitThreadCount

public int getNotEmptyWaitThreadCount()
Specified by:
getNotEmptyWaitThreadCount in interface DruidDataSourceMBean

getNotEmptyWaitThreadPeak

public int getNotEmptyWaitThreadPeak()

getNotEmptySignalCount

public long getNotEmptySignalCount()
Specified by:
getNotEmptySignalCount in interface DruidDataSourceMBean

getNotEmptyWaitMillis

public long getNotEmptyWaitMillis()
Specified by:
getNotEmptyWaitMillis in interface DruidDataSourceMBean

getNotEmptyWaitNanos

public long getNotEmptyWaitNanos()
Specified by:
getNotEmptyWaitNanos in interface DruidDataSourceMBean

getLockQueueLength

public int getLockQueueLength()
Specified by:
getLockQueueLength in interface DruidDataSourceMBean

getActivePeak

public int getActivePeak()
Specified by:
getActivePeak in interface DruidDataSourceMBean
Specified by:
getActivePeak in class DruidAbstractDataSource

getActivePeakTime

public Date getActivePeakTime()
Specified by:
getActivePeakTime in interface DruidDataSourceMBean

dump

public String dump()
Specified by:
dump in interface DruidDataSourceMBean

getErrorCount

public long getErrorCount()
Specified by:
getErrorCount in interface DruidDataSourceMBean

toString

public String toString()
Overrides:
toString in class Object

getPoolingConnectionInfo

public List<Map<String,Object>> getPoolingConnectionInfo()

logTransaction

public void logTransaction(TransactionInfo info)
Specified by:
logTransaction in class DruidAbstractDataSource

getVersion

public String getVersion()
Specified by:
getVersion in interface DruidDataSourceMBean

getDataSourceStat

public JdbcDataSourceStat getDataSourceStat()
Specified by:
getDataSourceStat in interface DataSourceProxy

clone

public Object clone()
             throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

cloneDruidDataSource

public DruidDataSource cloneDruidDataSource()

getStatDataForMBean

public Map<String,Object> getStatDataForMBean()

getStatData

public Map<String,Object> getStatData()

getSqlStat

public JdbcSqlStat getSqlStat(int sqlId)

getSqlStat

public JdbcSqlStat getSqlStat(long sqlId)

getSqlStatMap

public Map<String,JdbcSqlStat> getSqlStatMap()

getLock

public Lock getLock()


Copyright © 2012 Alibaba Group. All Rights Reserved.