This commit is contained in:
温少
2012-03-02 11:13:02 +08:00
parent 669408e30e
commit 9d9ceb37a3
120 changed files with 311 additions and 144 deletions
@@ -213,7 +213,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
TransactionInfo transInfo = (TransactionInfo) attributes.remove(ATTR_TRANSACTION);
if (transInfo != null) {
transInfo.setEndTimeMillis(System.currentTimeMillis());
transInfo.setEndTimeMillis();
}
}
@@ -382,6 +382,15 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
if (sqlStat != null) {
sqlStat.setExecuteLastStartTime(System.currentTimeMillis());
sqlStat.incrementRunningCount();
try {
boolean inTransaction = !statement.getConnectionProxy().getAutoCommit();
if (inTransaction) {
sqlStat.incrementInTransactionCount();
}
} catch (SQLException e) {
LOG.error("getAutoCommit error", e);
}
}
statement.getAttributes().put(ATTR_UPDATE_COUNT, 0);
@@ -487,7 +496,7 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
String sql = resultSet.getSql();
if (sql != null) {
JdbcSqlStat sqlStat = getSqlCounter(sql);
JdbcSqlStat sqlStat = getSqlCounter(sql);
if (sqlStat != null) {
sqlStat.addFetchRowCount(fetchCount);
}
@@ -590,12 +590,12 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
holder.setUnderlyingAutoCommit(autoCommit);
} catch (SQLException ex) {
if ((!autoCommit) && holder.isUnderlyingAutoCommit()) {
}
handleException(ex);
}
}
protected void transactionRecord(String sql) throws SQLException {
if (transactionInfo == null && (!conn.getAutoCommit())) {
DruidAbstractDataSource dataSource = holder.getDataSource();
@@ -684,10 +684,9 @@ public class DruidPooledConnection implements javax.sql.PooledConnection, Connec
private void handleEndTransaction(DruidAbstractDataSource dataSource) {
if (transactionInfo != null) {
long currentTimeMillis = System.currentTimeMillis();
transactionInfo.setEndTimeMillis(currentTimeMillis);
transactionInfo.setEndTimeMillis();
long transactionMillis = currentTimeMillis - transactionInfo.getStartTimeMillis();
long transactionMillis = transactionInfo.getEndTimeMillis() - transactionInfo.getStartTimeMillis();
dataSource.getTransactionHistogram().recode(transactionMillis);
dataSource.logTransaction(transactionInfo);
@@ -64,10 +64,12 @@ public class MySqlStatementParser extends SQLStatementParser {
public MySqlStatementParser(String sql) throws ParserException{
this(new MySqlLexer(sql));
this.lexer.nextToken();
this.exprParser = this.createExprParser();
}
public MySqlStatementParser(Lexer lexer){
super(lexer);
this.exprParser = this.createExprParser();
}
protected SQLExprParser createExprParser() {
@@ -37,7 +37,6 @@ import com.alibaba.druid.sql.ast.statement.SQLTableSource;
import com.alibaba.druid.sql.ast.statement.SQLTruncateStatement;
import com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem;
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
import com.alibaba.druid.sql.dialect.oracle.parser.OracleSelectParser;
public class SQLStatementParser extends SQLParser {
@@ -307,7 +306,7 @@ public class SQLStatementParser extends SQLParser {
}
public SQLSelectParser createSQLSelectParser() {
return new OracleSelectParser(this.lexer);
return new SQLSelectParser(this.lexer);
}
public SQLUpdateStatement parseUpdateStatement() throws ParserException {
@@ -62,6 +62,8 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
private final AtomicLong updateCount = new AtomicLong();
private final AtomicLong fetchRowCount = new AtomicLong();
private final AtomicLong inTransactionCount = new AtomicLong();
private final Histogram histogram = new Histogram(new long[] { //
//
4, 15, 60, 250, //
@@ -164,6 +166,7 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
fetchRowCount.set(0);
histogram.reset();
inTransactionCount.set(0);
}
public long getConcurrentMax() {
@@ -319,6 +322,14 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
return executeBatchSizeMax.get();
}
public long getInTransactionCount() {
return inTransactionCount.get();
}
public void incrementInTransactionCount() {
inTransactionCount.incrementAndGet();
}
private static CompositeType COMPOSITE_TYPE = null;
public static CompositeType getCompositeType() throws JMException {
@@ -327,20 +338,31 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
return COMPOSITE_TYPE;
}
OpenType<?>[] indexTypes = new OpenType<?>[] { SimpleType.LONG, SimpleType.STRING, SimpleType.STRING,
SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.DATE, SimpleType.LONG,
JMXUtils.getThrowableCompositeType(), SimpleType.LONG, SimpleType.LONG, SimpleType.DATE,
SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.STRING,
SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.DATE,
SimpleType.STRING, SimpleType.STRING //
OpenType<?>[] indexTypes = new OpenType<?>[] {
//
SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG,
SimpleType.LONG, //
, new ArrayType<Long>(SimpleType.LONG, true) };
SimpleType.LONG, SimpleType.DATE, SimpleType.LONG, JMXUtils.getThrowableCompositeType(),
SimpleType.LONG,
//
SimpleType.LONG, SimpleType.DATE, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
//
SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING,
//
SimpleType.STRING, SimpleType.DATE, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG //
, new ArrayType<Long>(SimpleType.LONG, true)
};
String[] indexNames = { "ID", "DataSource", "SQL", "ExecuteCount", "ErrorCount" //
, "TotalTime", "LastTime", "MaxTimespan", "LastError", "EffectedRowCount" //
, "FetchRowCount", "MaxTimespanOccurTime", "BatchSizeMax", "BatchSizeTotal", "ConcurrentMax" //
, "RunningCount", "Name", "File", "LastErrorMessage", "LastErrorClass" //
, "LastErrorStackTrace", "LastErrorTime", "DbType", "URL" //
, "LastErrorStackTrace", "LastErrorTime", "DbType", "InTransactionCount", "URL" //
, "Histogram" };
String[] indexDescriptions = indexNames;
@@ -394,6 +416,7 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
map.put("DbType", dbType);
map.put("URL", null);
map.put("InTransactionCount", getInTransactionCount());
map.put("Histogram", this.histogram.toArray());
@@ -45,6 +45,12 @@ public class TransactionInfo {
public long getEndTimeMillis() {
return endTimeMillis;
}
public void setEndTimeMillis() {
if (endTimeMillis == 0) {
endTimeMillis = System.currentTimeMillis();
}
}
public void setEndTimeMillis(long endTimeMillis) {
this.endTimeMillis = endTimeMillis;