添加ReusePreparedStatement计数

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@913 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-28 15:15:51 +00:00
parent 9dff400ff6
commit 7ce7234f64
5 changed files with 43 additions and 6 deletions
@@ -178,6 +178,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
protected final AtomicLong commitCount = new AtomicLong();
protected final AtomicLong startTransactionCount = new AtomicLong();
protected final AtomicLong rollbackCount = new AtomicLong();
protected final AtomicLong reusePreparedStatement = new AtomicLong();
protected final Histogram transactionHistogram = new Histogram(
10,
@@ -189,6 +190,14 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
public Histogram getTransactionHistogram() {
return transactionHistogram;
}
public void incrementPreparedStatementCount() {
reusePreparedStatement.incrementAndGet();
}
public long getReusePreparedStatement() {
return reusePreparedStatement.get();
}
public long getTransactionThresholdMillis() {
return transactionThresholdMillis;
@@ -203,7 +212,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
public long[] getTransactionHistogramValues() {
return transactionHistogram.toArray();
}
public long[] getTransactionHistogramRanges() {
return transactionHistogram.getRanges();
}
@@ -569,10 +578,6 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
}
public void setPoolPreparedStatements(boolean poolPreparedStatements) {
if (inited) {
throw new UnsupportedOperationException();
}
this.poolPreparedStatements = poolPreparedStatements;
}
@@ -117,4 +117,6 @@ public interface DruidAbstractDataSourceMBean {
void setTransactionThresholdMillis(long transactionThresholdMillis);
long getTransactionThresholdMillis();
long getReusePreparedStatement();
}
@@ -1157,6 +1157,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
@Override
public String getVersion() {
return VERSION.MajorVersion + "." + VERSION.MinorVersion + "." + VERSION.RevisionVersion + "-2011-09-11 17:31";
return VERSION.MajorVersion + "." + VERSION.MinorVersion + "." + VERSION.RevisionVersion + "-2011-09-28 22:44";
}
}
@@ -52,6 +52,8 @@ public interface DruidDataSourceMBean extends DruidAbstractDataSourceMBean {
void setResetStatEnable(boolean resetStatEnable);
String getVersion();
void setPoolPreparedStatements(boolean poolPreparedStatements);
/**
* ActiveCount峰值
@@ -42,6 +42,7 @@ import com.alibaba.druid.logging.Log;
import com.alibaba.druid.logging.LogFactory;
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
import com.alibaba.druid.util.JdbcUtils;
import com.alibaba.druid.util.TransactionInfo;
/**
@@ -103,6 +104,15 @@ public class PoolableConnection implements PooledConnection, Connection {
public Connection getConnection() {
return conn;
}
void closePoolableStatement() {
PreparedStatementPool statmentPool = holder.getStatementPool();
if (statmentPool != null) {
for (PreparedStatement stmt : statmentPool.getMap().values()) {
JdbcUtils.close(stmt);
}
}
}
void disable() {
this.holder = null;
@@ -155,6 +165,8 @@ public class PoolableConnection implements PooledConnection, Connection {
} catch (SQLException ex) {
handleException(ex);
}
} else {
holder.getDataSource().incrementPreparedStatementCount();
}
holder.getDataSource().initStatement(stmt);
@@ -185,6 +197,8 @@ public class PoolableConnection implements PooledConnection, Connection {
} catch (SQLException ex) {
handleException(ex);
}
} else {
holder.getDataSource().incrementPreparedStatementCount();
}
holder.getDataSource().initStatement(stmt);
@@ -215,6 +229,8 @@ public class PoolableConnection implements PooledConnection, Connection {
} catch (SQLException ex) {
handleException(ex);
}
} else {
holder.getDataSource().incrementPreparedStatementCount();
}
holder.getDataSource().initStatement(stmt);
@@ -243,6 +259,8 @@ public class PoolableConnection implements PooledConnection, Connection {
} catch (SQLException ex) {
handleException(ex);
}
} else {
holder.getDataSource().incrementPreparedStatementCount();
}
holder.getDataSource().initStatement(stmt);
@@ -271,6 +289,8 @@ public class PoolableConnection implements PooledConnection, Connection {
} catch (SQLException ex) {
handleException(ex);
}
} else {
holder.getDataSource().incrementPreparedStatementCount();
}
holder.getDataSource().initStatement(stmt);
@@ -299,6 +319,8 @@ public class PoolableConnection implements PooledConnection, Connection {
} catch (SQLException ex) {
handleException(ex);
}
} else {
holder.getDataSource().incrementPreparedStatementCount();
}
holder.getDataSource().initStatement(stmt);
@@ -330,6 +352,8 @@ public class PoolableConnection implements PooledConnection, Connection {
} catch (SQLException ex) {
handleException(ex);
}
} else {
holder.getDataSource().incrementPreparedStatementCount();
}
holder.getDataSource().initStatement(stmt);
@@ -359,6 +383,8 @@ public class PoolableConnection implements PooledConnection, Connection {
} catch (SQLException ex) {
handleException(ex);
}
} else {
holder.getDataSource().incrementPreparedStatementCount();
}
holder.getDataSource().initStatement(stmt);
@@ -387,6 +413,8 @@ public class PoolableConnection implements PooledConnection, Connection {
} catch (SQLException ex) {
handleException(ex);
}
} else {
holder.getDataSource().incrementPreparedStatementCount();
}
holder.getDataSource().initStatement(stmt);