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.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());
    }
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.getClobOpenCount());

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

        conn.close();

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

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

    public void test_stat() throws Exception {

        final String sql = "SELECT 1";
        Assert.assertTrue(dataSource.isInited());

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

        Assert.assertNull(sqlStat);

        {
            Connection conn = dataSource.getConnection();
            PreparedStatement stmt = conn.prepareStatement(sql);
            ResultSet rs = stmt.executeQuery();
            rs.next();
            rs.close();

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

            Assert.assertEquals("first failed", 1, sqlStat.getExecuteAndResultHoldTimeHistogramSum());

            rs.close();

            Assert.assertEquals("second failed", 1, sqlStat.getExecuteAndResultHoldTimeHistogramSum());

            stmt.close();

            conn.close();

            Assert.assertEquals(1, sqlStat.getExecuteAndResultHoldTimeHistogramSum());
        }

        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));

        {
            Assert.assertEquals(0, sqlStat.getExecuteAndResultHoldTimeHistogramSum());
        }

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

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

        conn.close();

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

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

        stmt.close();

        conn.close();
       
        JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
        Assert.assertNotNull(sqlStat);
       
        Assert.assertEquals(1, sqlStat.getClobOpenCount());
        sqlStat.reset();
        Assert.assertEquals(0, sqlStat.getClobOpenCount());
    }
View Full Code Here

    @Override
    public void statementPrepareCallAfter(CallableStatementProxy statement) {
        JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
        dataSourceStat.getStatementStat().incrementPrepareCallCount();

        JdbcSqlStat sqlStat = createSqlStat(statement, statement.getSql());
        statement.setSqlStat(sqlStat);
    }
View Full Code Here

    @Override
    public void statementPrepareAfter(PreparedStatementProxy statement) {
        JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
        dataSourceStat.getStatementStat().incrementPrepareCounter();
        JdbcSqlStat sqlStat = createSqlStat(statement, statement.getSql());
        statement.setSqlStat(sqlStat);
    }
View Full Code Here

    @Override
    protected void statementExecuteBatchBefore(StatementProxy statement) {
        final String sql = statement.getBatchSql();

        final int batchSize = statement.getBatchSqlList().size();
        JdbcSqlStat sqlStat = statement.getSqlStat();
        if (sqlStat == null || sqlStat.isRemoved()) {
            sqlStat = createSqlStat(statement, sql);
            statement.setSqlStat(sqlStat);
        }

        if (sqlStat != null) {
            sqlStat.addExecuteBatchCount(batchSize);
        }

        internalBeforeStatementExecute(statement, sql);

    }
View Full Code Here

            connectionCounter.setLastStatementStatckTrace(new Exception());
        }

        // //////////SQL

        JdbcSqlStat sqlStat = statement.getSqlStat();
        if (sqlStat == null || sqlStat.isRemoved()) {
            sqlStat = createSqlStat(statement, sql);
            statement.setSqlStat(sqlStat);
        }

        JdbcStatContext statContext = JdbcStatManager.getInstance().getStatContext();
        if (statContext != null) {
            sqlStat.setName(statContext.getName());
            sqlStat.setFile(statContext.getFile());
        }

        boolean inTransaction = false;
        try {
            inTransaction = !statement.getConnectionProxy().getAutoCommit();
        } catch (SQLException e) {
            LOG.error("getAutoCommit error", e);
        }

        if (sqlStat != null) {
            sqlStat.setExecuteLastStartTime(System.currentTimeMillis());
            sqlStat.incrementRunningCount();

            if (inTransaction) {
                sqlStat.incrementInTransactionCount();
            }
        }

        StatFilterContext.getInstance().executeBefore(sql, inTransaction);
       
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.