mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
format code
This commit is contained in:
@@ -301,6 +301,14 @@ public abstract class LogFilter extends FilterEventAdapter implements LogFilterM
|
||||
connectionLog("connect commited. id " + connection.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connection_setAutoCommit(FilterChain chain, ConnectionProxy connection, boolean autoCommit)
|
||||
throws SQLException {
|
||||
|
||||
connectionLog("connect setAutoComment " + autoCommit + ". id " + connection.getId());
|
||||
chain.connection_setAutoCommit(connection, autoCommit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connection_close(FilterChain chain, ConnectionProxy connection) throws SQLException {
|
||||
|
||||
@@ -488,9 +488,10 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
String sql = resultSet.getSql();
|
||||
if (sql != null) {
|
||||
JdbcSqlStat sqlStat = getSqlStat(sql);
|
||||
JdbcSqlStat sqlStat = resultSet.getSqlStat();
|
||||
if (sqlStat != null) {
|
||||
sqlStat.addFetchRowCount(fetchCount);
|
||||
sqlStat.addResultSetHoldTimeNano(nanoSpan);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ package com.alibaba.druid.proxy.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import com.alibaba.druid.stat.JdbcSqlStat;
|
||||
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
*/
|
||||
@@ -27,6 +29,8 @@ public interface ResultSetProxy extends ResultSet, WrapperProxy {
|
||||
StatementProxy getStatementProxy();
|
||||
|
||||
String getSql();
|
||||
|
||||
JdbcSqlStat getSqlStat();
|
||||
|
||||
int getCursorIndex();
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import java.util.Map;
|
||||
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.filter.FilterChainImpl;
|
||||
import com.alibaba.druid.stat.JdbcSqlStat;
|
||||
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
@@ -53,12 +54,14 @@ public class ResultSetProxyImpl extends WrapperProxyImpl implements ResultSetPro
|
||||
protected int cursorIndex = 0;
|
||||
protected int fetchRowCount = 0;
|
||||
protected long constructNano;
|
||||
protected final JdbcSqlStat sqlStat;
|
||||
|
||||
public ResultSetProxyImpl(StatementProxy statement, ResultSet resultSet, long id, String sql){
|
||||
super(resultSet, id);
|
||||
this.statement = statement;
|
||||
this.resultSet = resultSet;
|
||||
this.sql = sql;
|
||||
sqlStat = this.statement.getSqlStat();
|
||||
}
|
||||
|
||||
public long getConstructNano() {
|
||||
@@ -68,7 +71,7 @@ public class ResultSetProxyImpl extends WrapperProxyImpl implements ResultSetPro
|
||||
public void setConstructNano(long constructNano) {
|
||||
this.constructNano = constructNano;
|
||||
}
|
||||
|
||||
|
||||
public void setConstructNano() {
|
||||
if (this.constructNano <= 0) {
|
||||
this.constructNano = System.nanoTime();
|
||||
@@ -87,6 +90,10 @@ public class ResultSetProxyImpl extends WrapperProxyImpl implements ResultSetPro
|
||||
return sql;
|
||||
}
|
||||
|
||||
public JdbcSqlStat getSqlStat() {
|
||||
return sqlStat;
|
||||
}
|
||||
|
||||
public ResultSet getResultSetRaw() {
|
||||
return resultSet;
|
||||
}
|
||||
@@ -1061,7 +1068,7 @@ public class ResultSetProxyImpl extends WrapperProxyImpl implements ResultSetPro
|
||||
if (iface == ResultSet.class) {
|
||||
return (T) resultSet;
|
||||
}
|
||||
|
||||
|
||||
return super.unwrap(iface);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
|
||||
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
|
||||
if (dataSources.size() == 0) {
|
||||
try {
|
||||
|
||||
|
||||
ObjectName objectName = new ObjectName(MBEAN_NAME);
|
||||
if (!mbeanServer.isRegistered(objectName)) {
|
||||
mbeanServer.registerMBean(instance, objectName);
|
||||
@@ -98,9 +98,9 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
|
||||
|
||||
public synchronized static void remove(DruidDataSource dataSource) {
|
||||
ObjectName objectName = dataSources.remove(dataSource);
|
||||
|
||||
|
||||
if (objectName == null) {
|
||||
objectName = dataSource.getObjectName();
|
||||
objectName = dataSource.getObjectName();
|
||||
}
|
||||
|
||||
if (objectName == null) {
|
||||
@@ -164,54 +164,63 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
// 0 - 4
|
||||
map.put("Name", dataSource.getName());
|
||||
map.put("URL", dataSource.getUrl());
|
||||
map.put("CreateCount", dataSource.getCreateCount());
|
||||
map.put("DestroyCount", dataSource.getDestroyCount());
|
||||
map.put("ConnectCount", dataSource.getConnectCount());
|
||||
|
||||
// 5 - 9
|
||||
map.put("CloseCount", dataSource.getCloseCount());
|
||||
map.put("ActiveCount", dataSource.getActivePeak());
|
||||
map.put("PoolingCount", dataSource.getPoolingCount());
|
||||
map.put("LockQueueLength", dataSource.getLockQueueLength());
|
||||
map.put("WaitThreadCount", dataSource.getNotEmptyWaitThreadPeak());
|
||||
|
||||
// 10 - 14
|
||||
map.put("InitialSize", dataSource.getInitialSize());
|
||||
map.put("MaxActive", dataSource.getMaxActive());
|
||||
map.put("MinIdle", dataSource.getMinIdle());
|
||||
map.put("PoolPreparedStatements", dataSource.isPoolPreparedStatements());
|
||||
map.put("TestOnBorrow", dataSource.isTestOnBorrow());
|
||||
|
||||
// 15 - 19
|
||||
map.put("TestOnReturn", dataSource.isTestOnReturn());
|
||||
map.put("MinEvictableIdleTimeMillis", dataSource.getMinEvictableIdleTimeMillis());
|
||||
map.put("ConnectErrorCount", dataSource.getConnectErrorCount());
|
||||
map.put("CreateTimespanMillis", dataSource.getCreateTimespanMillis());
|
||||
map.put("DbType", dataSource.getDbType());
|
||||
|
||||
// 20 - 24
|
||||
map.put("ValidationQuery", dataSource.getValidationQuery());
|
||||
map.put("ValidationQueryTimeout", dataSource.getValidationQueryTimeout());
|
||||
map.put("DriverClassName", dataSource.getDriverClassName());
|
||||
map.put("Username", dataSource.getUsername());
|
||||
map.put("RemoveAbandonedCount", dataSource.getRemoveAbandonedCount());
|
||||
|
||||
// 25 - 29
|
||||
map.put("NotEmptyWaitCount", dataSource.getNotEmptyWaitCount());
|
||||
map.put("NotEmptyWaitNanos", dataSource.getNotEmptyWaitNanos());
|
||||
map.put("ErrorCount", dataSource.getErrorCount());
|
||||
map.put("ReusePreparedStatementCount", dataSource.getCachedPreparedStatementHitCount());
|
||||
map.put("StartTransactionCount", dataSource.getStartTransactionCount());
|
||||
|
||||
// 30 - 34
|
||||
map.put("CommitCount", dataSource.getCommitCount());
|
||||
map.put("RollbackCount", dataSource.getRollbackCount());
|
||||
map.put("LastError", JMXUtils.getErrorCompositeData(dataSource.getLastError()));
|
||||
map.put("LastCreateError", JMXUtils.getErrorCompositeData(dataSource.getLastCreateError()));
|
||||
map.put("PreparedStatementCacheDeleteCount", dataSource.getCachedPreparedStatementDeleteCount());
|
||||
|
||||
|
||||
// 35 - 39
|
||||
map.put("PreparedStatementCacheAccessCount", dataSource.getCachedPreparedStatementAccessCount());
|
||||
map.put("PreparedStatementCacheMissCount", dataSource.getCachedPreparedStatementMissCount());
|
||||
map.put("PreparedStatementCacheHitCount", dataSource.getCachedPreparedStatementHitCount());
|
||||
map.put("PreparedStatementCacheCurrentCount", dataSource.getCachedPreparedStatementCount());
|
||||
map.put("Version", dataSource.getVersion());
|
||||
|
||||
// 40 -
|
||||
map.put("LastErrorTime", dataSource.getLastErrorTime());
|
||||
map.put("LastCreateErrorTime", dataSource.getLastCreateErrorTime());
|
||||
map.put("CreateErrorCount", dataSource.getCreateErrorCount());
|
||||
@@ -228,36 +237,130 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
|
||||
}
|
||||
|
||||
OpenType<?>[] indexTypes = new OpenType<?>[] {
|
||||
//
|
||||
SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, //
|
||||
SimpleType.LONG, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, //
|
||||
SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.BOOLEAN, SimpleType.BOOLEAN, //
|
||||
SimpleType.BOOLEAN, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.STRING, //
|
||||
SimpleType.STRING, SimpleType.INTEGER, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, //
|
||||
SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG//
|
||||
, SimpleType.LONG, SimpleType.LONG, JMXUtils.getThrowableCompositeType(), JMXUtils.getThrowableCompositeType(), SimpleType.LONG //
|
||||
, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.STRING //
|
||||
, SimpleType.DATE , SimpleType.DATE, SimpleType.LONG
|
||||
// 0 - 4
|
||||
SimpleType.STRING, //
|
||||
SimpleType.STRING, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
|
||||
// 5 - 9
|
||||
SimpleType.LONG, //
|
||||
SimpleType.INTEGER, //
|
||||
SimpleType.INTEGER, //
|
||||
SimpleType.INTEGER, //
|
||||
SimpleType.INTEGER, //
|
||||
|
||||
// 10 - 14
|
||||
SimpleType.INTEGER, //
|
||||
SimpleType.INTEGER, //
|
||||
SimpleType.INTEGER, //
|
||||
SimpleType.BOOLEAN, //
|
||||
SimpleType.BOOLEAN, //
|
||||
|
||||
// 15 - 19
|
||||
SimpleType.BOOLEAN, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.STRING, //
|
||||
|
||||
// 20 - 24
|
||||
SimpleType.STRING, //
|
||||
SimpleType.INTEGER, //
|
||||
SimpleType.STRING, //
|
||||
SimpleType.STRING, //
|
||||
SimpleType.LONG, //
|
||||
|
||||
// 25 - 29
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
|
||||
// 30 - 34
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
JMXUtils.getThrowableCompositeType(), //
|
||||
JMXUtils.getThrowableCompositeType(), //
|
||||
SimpleType.LONG, //
|
||||
|
||||
// 35 - 39
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.STRING, //
|
||||
|
||||
// 40 -
|
||||
SimpleType.DATE, //
|
||||
SimpleType.DATE, //
|
||||
SimpleType.LONG //
|
||||
//
|
||||
};
|
||||
|
||||
String[] indexNames = {
|
||||
//
|
||||
"Name", "URL", "CreateCount", "DestroyCount",
|
||||
// 0 - 4
|
||||
"Name", //
|
||||
"URL", //
|
||||
"CreateCount", //
|
||||
"DestroyCount", //
|
||||
"ConnectCount", //
|
||||
"CloseCount", "ActiveCount", "PoolingCount", "LockQueueLength",
|
||||
|
||||
// 5 - 9
|
||||
"CloseCount", //
|
||||
"ActiveCount", //
|
||||
"PoolingCount", //
|
||||
"LockQueueLength", //
|
||||
"WaitThreadCount", //
|
||||
"InitialSize", "MaxActive", "MinIdle", "PoolPreparedStatements",
|
||||
|
||||
// 10 - 14
|
||||
"InitialSize", //
|
||||
"MaxActive", //
|
||||
"MinIdle", //
|
||||
"PoolPreparedStatements", //
|
||||
"TestOnBorrow", //
|
||||
"TestOnReturn", "MinEvictableIdleTimeMillis", "ConnectErrorCount", "CreateTimespanMillis",
|
||||
|
||||
// 15 - 19
|
||||
"TestOnReturn", //
|
||||
"MinEvictableIdleTimeMillis", //
|
||||
"ConnectErrorCount", //
|
||||
"CreateTimespanMillis", //
|
||||
"DbType", //
|
||||
"ValidationQuery", "ValidationQueryTimeout", "DriverClassName", "Username",
|
||||
|
||||
// 20 - 24
|
||||
"ValidationQuery", //
|
||||
"ValidationQueryTimeout", //
|
||||
"DriverClassName", //
|
||||
"Username", //
|
||||
"RemoveAbandonedCount", //
|
||||
"NotEmptyWaitCount", "NotEmptyWaitNanos", "ErrorCount", "ReusePreparedStatementCount",
|
||||
|
||||
// 25 - 29
|
||||
"NotEmptyWaitCount", //
|
||||
"NotEmptyWaitNanos", //
|
||||
"ErrorCount", //
|
||||
"ReusePreparedStatementCount", //
|
||||
"StartTransactionCount", //
|
||||
"CommitCount", "RollbackCount", "LastError", "LastCreateError", "PreparedStatementCacheDeleteCount" //
|
||||
, "PreparedStatementCacheAccessCount", "PreparedStatementCacheMissCount", "PreparedStatementCacheHitCount", "PreparedStatementCacheCurrentCount", "Version" //
|
||||
, "LastErrorTime", "LastCreateErrorTime", "CreateErrorCount"
|
||||
|
||||
// 30 - 34
|
||||
"CommitCount", //
|
||||
"RollbackCount", //
|
||||
"LastError", //
|
||||
"LastCreateError", //
|
||||
"PreparedStatementCacheDeleteCount", //
|
||||
|
||||
// 35 - 39
|
||||
"PreparedStatementCacheAccessCount", //
|
||||
"PreparedStatementCacheMissCount", //
|
||||
"PreparedStatementCacheHitCount", //
|
||||
"PreparedStatementCacheCurrentCount", //
|
||||
"Version" //
|
||||
|
||||
// 40 -
|
||||
, "LastErrorTime", //
|
||||
"LastCreateErrorTime", //
|
||||
"CreateErrorCount" //
|
||||
//
|
||||
};
|
||||
|
||||
|
||||
@@ -49,6 +49,8 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
private final AtomicLong executeSpanNanoMax = new AtomicLong();
|
||||
private final AtomicLong runningCount = new AtomicLong(0L);
|
||||
private final AtomicLong concurrentMax = new AtomicLong();
|
||||
private final AtomicLong resultSetHoldTimeNano = new AtomicLong();
|
||||
|
||||
private String name;
|
||||
private String file;
|
||||
private String dbType;
|
||||
@@ -180,6 +182,7 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
histogram.reset();
|
||||
this.lastSlowParameters = null;
|
||||
inTransactionCount.set(0);
|
||||
resultSetHoldTimeNano.set(0);
|
||||
}
|
||||
|
||||
public long getConcurrentMax() {
|
||||
@@ -393,6 +396,7 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
// 25 -
|
||||
new ArrayType<Long>(SimpleType.LONG, true), //
|
||||
SimpleType.STRING, //
|
||||
SimpleType.LONG, //
|
||||
};
|
||||
|
||||
String[] indexNames = {
|
||||
@@ -433,7 +437,8 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
|
||||
// 25 -
|
||||
"Histogram", //
|
||||
"LastSlowParameters"
|
||||
"LastSlowParameters",
|
||||
"ResultSetHoldTime"
|
||||
//
|
||||
};
|
||||
String[] indexDescriptions = indexNames;
|
||||
@@ -455,30 +460,33 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
map.put("SQL", sql);
|
||||
map.put("ExecuteCount", getExecuteCount());
|
||||
map.put("ErrorCount", getErrorCount());
|
||||
map.put("TotalTime", getExecuteMillisTotal());
|
||||
|
||||
// 5 - 9
|
||||
map.put("TotalTime", getExecuteMillisTotal());
|
||||
map.put("LastTime", getExecuteLastStartTime());
|
||||
map.put("MaxTimespan", getExecuteMillisMax());
|
||||
map.put("LastError", JMXUtils.getErrorCompositeData(this.getExecuteErrorLast()));
|
||||
map.put("EffectedRowCount", getUpdateCount());
|
||||
map.put("FetchRowCount", getFetchRowCount());
|
||||
|
||||
// 10 - 14
|
||||
map.put("FetchRowCount", getFetchRowCount());
|
||||
map.put("MaxTimespanOccurTime", getExecuteNanoSpanMaxOccurTime());
|
||||
map.put("BatchSizeMax", getExecuteBatchSizeMax());
|
||||
map.put("BatchSizeTotal", getExecuteBatchSizeTotal());
|
||||
map.put("ConcurrentMax", getConcurrentMax());
|
||||
map.put("RunningCount", getRunningCount());
|
||||
|
||||
map.put("Name", getName());
|
||||
map.put("File", getFile());
|
||||
// 15 -
|
||||
map.put("RunningCount", getRunningCount()); // 15
|
||||
map.put("Name", getName()); // 16
|
||||
map.put("File", getFile()); // 17
|
||||
|
||||
Throwable lastError = this.executeErrorLast;
|
||||
if (lastError != null) {
|
||||
map.put("LastErrorMessage", lastError.getMessage());
|
||||
map.put("LastErrorClass", lastError.getClass().getName());
|
||||
map.put("LastErrorMessage", lastError.getMessage()); // 18
|
||||
map.put("LastErrorClass", lastError.getClass().getName()); // 19
|
||||
|
||||
map.put("LastErrorStackTrace", IOUtils.getStackTrace(lastError));
|
||||
map.put("LastErrorTime", new Date(executeErrorLastTime));
|
||||
map.put("LastErrorStackTrace", IOUtils.getStackTrace(lastError)); // 20
|
||||
map.put("LastErrorTime", new Date(executeErrorLastTime)); // 21
|
||||
} else {
|
||||
map.put("LastErrorMessage", null);
|
||||
map.put("LastErrorClass", null);
|
||||
@@ -486,13 +494,13 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
map.put("LastErrorTime", null);
|
||||
}
|
||||
|
||||
map.put("DbType", dbType);
|
||||
map.put("URL", null);
|
||||
map.put("InTransactionCount", getInTransactionCount());
|
||||
map.put("DbType", dbType); // 22
|
||||
map.put("URL", null); // 23
|
||||
map.put("InTransactionCount", getInTransactionCount()); // 24
|
||||
|
||||
map.put("Histogram", this.histogram.toArray());
|
||||
|
||||
map.put("LastSlowParameters", lastSlowParameters);
|
||||
map.put("Histogram", this.histogram.toArray()); // 25
|
||||
map.put("LastSlowParameters", lastSlowParameters); // 26
|
||||
map.put("ResultSetHoldTime", getResultSetHoldTimeMilis()); // 26
|
||||
|
||||
return map;
|
||||
}
|
||||
@@ -511,4 +519,17 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
executeErrorLast = error;
|
||||
|
||||
}
|
||||
|
||||
public long getResultSetHoldTimeMilis() {
|
||||
return getResultSetHoldTimeNano() / (1000 * 1000);
|
||||
}
|
||||
|
||||
public long getResultSetHoldTimeNano() {
|
||||
return resultSetHoldTimeNano.get();
|
||||
}
|
||||
|
||||
public void addResultSetHoldTimeNano(long nano) {
|
||||
resultSetHoldTimeNano.addAndGet(nano);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user