mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed pooledStatementStat
This commit is contained in:
@@ -469,7 +469,7 @@ public class PreparedStatementProxyImpl extends StatementProxyImpl implements Pr
|
||||
|
||||
public JdbcSqlStat getSqlStat() {
|
||||
if (sqlStat != null && sqlStat.isRemoved()) {
|
||||
JdbcSqlStat sqlStat = this.getConnectionProxy().getDirectDataSource().getDataSourceStat().getSqlStat(sql);
|
||||
JdbcSqlStat sqlStat = this.getConnectionProxy().getDirectDataSource().getDataSourceStat().createSqlStat(sql);
|
||||
sqlStat.setDbType(this.sqlStat.getDbType());
|
||||
this.sqlStat = sqlStat;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.stat.JdbcSqlStat;
|
||||
import com.alibaba.druid.stat.JdbcStatManager;
|
||||
import com.alibaba.druid.util.Histogram;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
@@ -21,6 +22,8 @@ public class StatFilterResultSetMultiCloseTest extends TestCase {
|
||||
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.setPoolPreparedStatements(true);
|
||||
dataSource.setMaxOpenPreparedStatements(100);
|
||||
|
||||
dataSource.init();
|
||||
}
|
||||
@@ -38,27 +41,48 @@ public class StatFilterResultSetMultiCloseTest extends TestCase {
|
||||
|
||||
Assert.assertNull(sqlStat);
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.close();
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.close();
|
||||
sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
Assert.assertNotNull(sqlStat);
|
||||
|
||||
sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
|
||||
Assert.assertNotNull(sqlStat);
|
||||
Histogram histogram = sqlStat.getExecuteAndResultHoldTimeHistogram();
|
||||
Assert.assertEquals("first failed", 1,
|
||||
histogram.getValue(0) + histogram.getValue(1) + histogram.getValue(2));
|
||||
|
||||
Histogram histogram = sqlStat.getExecuteAndResultHoldTimeHistogram();
|
||||
Assert.assertEquals("first failed", 1, histogram.getValue(0) + histogram.getValue(1));
|
||||
|
||||
rs.close();
|
||||
|
||||
Assert.assertEquals("second failed", 1, histogram.getValue(0) + histogram.getValue(1));
|
||||
rs.close();
|
||||
|
||||
stmt.close();
|
||||
Assert.assertEquals("second failed", 1,
|
||||
histogram.getValue(0) + histogram.getValue(1) + histogram.getValue(2));
|
||||
|
||||
conn.close();
|
||||
stmt.close();
|
||||
|
||||
Assert.assertEquals(1, histogram.getValue(1));
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(1, histogram.getValue(1));
|
||||
}
|
||||
|
||||
JdbcStatManager.getInstance().reset();
|
||||
|
||||
Assert.assertFalse(sqlStat.isRemoved());
|
||||
|
||||
JdbcStatManager.getInstance().reset();
|
||||
Assert.assertTrue(sqlStat.isRemoved());
|
||||
|
||||
{
|
||||
Connection conn = dataSource.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
rs.next();
|
||||
rs.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
Assert.assertNotSame(sqlStat, dataSource.getDataSourceStat().getSqlStat(sql));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user