mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Filter-Chain refactor
This commit is contained in:
@@ -60,15 +60,12 @@ import com.alibaba.druid.proxy.jdbc.StatementProxy;
|
||||
*/
|
||||
public abstract class FilterAdapter extends NotificationBroadcasterSupport implements Filter {
|
||||
|
||||
protected DataSourceProxy dataSource;
|
||||
|
||||
@Override
|
||||
public void loadConfig(AbstractDruidFilterConfig DruidFilterConfig) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(DataSourceProxy dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2709,7 +2706,8 @@ public abstract class FilterAdapter extends NotificationBroadcasterSupport imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public DruidPooledConnection dataSource_getConnection(FilterChain chain, DruidDataSource dataSource, long maxWaitMillis) throws SQLException {
|
||||
public DruidPooledConnection dataSource_getConnection(FilterChain chain, DruidDataSource dataSource,
|
||||
long maxWaitMillis) throws SQLException {
|
||||
return chain.dataSource_connect(dataSource, maxWaitMillis);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.alibaba.druid.proxy.jdbc.CallableStatementProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ClobProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.DataSourceProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.StatementProxy;
|
||||
@@ -54,7 +55,8 @@ import com.alibaba.druid.proxy.jdbc.StatementProxy;
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
*/
|
||||
public interface FilterChain {
|
||||
|
||||
DataSourceProxy getDataSource();
|
||||
|
||||
int getFilterSize();
|
||||
|
||||
FilterChain cloneChain();
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.sql.CallableStatement;
|
||||
import java.sql.Clob;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.Driver;
|
||||
import java.sql.NClob;
|
||||
import java.sql.ParameterMetaData;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -93,6 +94,10 @@ public class FilterChainImpl implements FilterChain {
|
||||
return new FilterChainImpl(dataSource, pos);
|
||||
}
|
||||
|
||||
public DataSourceProxy getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Wrapper wrapper, Class<?> iface) throws SQLException {
|
||||
if (this.pos < filterSize) {
|
||||
@@ -131,7 +136,10 @@ public class FilterChainImpl implements FilterChain {
|
||||
return nextFilter().connection_connect(this, info);
|
||||
}
|
||||
|
||||
Connection nativeConnection = dataSource.getRawDriver().connect(dataSource.getRawJdbcUrl(), info);
|
||||
Driver driver = dataSource.getRawDriver();
|
||||
String url = dataSource.getRawJdbcUrl();
|
||||
|
||||
Connection nativeConnection = driver.connect(url, info);
|
||||
return wrap(nativeConnection, info);
|
||||
}
|
||||
|
||||
@@ -248,7 +256,7 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
Statement statement = connection.getRawObject().createStatement(resultSetType, resultSetConcurrency,
|
||||
resultSetHoldability);
|
||||
resultSetHoldability);
|
||||
return wrap(connection, statement);
|
||||
}
|
||||
|
||||
@@ -409,8 +417,7 @@ public class FilterChainImpl implements FilterChain {
|
||||
return nextFilter().connection_prepareCall(this, connection, sql, resultSetType, resultSetConcurrency);
|
||||
}
|
||||
|
||||
CallableStatement statement = connection.getRawObject().prepareCall(sql, resultSetType,
|
||||
resultSetConcurrency);
|
||||
CallableStatement statement = connection.getRawObject().prepareCall(sql, resultSetType, resultSetConcurrency);
|
||||
return wrap(connection, statement, sql);
|
||||
}
|
||||
|
||||
@@ -423,9 +430,8 @@ public class FilterChainImpl implements FilterChain {
|
||||
resultSetHoldability);
|
||||
}
|
||||
|
||||
CallableStatement statement = connection.getRawObject().prepareCall(sql, resultSetType,
|
||||
resultSetConcurrency,
|
||||
resultSetHoldability);
|
||||
CallableStatement statement = connection.getRawObject().prepareCall(sql, resultSetType, resultSetConcurrency,
|
||||
resultSetHoldability);
|
||||
return wrap(connection, statement, sql);
|
||||
}
|
||||
|
||||
@@ -460,7 +466,7 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
PreparedStatement statement = connection.getRawObject().prepareStatement(sql, resultSetType,
|
||||
resultSetConcurrency);
|
||||
resultSetConcurrency);
|
||||
return wrap(connection, statement, sql);
|
||||
}
|
||||
|
||||
@@ -474,8 +480,8 @@ public class FilterChainImpl implements FilterChain {
|
||||
}
|
||||
|
||||
PreparedStatement statement = connection.getRawObject().prepareStatement(sql, resultSetType,
|
||||
resultSetConcurrency,
|
||||
resultSetHoldability);
|
||||
resultSetConcurrency,
|
||||
resultSetHoldability);
|
||||
return wrap(connection, statement, sql);
|
||||
}
|
||||
|
||||
@@ -3336,33 +3342,31 @@ public class FilterChainImpl implements FilterChain {
|
||||
if (this.pos < filterSize) {
|
||||
return nextFilter().callableStatement_getObject(this, statement, parameterIndex);
|
||||
}
|
||||
|
||||
|
||||
Object obj = statement.getRawObject().getObject(parameterIndex);
|
||||
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(statement, (ResultSet) obj);
|
||||
}
|
||||
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object callableStatement_getObject(CallableStatementProxy statement, int parameterIndex,
|
||||
java.util.Map<String, Class<?>> map) throws SQLException {
|
||||
if (this.pos < filterSize) {
|
||||
return nextFilter().callableStatement_getObject(this, statement, parameterIndex, map);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Object obj = statement.getRawObject().getObject(parameterIndex, map);
|
||||
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(statement, (ResultSet) obj);
|
||||
}
|
||||
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object callableStatement_getObject(CallableStatementProxy statement, String parameterName)
|
||||
@@ -3370,16 +3374,15 @@ public class FilterChainImpl implements FilterChain {
|
||||
if (this.pos < filterSize) {
|
||||
return nextFilter().callableStatement_getObject(this, statement, parameterName);
|
||||
}
|
||||
|
||||
|
||||
Object obj = statement.getRawObject().getObject(parameterName);
|
||||
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(statement, (ResultSet) obj);
|
||||
}
|
||||
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object callableStatement_getObject(CallableStatementProxy statement, String parameterName,
|
||||
@@ -3387,13 +3390,13 @@ public class FilterChainImpl implements FilterChain {
|
||||
if (this.pos < filterSize) {
|
||||
return nextFilter().callableStatement_getObject(this, statement, parameterName, map);
|
||||
}
|
||||
|
||||
|
||||
Object obj = statement.getRawObject().getObject(parameterName, map);
|
||||
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(statement, (ResultSet) obj);
|
||||
}
|
||||
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -4429,7 +4432,7 @@ public class FilterChainImpl implements FilterChain {
|
||||
nextFilter().dataSource_releaseConnection(this, connection);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
connection.recycle();
|
||||
}
|
||||
|
||||
@@ -4439,7 +4442,7 @@ public class FilterChainImpl implements FilterChain {
|
||||
DruidPooledConnection conn = nextFilter().dataSource_getConnection(this, dataSource, maxWaitMillis);
|
||||
return conn;
|
||||
}
|
||||
|
||||
|
||||
return dataSource.getConnectionDirect(maxWaitMillis);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,13 +23,8 @@ import java.sql.SQLException;
|
||||
import java.sql.Savepoint;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import javax.management.JMException;
|
||||
import javax.management.openmbean.CompositeData;
|
||||
import javax.management.openmbean.TabularData;
|
||||
|
||||
import com.alibaba.druid.filter.Filter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.filter.FilterEventAdapter;
|
||||
@@ -66,7 +61,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
public final static String ATTR_TRANSACTION = "stat.tx";
|
||||
public final static String ATTR_RESULTSET_CLOSED = "stat.rs.closed";
|
||||
|
||||
protected JdbcDataSourceStat dataSourceStat;
|
||||
// protected JdbcDataSourceStat dataSourceStat;
|
||||
|
||||
@Deprecated
|
||||
protected final JdbcStatementStat statementStat = JdbcStatManager.getInstance().getStatementStat();
|
||||
@@ -110,16 +105,6 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
this.connectionStackTraceEnable = connectionStackTraceEnable;
|
||||
}
|
||||
|
||||
public JdbcDataSourceStat getDataSourceStat() {
|
||||
return this.dataSourceStat;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
dataSourceStat.reset();
|
||||
|
||||
resetCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public long getResetCount() {
|
||||
return resetCount.get();
|
||||
}
|
||||
@@ -148,9 +133,6 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
@Override
|
||||
public synchronized void init(DataSourceProxy dataSource) {
|
||||
|
||||
this.dataSourceStat = dataSource.getDataSourceStat();
|
||||
|
||||
if (this.dbType == null || this.dbType.trim().length() == 0) {
|
||||
this.dbType = dataSource.getDbType();
|
||||
}
|
||||
@@ -195,15 +177,6 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void destory() {
|
||||
if (dataSource == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
dataSource = null;
|
||||
}
|
||||
|
||||
public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException {
|
||||
ConnectionProxy connection = null;
|
||||
{
|
||||
@@ -213,6 +186,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
long nanoSpan;
|
||||
long nowTime = System.currentTimeMillis();
|
||||
|
||||
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
|
||||
dataSourceStat.getConnectionStat().beforeConnect();
|
||||
try {
|
||||
connection = chain.connection_connect(info);
|
||||
@@ -245,6 +219,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
if (connection.getCloseCount() == 0) {
|
||||
long nowNano = System.nanoTime();
|
||||
|
||||
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
|
||||
dataSourceStat.getConnectionStat().incrementConnectionCloseCount();
|
||||
|
||||
JdbcConnectionStat.Entry connectionInfo = getConnectionInfo(connection);
|
||||
@@ -265,6 +240,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
public void connection_commit(FilterChain chain, ConnectionProxy connection) throws SQLException {
|
||||
chain.connection_commit(connection);
|
||||
|
||||
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
|
||||
dataSourceStat.getConnectionStat().incrementConnectionCommitCount();
|
||||
}
|
||||
|
||||
@@ -272,8 +248,8 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
public void connection_rollback(FilterChain chain, ConnectionProxy connection) throws SQLException {
|
||||
chain.connection_rollback(connection);
|
||||
|
||||
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
|
||||
dataSourceStat.getConnectionStat().incrementConnectionRollbackCount();
|
||||
|
||||
dataSourceStat.getConnectionStat().incrementConnectionRollbackCount();
|
||||
}
|
||||
|
||||
@@ -282,11 +258,13 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
throws SQLException {
|
||||
chain.connection_rollback(connection, savepoint);
|
||||
|
||||
JdbcDataSourceStat dataSourceStat = connection.getDirectDataSource().getDataSourceStat();
|
||||
dataSourceStat.getConnectionStat().incrementConnectionRollbackCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void statementCreateAfter(StatementProxy statement) {
|
||||
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
|
||||
dataSourceStat.getStatementStat().incrementCreateCounter();
|
||||
|
||||
super.statementCreateAfter(statement);
|
||||
@@ -294,6 +272,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
@Override
|
||||
public void statementPrepareCallAfter(CallableStatementProxy statement) {
|
||||
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
|
||||
dataSourceStat.getStatementStat().incrementPrepareCallCount();
|
||||
|
||||
JdbcSqlStat sqlStat = createSqlStat(statement, statement.getSql());
|
||||
@@ -302,6 +281,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
@Override
|
||||
public void statementPrepareAfter(PreparedStatementProxy statement) {
|
||||
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
|
||||
dataSourceStat.getStatementStat().incrementPrepareCounter();
|
||||
JdbcSqlStat sqlStat = createSqlStat(statement, statement.getSql());
|
||||
statement.setSqlStat(sqlStat);
|
||||
@@ -311,6 +291,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
public void statement_close(FilterChain chain, StatementProxy statement) throws SQLException {
|
||||
chain.statement_close(statement);
|
||||
|
||||
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
|
||||
dataSourceStat.getStatementStat().incrementStatementCloseCounter();
|
||||
JdbcStatContext context = JdbcStatManager.getInstance().getStatContext();
|
||||
if (context != null) {
|
||||
@@ -376,9 +357,10 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
}
|
||||
|
||||
private final void internalBeforeStatementExecute(StatementProxy statement, String sql) {
|
||||
|
||||
|
||||
final long startNano = System.nanoTime();
|
||||
|
||||
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
|
||||
dataSourceStat.getStatementStat().beforeExecute();
|
||||
|
||||
final JdbcStatementStat.Entry statementStat = getStatementInfo(statement);
|
||||
@@ -435,6 +417,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
final long nowNano = System.nanoTime();
|
||||
final long nanoSpan = nowNano - entry.getLastExecuteStartNano();
|
||||
|
||||
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
|
||||
dataSourceStat.getStatementStat().afterExecute(nanoSpan);
|
||||
|
||||
final JdbcSqlStat sqlStat = statement.getSqlStat();
|
||||
@@ -469,11 +452,11 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String sql = statement.getLastExecuteSql();
|
||||
StatFilterContext.getInstance().executeAfter(sql, nanoSpan, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void statement_executeErrorAfter(StatementProxy statement, String sql, Throwable error) {
|
||||
|
||||
@@ -483,6 +466,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
long nanoSpan = System.nanoTime() - counter.getLastExecuteStartNano();
|
||||
|
||||
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
|
||||
dataSourceStat.getStatementStat().error(error);
|
||||
dataSourceStat.getStatementStat().afterExecute(nanoSpan);
|
||||
|
||||
@@ -496,7 +480,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
sqlStat.addExecuteTime(statement.getLastExecuteType(), statement.isFirstResultSet(), nanoSpan);
|
||||
statement.setLastExecuteTimeNano(nanoSpan);
|
||||
}
|
||||
|
||||
|
||||
StatFilterContext.getInstance().executeAfter(sql, nanoSpan, error);
|
||||
}
|
||||
|
||||
@@ -568,6 +552,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
@Override
|
||||
protected void resultSetOpenAfter(ResultSetProxy resultSet) {
|
||||
JdbcDataSourceStat dataSourceStat = resultSet.getStatementProxy().getConnectionProxy().getDirectDataSource().getDataSourceStat();
|
||||
dataSourceStat.getResultSetStat().beforeOpen();
|
||||
|
||||
resultSet.setConstructNano();
|
||||
@@ -580,6 +565,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
int fetchRowCount = resultSet.getFetchRowCount();
|
||||
|
||||
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
|
||||
dataSourceStat.getResultSetStat().afterClose(nanoSpan);
|
||||
dataSourceStat.getResultSetStat().addFetchRowCount(fetchRowCount);
|
||||
dataSourceStat.getResultSetStat().incrementCloseCounter();
|
||||
@@ -623,131 +609,9 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
return counter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getConnectionActiveCount() {
|
||||
return dataSourceStat.getConnections().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getConnectionCloseCount() {
|
||||
return dataSourceStat.getConnectionStat().getCloseCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getConnectionCommitCount() {
|
||||
return dataSourceStat.getConnectionStat().getCommitCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getConnectionConnectCount() {
|
||||
return dataSourceStat.getConnectionStat().getConnectCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getConnectionConnectMillis() {
|
||||
return dataSourceStat.getConnectionStat().getConnectMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getConnectionConnectingMax() {
|
||||
return dataSourceStat.getConnectionStat().getConnectingMax();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getConnectionRollbackCount() {
|
||||
return dataSourceStat.getConnectionStat().getConnectMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getConnectionConnectAliveMillis() {
|
||||
return dataSourceStat.getConnectionConnectAliveMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getConnectionConnectErrorCount() {
|
||||
return dataSourceStat.getConnectionStat().getConnectErrorCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getConnectionConnectLastTime() {
|
||||
return dataSourceStat.getConnectionStat().getConnectLastTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStatementCloseCount() {
|
||||
return dataSourceStat.getStatementStat().getCloseCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStatementCreateCount() {
|
||||
return dataSourceStat.getStatementStat().getCreateCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStatementExecuteMillisTotal() {
|
||||
return dataSourceStat.getStatementStat().getExecuteMillisTotal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStatementExecuteErrorLastTime() {
|
||||
return dataSourceStat.getStatementStat().getLastErrorTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getStatementExecuteLastTime() {
|
||||
return dataSourceStat.getStatementStat().getExecuteLastTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStatementPrepareCallCount() {
|
||||
return dataSourceStat.getStatementStat().getPrepareCallCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStatementPrepareCount() {
|
||||
return dataSourceStat.getStatementStat().getPrepareCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStatementExecuteErrorCount() {
|
||||
return dataSourceStat.getStatementStat().getErrorCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStatementExecuteSuccessCount() {
|
||||
return dataSourceStat.getStatementStat().getExecuteSuccessCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getResultSetHoldMillisTotal() {
|
||||
return dataSourceStat.getResultSetStat().getHoldMillisTotal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getResultSetFetchRowCount() {
|
||||
return dataSourceStat.getResultSetStat().getFetchRowCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getResultSetOpenCount() {
|
||||
return dataSourceStat.getResultSetStat().getOpenCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getResultSetCloseCount() {
|
||||
return dataSourceStat.getResultSetStat().getCloseCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConnectionUrl() {
|
||||
if (dataSource == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return dataSource.getUrl();
|
||||
}
|
||||
|
||||
public JdbcSqlStat createSqlStat(StatementProxy statement, String sql) {
|
||||
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
|
||||
|
||||
JdbcStatContext context = JdbcStatManager.getInstance().getStatContext();
|
||||
String contextSql = context != null ? context.getSql() : null;
|
||||
if (contextSql != null && contextSql.length() > 0) {
|
||||
@@ -758,23 +622,6 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
}
|
||||
}
|
||||
|
||||
public JdbcSqlStat getSqlCounter(String sql) {
|
||||
|
||||
sql = mergeSql(sql); // mergeSql
|
||||
return getSqlStat(sql);
|
||||
}
|
||||
|
||||
public JdbcSqlStat getSqlStat(String sql) {
|
||||
|
||||
sql = mergeSql(sql);
|
||||
return dataSourceStat.getSqlStat(sql);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabularData getSqlList() throws JMException {
|
||||
return dataSourceStat.getSqlList();
|
||||
}
|
||||
|
||||
public static StatFilter getStatFilter(DataSourceProxy dataSource) {
|
||||
for (Filter filter : dataSource.getProxyFilters()) {
|
||||
if (filter instanceof StatFilter) {
|
||||
@@ -785,30 +632,13 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
return null;
|
||||
}
|
||||
|
||||
public JdbcSqlStat getSqlStat(long id) {
|
||||
return dataSourceStat.getSqlStat(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompositeData getStatementExecuteLastError() throws JMException {
|
||||
return dataSourceStat.getStatementStat().getLastError();
|
||||
}
|
||||
|
||||
public final ConcurrentMap<Long, JdbcConnectionStat.Entry> getConnections() {
|
||||
return dataSourceStat.getConnections();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabularData getConnectionList() throws JMException {
|
||||
return dataSourceStat.getConnectionList();
|
||||
}
|
||||
|
||||
public void dataSource_releaseConnection(FilterChain chain, DruidPooledConnection conn) throws SQLException {
|
||||
chain.dataSource_recycle(conn);
|
||||
|
||||
long nanos = System.nanoTime() - conn.getConnectedTimeNano();
|
||||
|
||||
long millis = nanos / (1000L * 1000L);
|
||||
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
|
||||
dataSourceStat.getConnectionHoldHistogram().record(millis);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,76 +15,9 @@
|
||||
*/
|
||||
package com.alibaba.druid.filter.stat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.management.JMException;
|
||||
import javax.management.openmbean.CompositeData;
|
||||
import javax.management.openmbean.TabularData;
|
||||
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
*/
|
||||
public interface StatFilterMBean {
|
||||
|
||||
void reset();
|
||||
|
||||
boolean isConnectionStackTraceEnable();
|
||||
|
||||
void setConnectionStackTraceEnable(boolean connectionStackTraceEnable);
|
||||
|
||||
String getConnectionUrl();
|
||||
|
||||
long getConnectionConnectCount();
|
||||
|
||||
long getConnectionCloseCount();
|
||||
|
||||
long getConnectionActiveCount();
|
||||
|
||||
long getConnectionConnectingMax();
|
||||
|
||||
long getConnectionCommitCount();
|
||||
|
||||
long getConnectionRollbackCount();
|
||||
|
||||
long getConnectionConnectMillis();
|
||||
|
||||
long getConnectionConnectAliveMillis();
|
||||
|
||||
long getConnectionConnectErrorCount();
|
||||
|
||||
Date getConnectionConnectLastTime();
|
||||
|
||||
long getStatementCreateCount();
|
||||
|
||||
long getStatementPrepareCount();
|
||||
|
||||
long getStatementPrepareCallCount();
|
||||
|
||||
long getStatementCloseCount();
|
||||
|
||||
long getStatementExecuteMillisTotal();
|
||||
|
||||
long getStatementExecuteSuccessCount();
|
||||
|
||||
long getStatementExecuteErrorCount();
|
||||
|
||||
Date getStatementExecuteErrorLastTime();
|
||||
|
||||
CompositeData getStatementExecuteLastError() throws JMException;
|
||||
|
||||
Date getStatementExecuteLastTime();
|
||||
|
||||
long getResultSetHoldMillisTotal();
|
||||
|
||||
long getResultSetFetchRowCount();
|
||||
|
||||
long getResultSetOpenCount();
|
||||
|
||||
long getResultSetCloseCount();
|
||||
|
||||
TabularData getSqlList() throws JMException;
|
||||
|
||||
TabularData getConnectionList() throws JMException;
|
||||
|
||||
long getResetCount();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ package com.alibaba.druid.pool;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverManager;
|
||||
@@ -50,7 +48,6 @@ import javax.sql.DataSource;
|
||||
import com.alibaba.druid.filter.Filter;
|
||||
import com.alibaba.druid.filter.FilterChainImpl;
|
||||
import com.alibaba.druid.filter.FilterManager;
|
||||
import com.alibaba.druid.filter.stat.StatFilter;
|
||||
import com.alibaba.druid.pool.DruidDataSource.ActiveConnectionTraceInfo;
|
||||
import com.alibaba.druid.pool.vendor.NullExceptionSorter;
|
||||
import com.alibaba.druid.proxy.jdbc.DataSourceProxy;
|
||||
@@ -60,6 +57,7 @@ import com.alibaba.druid.stat.JdbcStatManager;
|
||||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
import com.alibaba.druid.util.ConcurrentIdentityHashMap;
|
||||
import com.alibaba.druid.util.DruidPasswordCallback;
|
||||
import com.alibaba.druid.util.Histogram;
|
||||
import com.alibaba.druid.util.IOUtils;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
@@ -993,12 +991,12 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
public ExceptionSorter getExceptionSorter() {
|
||||
return exceptionSorter;
|
||||
}
|
||||
|
||||
|
||||
public String getExceptionSorterClassName() {
|
||||
if (exceptionSorter == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return exceptionSorter.getClass().getName();
|
||||
}
|
||||
|
||||
@@ -1011,7 +1009,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
this.setExceptionSorter(exceptionSorter);
|
||||
}
|
||||
|
||||
public void setExceptionSorter(String exceptionSorter) throws Exception {
|
||||
public void setExceptionSorter(String exceptionSorter) throws SQLException {
|
||||
if (exceptionSorter == null) {
|
||||
this.exceptionSorter = NullExceptionSorter.getInstance();
|
||||
return;
|
||||
@@ -1027,7 +1025,11 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
if (clazz == null) {
|
||||
LOG.error("load exceptionSorter error : " + exceptionSorter);
|
||||
} else {
|
||||
this.exceptionSorter = (ExceptionSorter) clazz.newInstance();
|
||||
try {
|
||||
this.exceptionSorter = (ExceptionSorter) clazz.newInstance();
|
||||
} catch (Exception ex) {
|
||||
throw new SQLException("create exceptionSorter error", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1221,39 +1223,14 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
user = dataSource.getUsername();
|
||||
}
|
||||
|
||||
String password;
|
||||
String password = dataSource.getPassword();
|
||||
PasswordCallback passwordCallback = dataSource.getPasswordCallback();
|
||||
if (passwordCallback != null) {
|
||||
try {
|
||||
Method method = passwordCallback.getClass().getMethod("setUrl", String.class);
|
||||
method.invoke(passwordCallback, url);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
// skip
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new SQLException("passwordCallback Error", e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new SQLException("passwordCallback Error", e);
|
||||
}
|
||||
|
||||
try {
|
||||
Method method = passwordCallback.getClass().getMethod("setProperties", Properties.class);
|
||||
method.invoke(passwordCallback, properties);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
// skip
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new SQLException("passwordCallback Error", e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new SQLException("passwordCallback Error", e);
|
||||
}
|
||||
if (passwordCallback instanceof DruidPasswordCallback) {
|
||||
DruidPasswordCallback druidPasswordCallback = (DruidPasswordCallback) passwordCallback;
|
||||
|
||||
char[] chars = passwordCallback.getPassword();
|
||||
if (chars != null) {
|
||||
password = new String(chars);
|
||||
} else {
|
||||
password = null;
|
||||
}
|
||||
} else {
|
||||
password = dataSource.getPassword();
|
||||
druidPasswordCallback.setUrl(url);
|
||||
druidPasswordCallback.setProperties(properties);
|
||||
}
|
||||
|
||||
this.info = new Properties(dataSource.getConnectProperties());
|
||||
@@ -1282,6 +1259,15 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
@Override
|
||||
public Connection createConnection() throws SQLException {
|
||||
Connection conn;
|
||||
|
||||
PasswordCallback passwordCallback = dataSource.getPasswordCallback();
|
||||
if (passwordCallback != null) {
|
||||
char[] chars = passwordCallback.getPassword();
|
||||
if (chars != null) {
|
||||
String callbackPassword = new String(chars);
|
||||
info.put("password", callbackPassword);
|
||||
}
|
||||
}
|
||||
|
||||
long startNano = System.nanoTime();
|
||||
|
||||
@@ -1342,16 +1328,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
}
|
||||
|
||||
public CompositeDataSupport getCompositeData() throws JMException {
|
||||
StatFilter statFilter = null;
|
||||
JdbcDataSourceStat stat = null;
|
||||
for (Filter filter : this.getProxyFilters()) {
|
||||
if (filter instanceof StatFilter) {
|
||||
statFilter = (StatFilter) filter;
|
||||
}
|
||||
}
|
||||
if (statFilter != null) {
|
||||
stat = statFilter.getDataSourceStat();
|
||||
}
|
||||
JdbcDataSourceStat stat = this.getDataSourceStat();
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
|
||||
@@ -257,8 +257,12 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
|
||||
initStackTrace = IOUtils.toString(Thread.currentThread().getStackTrace());
|
||||
|
||||
|
||||
this.id = DruidDriver.createDataSourceId();
|
||||
|
||||
for (Filter filter : filters) {
|
||||
filter.init(this);
|
||||
}
|
||||
|
||||
if (maxActive <= 0) {
|
||||
throw new IllegalArgumentException("illegal maxActive " + maxActive);
|
||||
@@ -387,10 +391,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
}
|
||||
}
|
||||
|
||||
for (Filter filter : filters) {
|
||||
filter.init(this);
|
||||
}
|
||||
|
||||
initConnectionFactory();
|
||||
|
||||
connections = new ConnectionHolder[maxActive];
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
*/
|
||||
package com.alibaba.druid.pool;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -31,7 +30,6 @@ import javax.naming.Reference;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
||||
public class DruidDataSourceFactory implements ObjectFactory {
|
||||
|
||||
static final int UNKNOWN_TRANSACTIONISOLATION = -1;
|
||||
@@ -109,15 +107,15 @@ public class DruidDataSourceFactory implements ObjectFactory {
|
||||
return createDataSource(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and configures a {@link BasicDataSource} instance based on the given properties.
|
||||
*
|
||||
* @param properties the datasource configuration properties
|
||||
* @throws Exception if an error occurs creating the data source
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static DataSource createDataSource(Map properties) throws Exception {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
config(dataSource, properties);
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "deprecation", "rawtypes" })
|
||||
public static void config(DruidDataSource dataSource, Map properties) throws SQLException {
|
||||
String value = null;
|
||||
|
||||
value = (String) properties.get(PROP_DEFAULTAUTOCOMMIT);
|
||||
@@ -299,37 +297,12 @@ public class DruidDataSourceFactory implements ObjectFactory {
|
||||
|
||||
value = (String) properties.get(PROP_CONNECTIONPROPERTIES);
|
||||
if (value != null) {
|
||||
Properties p = getProperties(value);
|
||||
Enumeration<?> e = p.propertyNames();
|
||||
while (e.hasMoreElements()) {
|
||||
String propertyName = (String) e.nextElement();
|
||||
dataSource.addConnectionProperty(propertyName, p.getProperty(propertyName));
|
||||
}
|
||||
dataSource.setConnectionProperties(value);
|
||||
}
|
||||
|
||||
|
||||
value = (String) properties.get(PROP_INIT);
|
||||
if ("true".equals(value)) {
|
||||
dataSource.init();
|
||||
}
|
||||
|
||||
// Return the configured DataSource instance
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Parse properties from the string. Format of the string must be [propertyName=property;]*
|
||||
* <p>
|
||||
*
|
||||
* @param propText
|
||||
* @return Properties
|
||||
* @throws Exception
|
||||
*/
|
||||
static private Properties getProperties(String propText) throws Exception {
|
||||
Properties p = new Properties();
|
||||
if (propText != null) {
|
||||
p.load(new ByteArrayInputStream(propText.replace(';', '\n').getBytes()));
|
||||
}
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import javax.security.auth.callback.PasswordCallback;
|
||||
import com.alibaba.druid.filter.Filter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.filter.FilterChainImpl;
|
||||
import com.alibaba.druid.filter.stat.StatFilter;
|
||||
import com.alibaba.druid.stat.JdbcDataSourceStat;
|
||||
import com.alibaba.druid.stat.JdbcStatManager;
|
||||
import com.alibaba.druid.util.IOUtils;
|
||||
@@ -188,16 +187,7 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
}
|
||||
|
||||
public CompositeDataSupport getCompositeData() throws JMException {
|
||||
StatFilter statFilter = null;
|
||||
JdbcDataSourceStat stat = null;
|
||||
for (Filter filter : this.getProxyFilters()) {
|
||||
if (filter instanceof StatFilter) {
|
||||
statFilter = (StatFilter) filter;
|
||||
}
|
||||
}
|
||||
if (statFilter != null) {
|
||||
stat = statFilter.getDataSourceStat();
|
||||
}
|
||||
JdbcDataSourceStat stat = this.getDataSourceStat();
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
|
||||
@@ -69,6 +69,10 @@ public class JdbcConnectionStat implements JdbcConnectionStatMBean {
|
||||
private final Histogram histogram = new Histogram(TimeUnit.SECONDS, new long[] { //
|
||||
1, 5, 15, 60, 300, 1800 });
|
||||
|
||||
public JdbcConnectionStat(){
|
||||
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
connectingMax.set(0);
|
||||
connectErrorCount.set(0);
|
||||
|
||||
@@ -171,6 +171,10 @@ public class JdbcDataSourceStat implements JdbcDataSourceStatMBean {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public JdbcSqlStat getSqlStat(int id) {
|
||||
return getSqlStat((long) id);
|
||||
}
|
||||
|
||||
public JdbcSqlStat getSqlStat(long id) {
|
||||
lock.readLock().lock();
|
||||
|
||||
@@ -30,8 +30,6 @@ import javax.management.openmbean.TabularData;
|
||||
import javax.management.openmbean.TabularDataSupport;
|
||||
import javax.management.openmbean.TabularType;
|
||||
|
||||
import com.alibaba.druid.filter.Filter;
|
||||
import com.alibaba.druid.filter.stat.StatFilter;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.DruidDriver;
|
||||
import com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl;
|
||||
@@ -336,28 +334,18 @@ public class JdbcStatManager implements JdbcStatManagerMBean {
|
||||
|
||||
final ConcurrentMap<String, DataSourceProxyImpl> dataSources = DruidDriver.getProxyDataSources();
|
||||
for (DataSourceProxyImpl dataSource : dataSources.values()) {
|
||||
for (Filter filter : dataSource.getConfig().getFilters()) {
|
||||
if (filter instanceof StatFilter) {
|
||||
StatFilter countFilter = (StatFilter) filter;
|
||||
|
||||
ConcurrentMap<Long, JdbcConnectionStat.Entry> connections = countFilter.getConnections();
|
||||
for (Map.Entry<Long, JdbcConnectionStat.Entry> entry : connections.entrySet()) {
|
||||
data.put(entry.getValue().getCompositeData());
|
||||
}
|
||||
}
|
||||
JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();
|
||||
ConcurrentMap<Long, JdbcConnectionStat.Entry> connections = dataSourceStat.getConnections();
|
||||
for (Map.Entry<Long, JdbcConnectionStat.Entry> entry : connections.entrySet()) {
|
||||
data.put(entry.getValue().getCompositeData());
|
||||
}
|
||||
}
|
||||
|
||||
for (DruidDataSource instance : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
|
||||
for (Filter filter : instance.getProxyFilters()) {
|
||||
if (filter instanceof StatFilter) {
|
||||
StatFilter countFilter = (StatFilter) filter;
|
||||
|
||||
ConcurrentMap<Long, JdbcConnectionStat.Entry> connections = countFilter.getConnections();
|
||||
for (Map.Entry<Long, JdbcConnectionStat.Entry> entry : connections.entrySet()) {
|
||||
data.put(entry.getValue().getCompositeData());
|
||||
}
|
||||
}
|
||||
JdbcDataSourceStat dataSourceStat = instance.getDataSourceStat();
|
||||
ConcurrentMap<Long, JdbcConnectionStat.Entry> connections = dataSourceStat.getConnections();
|
||||
for (Map.Entry<Long, JdbcConnectionStat.Entry> entry : connections.entrySet()) {
|
||||
data.put(entry.getValue().getCompositeData());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,21 +362,11 @@ public class JdbcStatManager implements JdbcStatManagerMBean {
|
||||
|
||||
final ConcurrentMap<String, DataSourceProxyImpl> dataSources = DruidDriver.getProxyDataSources();
|
||||
for (DataSourceProxyImpl dataSource : dataSources.values()) {
|
||||
for (Filter filter : dataSource.getConfig().getFilters()) {
|
||||
if (filter instanceof StatFilter) {
|
||||
StatFilter countFilter = (StatFilter) filter;
|
||||
countFilter.reset();
|
||||
}
|
||||
}
|
||||
dataSource.getDataSourceStat().reset();
|
||||
}
|
||||
|
||||
for (DruidDataSource instance : DruidDataSourceStatManager.getDruidDataSourceInstances()) {
|
||||
for (Filter filter : instance.getProxyFilters()) {
|
||||
if (filter instanceof StatFilter) {
|
||||
StatFilter countFilter = (StatFilter) filter;
|
||||
countFilter.reset();
|
||||
}
|
||||
}
|
||||
instance.getDataSourceStat().reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.alibaba.druid.util;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.security.auth.callback.PasswordCallback;
|
||||
|
||||
public class DruidPasswordCallback extends PasswordCallback {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String url;
|
||||
|
||||
private Properties properties;
|
||||
|
||||
public DruidPasswordCallback(){
|
||||
this("druidDataSouce password", false);
|
||||
}
|
||||
|
||||
public DruidPasswordCallback(String prompt, boolean echoOn){
|
||||
super(prompt, echoOn);
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public Properties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(Properties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,7 +39,6 @@ public class WallFilter extends FilterAdapter implements WallFilterMBean {
|
||||
|
||||
@Override
|
||||
public void init(DataSourceProxy dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
|
||||
if (this.dbType == null || this.dbType.trim().length() == 0) {
|
||||
this.dbType = dataSource.getDbType();
|
||||
|
||||
@@ -3,13 +3,12 @@ package com.alibaba.druid.bvt.pool;
|
||||
import java.sql.Connection;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.security.auth.callback.PasswordCallback;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
import com.alibaba.druid.util.DruidPasswordCallback;
|
||||
|
||||
public class PasswordCallbackTest extends TestCase {
|
||||
|
||||
@@ -37,11 +36,10 @@ public class PasswordCallbackTest extends TestCase {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public static class TestPasswordCallback extends PasswordCallback {
|
||||
public static class TestPasswordCallback extends DruidPasswordCallback {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String url;
|
||||
private Properties properties;
|
||||
|
||||
public TestPasswordCallback(){
|
||||
@@ -52,14 +50,6 @@ public class PasswordCallbackTest extends TestCase {
|
||||
super(prompt, echoOn);
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public Properties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig;
|
||||
import com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.stat.JdbcDataSourceStat;
|
||||
|
||||
public class CounterFilterTest extends TestCase {
|
||||
|
||||
@@ -41,16 +42,19 @@ public class CounterFilterTest extends TestCase {
|
||||
DataSourceProxyConfig config = new DataSourceProxyConfig();
|
||||
config.setUrl("");
|
||||
|
||||
DataSourceProxyImpl dataSource = new DataSourceProxyImpl(null, config);
|
||||
JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();
|
||||
|
||||
StatFilter filter = new StatFilter();
|
||||
filter.init(new DataSourceProxyImpl(null, config));
|
||||
filter.init(dataSource);
|
||||
|
||||
filter.reset();
|
||||
dataSourceStat.reset();
|
||||
|
||||
Assert.assertNull(StatFilter.getStatFilter(new DataSourceProxyImpl(null, config)));
|
||||
Assert.assertNull(filter.getSqlStat(Integer.MAX_VALUE));
|
||||
Assert.assertNull(filter.getConnectionConnectLastTime());
|
||||
Assert.assertNull(StatFilter.getStatFilter(dataSource));
|
||||
Assert.assertNull(dataSourceStat.getSqlStat(Integer.MAX_VALUE));
|
||||
Assert.assertNull(dataSourceStat.getConnectionStat().getConnectLastTime());
|
||||
|
||||
FilterChain chain = new FilterChainImpl(new DataSourceProxyImpl(null, config)) {
|
||||
FilterChain chain = new FilterChainImpl(dataSource) {
|
||||
|
||||
public ConnectionProxy connection_connect(Properties info) throws SQLException {
|
||||
throw new SQLException();
|
||||
@@ -64,8 +68,8 @@ public class CounterFilterTest extends TestCase {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
Assert.assertEquals(1, filter.getConnectionConnectErrorCount());
|
||||
Assert.assertNotNull(filter.getConnectionConnectLastTime());
|
||||
Assert.assertEquals(1, dataSourceStat.getConnectionStat().getConnectErrorCount());
|
||||
Assert.assertNotNull(dataSourceStat.getConnectionStat().getConnectLastTime());
|
||||
}
|
||||
|
||||
public void test_count_filter() throws Exception {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class StatFilterConcurrentTest extends TestCase {
|
||||
|
||||
public void test_stat() throws Exception {
|
||||
concurrent(100);
|
||||
for (JdbcSqlStat sqlStat : statFilter.getDataSourceStat().getSqlStatMap().values()) {
|
||||
for (JdbcSqlStat sqlStat : dataSource.getDataSourceStat().getSqlStatMap().values()) {
|
||||
System.out.println(sqlStat.getConcurrentMax());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user