Search in sources :

Example 31 with JdbcSqlStat

use of com.alibaba.druid.stat.JdbcSqlStat in project druid by alibaba.

the class StatFilterExecuteTest method test_stat.

public void test_stat() throws Exception {
    Assert.assertTrue(dataSource.isInited());
    final String sql = "update x";
    Connection conn = dataSource.getConnection();
    PreparedStatement stmt = conn.prepareStatement(sql);
    Assert.assertEquals(0, dataSource.getDataSourceStat().getSqlStat(sql).getExecuteAndResultHoldTimeHistogramSum());
    boolean firstResult = stmt.execute();
    Assert.assertFalse(firstResult);
    stmt.close();
    conn.close();
    JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
    Assert.assertEquals(1, sqlStat.getHistogramSum());
    Assert.assertEquals(1, sqlStat.getExecuteAndResultHoldTimeHistogramSum());
}
Also used : JdbcSqlStat(com.alibaba.druid.stat.JdbcSqlStat) Connection(java.sql.Connection) MockConnection(com.alibaba.druid.mock.MockConnection) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) PreparedStatement(java.sql.PreparedStatement)

Example 32 with JdbcSqlStat

use of com.alibaba.druid.stat.JdbcSqlStat in project druid by alibaba.

the class StatFilterOpenBlobCountTest2 method test_stat_1.

public void test_stat_1() throws Exception {
    Connection conn = dataSource.getConnection();
    String sql = "select 'x'";
    PreparedStatement stmt = conn.prepareStatement("select 'x'");
    JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
    Assert.assertEquals(0, sqlStat.getBlobOpenCount());
    ResultSet rs = stmt.executeQuery();
    rs.next();
    rs.getObject("1");
    rs.getObject("2");
    rs.getObject("3");
    rs.close();
    stmt.close();
    conn.close();
    Assert.assertEquals(3, sqlStat.getBlobOpenCount());
    sqlStat.reset();
    Assert.assertEquals(0, sqlStat.getBlobOpenCount());
}
Also used : JdbcSqlStat(com.alibaba.druid.stat.JdbcSqlStat) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 33 with JdbcSqlStat

use of com.alibaba.druid.stat.JdbcSqlStat in project druid by alibaba.

the class StatFilterOpenBlobCountTest2 method test_stat.

public void test_stat() throws Exception {
    Connection conn = dataSource.getConnection();
    String sql = "select 'x'";
    PreparedStatement stmt = conn.prepareStatement("select 'x'");
    JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
    Assert.assertEquals(0, sqlStat.getBlobOpenCount());
    ResultSet rs = stmt.executeQuery();
    rs.next();
    rs.getObject(1);
    rs.getObject(2);
    rs.close();
    stmt.close();
    conn.close();
    Assert.assertEquals(2, sqlStat.getBlobOpenCount());
    sqlStat.reset();
    Assert.assertEquals(0, sqlStat.getBlobOpenCount());
}
Also used : JdbcSqlStat(com.alibaba.druid.stat.JdbcSqlStat) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 34 with JdbcSqlStat

use of com.alibaba.druid.stat.JdbcSqlStat in project druid by alibaba.

the class StatFilterOpenClobCountTest method test_stat.

public void test_stat() throws Exception {
    Connection conn = dataSource.getConnection();
    String sql = "select 'x'";
    PreparedStatement stmt = conn.prepareStatement("select 'x'");
    JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
    Assert.assertEquals(0, sqlStat.getClobOpenCount());
    ResultSet rs = stmt.executeQuery();
    rs.next();
    rs.getClob(1);
    rs.getClob(2);
    rs.close();
    stmt.close();
    conn.close();
    Assert.assertEquals(2, sqlStat.getClobOpenCount());
    sqlStat.reset();
    Assert.assertEquals(0, sqlStat.getClobOpenCount());
}
Also used : JdbcSqlStat(com.alibaba.druid.stat.JdbcSqlStat) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 35 with JdbcSqlStat

use of com.alibaba.druid.stat.JdbcSqlStat in project druid by alibaba.

the class StatFilterOpenClobCountTest2 method test_stat_4.

public void test_stat_4() throws Exception {
    Connection conn = dataSource.getConnection();
    String sql = "select 'x'";
    PreparedStatement stmt = conn.prepareStatement("select 'x'");
    JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
    Assert.assertEquals(0, sqlStat.getClobOpenCount());
    ResultSet rs = stmt.executeQuery();
    rs.next();
    rs.getObject("1", Collections.<String, Class<?>>emptyMap());
    rs.getObject("2", Collections.<String, Class<?>>emptyMap());
    rs.getObject("3", Collections.<String, Class<?>>emptyMap());
    rs.getObject("4", Collections.<String, Class<?>>emptyMap());
    rs.getObject("5", Collections.<String, Class<?>>emptyMap());
    rs.close();
    stmt.close();
    conn.close();
    Assert.assertEquals(5, sqlStat.getClobOpenCount());
    sqlStat.reset();
    Assert.assertEquals(0, sqlStat.getClobOpenCount());
}
Also used : JdbcSqlStat(com.alibaba.druid.stat.JdbcSqlStat) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

JdbcSqlStat (com.alibaba.druid.stat.JdbcSqlStat)42 Connection (java.sql.Connection)31 PreparedStatement (java.sql.PreparedStatement)31 ResultSet (java.sql.ResultSet)29 JdbcDataSourceStat (com.alibaba.druid.stat.JdbcDataSourceStat)6 SQLException (java.sql.SQLException)3 Savepoint (java.sql.Savepoint)3 MockClob (com.alibaba.druid.mock.MockClob)2 MockConnection (com.alibaba.druid.mock.MockConnection)2 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)2 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)2 JdbcConnectionStat (com.alibaba.druid.stat.JdbcConnectionStat)2 MockBlob (com.alibaba.druid.mock.MockBlob)1 MockNClob (com.alibaba.druid.mock.MockNClob)1 MockRowId (com.alibaba.druid.mock.MockRowId)1 ClobProxy (com.alibaba.druid.proxy.jdbc.ClobProxy)1 JdbcStatContext (com.alibaba.druid.stat.JdbcStatContext)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1 Time (java.sql.Time)1