事务时间直方图

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@855 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-19 04:58:43 +00:00
parent dfdf2d747d
commit 1dd5fd7576
7 changed files with 59 additions and 16 deletions
@@ -36,8 +36,8 @@ public class PoolableCallableStatement extends PoolablePreparedStatement impleme
private CallableStatement stmt;
public PoolableCallableStatement(PoolableConnection conn, CallableStatement stmt, PreparedStatementKey key){
super(conn, stmt, key);
public PoolableCallableStatement(PoolableConnection conn, CallableStatement stmt, PreparedStatementKey key, String sql){
super(conn, stmt, key, sql);
this.stmt = stmt;
}
@@ -173,7 +173,7 @@ public class PoolableConnection implements PooledConnection, Connection {
holder.getDataSource().initStatement(stmt);
PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key);
PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql);
holder.addTrace(rtnVal);
@@ -208,7 +208,7 @@ public class PoolableConnection implements PooledConnection, Connection {
holder.getDataSource().initStatement(stmt);
PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key);
PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql);
holder.addTrace(rtnVal);
@@ -242,7 +242,7 @@ public class PoolableConnection implements PooledConnection, Connection {
holder.getDataSource().initStatement(stmt);
PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key);
PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql);
holder.addTrace(rtnVal);
@@ -274,7 +274,7 @@ public class PoolableConnection implements PooledConnection, Connection {
holder.getDataSource().initStatement(stmt);
PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key);
PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql);
holder.addTrace(rtnVal);
@@ -306,7 +306,7 @@ public class PoolableConnection implements PooledConnection, Connection {
holder.getDataSource().initStatement(stmt);
PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key);
PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql);
holder.addTrace(rtnVal);
@@ -338,7 +338,7 @@ public class PoolableConnection implements PooledConnection, Connection {
holder.getDataSource().initStatement(stmt);
PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key);
PreparedStatement rtnVal = new PoolablePreparedStatement(this, stmt, key, sql);
holder.addTrace(rtnVal);
@@ -373,7 +373,7 @@ public class PoolableConnection implements PooledConnection, Connection {
holder.getDataSource().initStatement(stmt);
CallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key);
CallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key, sql);
holder.addTrace(rtnVal);
@@ -406,7 +406,7 @@ public class PoolableConnection implements PooledConnection, Connection {
holder.getDataSource().initStatement(stmt);
CallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key);
CallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key, sql);
holder.addTrace(rtnVal);
@@ -439,7 +439,7 @@ public class PoolableConnection implements PooledConnection, Connection {
holder.getDataSource().initStatement(stmt);
CallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key);
CallableStatement rtnVal = new PoolableCallableStatement(this, stmt, key, sql);
holder.addTrace(rtnVal);
return rtnVal;
@@ -45,11 +45,18 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep
private PreparedStatement stmt;
private final PreparedStatementKey key;
private final String sql;
public PoolablePreparedStatement(PoolableConnection conn, PreparedStatement stmt, PreparedStatementKey key){
public PoolablePreparedStatement(PoolableConnection conn, PreparedStatement stmt, PreparedStatementKey key,
String sql){
super(conn, stmt);
this.stmt = stmt;
this.key = key;
this.sql = sql;
}
public String getSql() {
return sql;
}
public PreparedStatementKey getKey() {
@@ -84,6 +91,8 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep
@Override
public ResultSet executeQuery() throws SQLException {
checkOpen();
transactionRecord(sql);
try {
ResultSet rs = stmt.executeQuery();
@@ -100,6 +109,8 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep
@Override
public int executeUpdate() throws SQLException {
checkOpen();
transactionRecord(sql);
try {
return stmt.executeUpdate();
@@ -332,6 +343,8 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep
@Override
public boolean execute() throws SQLException {
checkOpen();
transactionRecord(sql);
try {
return stmt.execute();
@@ -350,6 +363,12 @@ public class PoolablePreparedStatement extends PoolableStatement implements Prep
throw checkException(t);
}
}
public int[] executeBatch() throws SQLException {
transactionRecord(sql);
return super.executeBatch();
}
@Override
public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
@@ -83,6 +83,8 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
@Override
public final ResultSet executeQuery(String sql) throws SQLException {
checkOpen();
transactionRecord(sql);
try {
ResultSet rs = stmt.executeQuery(sql);
@@ -96,9 +98,17 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
}
}
protected void transactionRecord(String sql) {
if (conn.getTransactionInfo() != null) {
conn.getTransactionInfo().getSqlList().add(sql);
}
}
@Override
public final int executeUpdate(String sql) throws SQLException {
checkOpen();
transactionRecord(sql);
try {
return stmt.executeUpdate(sql);
@@ -356,6 +366,8 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
@Override
public final void addBatch(String sql) throws SQLException {
checkOpen();
transactionRecord(sql);
try {
stmt.addBatch(sql);
@@ -376,7 +388,7 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
}
@Override
public final int[] executeBatch() throws SQLException {
public int[] executeBatch() throws SQLException {
checkOpen();
try {
@@ -424,6 +436,8 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
@Override
public final int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
checkOpen();
transactionRecord(sql);
try {
return stmt.executeUpdate(sql, autoGeneratedKeys);
@@ -435,6 +449,8 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
@Override
public final int executeUpdate(String sql, int columnIndexes[]) throws SQLException {
checkOpen();
transactionRecord(sql);
try {
return stmt.executeUpdate(sql, columnIndexes);
@@ -446,6 +462,8 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
@Override
public final int executeUpdate(String sql, String columnNames[]) throws SQLException {
checkOpen();
transactionRecord(sql);
try {
return stmt.executeUpdate(sql, columnNames);
@@ -457,6 +475,8 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
@Override
public final boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
checkOpen();
transactionRecord(sql);
try {
return stmt.execute(sql, autoGeneratedKeys);
@@ -468,6 +488,8 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
@Override
public final boolean execute(String sql, int columnIndexes[]) throws SQLException {
checkOpen();
transactionRecord(sql);
try {
return stmt.execute(sql, columnIndexes);
@@ -479,6 +501,8 @@ public class PoolableStatement extends PoolableWrapper implements Statement {
@Override
public final boolean execute(String sql, String columnNames[]) throws SQLException {
checkOpen();
transactionRecord(sql);
try {
return stmt.execute(sql, columnNames);
@@ -26,7 +26,7 @@ public class PoolableCallableStatementTest extends TestCase {
protected void setUp() throws Exception {
raw = new MockCallableStatement(null, null);
stmt = new PoolableCallableStatement(null, raw, null) {
stmt = new PoolableCallableStatement(null, raw, null, null) {
protected SQLException checkException(Throwable error) throws SQLException {
if (error instanceof SQLException) {
@@ -22,7 +22,7 @@ public class PoolablePreparedStatementTest extends TestCase {
protected void setUp() throws Exception {
raw = new MockPreparedStatement(null, null);
stmt = new PoolablePreparedStatement(null, raw, null) {
stmt = new PoolablePreparedStatement(null, raw, null, null) {
protected SQLException checkException(Throwable error) throws SQLException {
if (error instanceof SQLException) {
@@ -96,7 +96,7 @@ public class PreparedStatementKeyTest extends TestCase {
public void test_contains() throws Exception {
PreparedStatementKey k1 = new PreparedStatementKey("x1", "c1", MethodType.M1);
PreparedStatementPool pool = new PreparedStatementPool();
pool.put(new PoolablePreparedStatement(null, null, k1));
pool.put(new PoolablePreparedStatement(null, null, k1, null));
Assert.assertTrue(pool.get(k1) != null);
Assert.assertTrue(pool.get(k1) == null);
}