Package com.alibaba.druid.stat

Examples of com.alibaba.druid.stat.JdbcSqlStat


        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", 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.getBlobOpenCount());

        sqlStat.reset();
        Assert.assertEquals(0, sqlStat.getBlobOpenCount());
    }
View Full Code Here


        stmt.close();

        conn.close();

        JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);

        Assert.assertEquals(1, sqlStat.getHistogramSum());


        Assert.assertEquals(1, sqlStat.getExecuteAndResultHoldTimeHistogramSum());
    }
View Full Code Here

        Connection conn = dataSource.getConnection();

        String sql = "select 'x'";
        PreparedStatement stmt = conn.prepareStatement("select 'x'");

        JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);

        Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());

        ResultSet rs = stmt.executeQuery();
        rs.next();
        rs.getBinaryStream(1);
        rs.getBinaryStream(2);
        rs.close();
        stmt.close();

        conn.close();

        Assert.assertEquals(2, sqlStat.getInputStreamOpenCount());

        sqlStat.reset();
        Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());
    }
View Full Code Here

        Connection conn = dataSource.getConnection();

        String sql = "select 'x'";
        PreparedStatement stmt = conn.prepareStatement("select 'x'");

        JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);

        Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());

        ResultSet rs = stmt.executeQuery();
        rs.next();
        rs.getBinaryStream("1");
        rs.getBinaryStream("2");
        rs.getBinaryStream("3");
        rs.close();
        stmt.close();

        conn.close();

        Assert.assertEquals(3, sqlStat.getInputStreamOpenCount());

        sqlStat.reset();
        Assert.assertEquals(0, sqlStat.getInputStreamOpenCount());
    }
View Full Code Here

        Connection conn = dataSource.getConnection();

        String sql = "select 'x'";
        PreparedStatement stmt = conn.prepareStatement("select 'x'");

        JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);

        Assert.assertEquals(0, sqlStat.getReadStringLength());

        ResultSet rs = stmt.executeQuery();
        rs.next();
        rs.getString(1);
        rs.close();
        stmt.close();

        conn.close();

        Assert.assertEquals(6, sqlStat.getReadStringLength());

        sqlStat.reset();
        Assert.assertEquals(0, sqlStat.getReadStringLength());
    }
View Full Code Here

        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.getBlob(1);
        rs.getBlob(2);
        rs.close();
        stmt.close();

        conn.close();

        Assert.assertEquals(2, sqlStat.getBlobOpenCount());

        sqlStat.reset();
        Assert.assertEquals(0, sqlStat.getBlobOpenCount());
    }
View Full Code Here

        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.getBlob("1");
        rs.getBlob("2");
        rs.getBlob("3");
        rs.close();
        stmt.close();

        conn.close();

        Assert.assertEquals(3, sqlStat.getBlobOpenCount());

        sqlStat.reset();
        Assert.assertEquals(0, sqlStat.getBlobOpenCount());
    }
View Full Code Here

        Connection conn = dataSource.getConnection();

        String sql = "select 'x'";
        PreparedStatement stmt = conn.prepareStatement("select 'x'");

        JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);

        Assert.assertEquals(0, sqlStat.getReadStringLength());

        ResultSet rs = stmt.executeQuery();
        rs.next();
        rs.getString("1");
        rs.close();
        stmt.close();

        conn.close();

        Assert.assertEquals(7, sqlStat.getReadStringLength());

        sqlStat.reset();
        Assert.assertEquals(0, sqlStat.getReadStringLength());
    }
View Full Code Here

        stmt.close();

        conn.close();

        JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);

        Assert.assertEquals(1, sqlStat.getHistogramSum());

        Assert.assertEquals(1, sqlStat.getExecuteAndResultHoldTimeHistogramSum());
    }
View Full Code Here

            conn.close();

            // //////

            JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
            Assert.assertNotNull(sqlStat);

            String slowParameters = sqlStat.getLastSlowParameters();
            Assert.assertNotNull(slowParameters);

            List<Object> parameters = (List<Object>) JSONUtils.parse(slowParameters);
            Assert.assertEquals(5, parameters.size());

            Assert.assertEquals(true, parameters.get(0));
            Assert.assertEquals(123, parameters.get(1));
            Assert.assertEquals(10001, parameters.get(2));
            Assert.assertEquals(dateText, parameters.get(3));
            Assert.assertEquals(dateText, parameters.get(4));
        }

        currentMillis = System.currentTimeMillis();
        date = new Date(System.currentTimeMillis());
        dateText = dateFormat.format(date);
        {
            Connection conn = dataSource.getConnection();

            PreparedStatement stmt = conn.prepareStatement(sql);

            stmt.setBoolean(1, false);
            stmt.setInt(2, 234);
            stmt.setLong(3, 10002);
            stmt.setTimestamp(4, new java.sql.Timestamp(currentMillis));
            stmt.setDate(5, new java.sql.Date(currentMillis));

            ResultSet rs = stmt.executeQuery();
            rs.close();

            stmt.close();

            conn.close();

            // //////

            JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
            Assert.assertNotNull(sqlStat);

            String slowParameters = sqlStat.getLastSlowParameters();
            Assert.assertNotNull(slowParameters);

            List<Object> parameters = (List<Object>) JSONUtils.parse(slowParameters);
            Assert.assertEquals(5, parameters.size());

            Assert.assertEquals(false, parameters.get(0));
            Assert.assertEquals(234, parameters.get(1));
            Assert.assertEquals(10002, parameters.get(2));
            Assert.assertEquals(dateText, parameters.get(3));
            Assert.assertEquals(dateText, parameters.get(4));
        }

        {
            StringBuilder buf = new StringBuilder();
            for (int i = 0; i < 10; ++i) {
                buf.append("abcdefghijklmnABCDEFGHIJKLMN1234567890!@#$%^&*(");
            }

            Connection conn = dataSource.getConnection();

            PreparedStatement stmt = conn.prepareStatement(sql);

            stmt.setNull(1, Types.VARCHAR);
            stmt.setString(2, buf.toString());
            stmt.setClob(3, new MockClob());
            stmt.setNClob(4, new MockNClob());
            stmt.setBlob(5, new MockBlob());

            ResultSet rs = stmt.executeQuery();
            rs.close();

            stmt.close();

            conn.close();

            // //////

            JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
            Assert.assertNotNull(sqlStat);

            String slowParameters = sqlStat.getLastSlowParameters();
            Assert.assertNotNull(slowParameters);

            List<Object> parameters = (List<Object>) JSONUtils.parse(slowParameters);
            Assert.assertEquals(5, parameters.size());

            Assert.assertEquals(null, parameters.get(0));
            Assert.assertEquals(buf.substring(0, 97) + "...", parameters.get(1));
            Assert.assertEquals("<Clob>", parameters.get(2));
            Assert.assertEquals("<NClob>", parameters.get(3));
            Assert.assertEquals("<Blob>", parameters.get(4));
        }
        {
            StringBuilder buf = new StringBuilder();
            for (int i = 0; i < 10; ++i) {
                buf.append("中国abcdefghijklmnABCDEFGHIJKLMN1234567890!@#$%^&*(");
            }
           
            Connection conn = dataSource.getConnection();
           
            PreparedStatement stmt = conn.prepareStatement(sql);
           
            stmt.setBinaryStream(1, new ByteInputStream(new byte[0]));
            stmt.setString(2, buf.toString());
            stmt.setTime(3, new Time(currentMillis));
            stmt.setBigDecimal(4, new BigDecimal("56789.123"));
            stmt.setRowId(5, new MockRowId());
           
            ResultSet rs = stmt.executeQuery();
            rs.close();
           
            stmt.close();
           
            conn.close();
           
            // //////
           
            JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
            Assert.assertNotNull(sqlStat);
           
            String slowParameters = sqlStat.getLastSlowParameters();
            Assert.assertNotNull(slowParameters);
           
            List<Object> parameters = (List<Object>) JSONUtils.parse(slowParameters);
            Assert.assertEquals(5, parameters.size());
           
View Full Code Here

TOP

Related Classes of com.alibaba.druid.stat.JdbcSqlStat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.