Package com.alibaba.druid.stat

Examples of com.alibaba.druid.stat.JdbcSqlStat


    @Override
    public void statementPrepareAfter(PreparedStatementProxy statement) {
        statementStat.incrementPrepareCounter();
        dataSourceStat.getStatementStat().incrementPrepareCounter();
        JdbcSqlStat sqlStat = createSqlStat(statement, statement.getSql());
        statement.getAttributes().put(ATTR_SQL, sqlStat);

        // super.statementPrepareAfter(statement);
    }
View Full Code Here


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

        final int batchSize = statement.getBatchSqlList().size();
        JdbcSqlStat sqlStat = getSqlStat(statement);
        if (sqlStat == null) {
            sqlStat = createSqlStat(statement, sql);
            statement.getAttributes().put(ATTR_SQL, sqlStat);
        }

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

        internalBeforeStatementExecute(statement, sql);

        // super.statementExecuteBatchBefore(statement);
View Full Code Here

            connectionCounter.setLastStatementStatckTrace(new Exception());
        }

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

        JdbcSqlStat sqlStat = getSqlStat(statement);
        if (sqlStat == null) {
            sqlStat = createSqlStat(statement, sql);
            statement.getAttributes().put(ATTR_SQL, sqlStat);
        }

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

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

        statement.getAttributes().put(ATTR_UPDATE_COUNT, 0);
    }
View Full Code Here

        Integer attr = (Integer) statement.getAttributes().get(ATTR_UPDATE_COUNT);
        if (attr == null) {
            statement.getAttributes().put(ATTR_UPDATE_COUNT, updateCount);

            final JdbcSqlStat sqlStat = getSqlStat(statement);
            if (sqlStat != null) {
                sqlStat.addUpdateCount(updateCount);
            }
        }

        return updateCount;
    }
View Full Code Here

        statementStat.afterExecute(nanoSpan);
        dataSourceStat.getStatementStat().afterExecute(nanoSpan);

        // // SQL
        final JdbcSqlStat sqlStat = getSqlStat(statement);

        if (sqlStat != null) {
            sqlStat.incrementExecuteSuccessCount();
            for (int updateCount : updateCountArray) {
                sqlStat.addUpdateCount(updateCount);
            }

            sqlStat.decrementExecutingCount();
            sqlStat.addExecuteTime(nanoSpan);
        }

        if (updateCountArray.length == 1) {
            statement.getAttributes().put(ATTR_UPDATE_COUNT, updateCountArray[0]);
        }
View Full Code Here

        dataSourceStat.getStatementStat().afterExecute(nanoSpan);

        connectionCounter.error(error);

        // SQL
        JdbcSqlStat sqlStat = getSqlStat(statement);

        if (sqlStat != null) {
            sqlStat.error(error);
            sqlStat.addExecuteTime(nanoSpan);
        }

        super.statement_executeErrorAfter(statement, sql, error);
    }
View Full Code Here

        resultSetStat.incrementCloseCounter();
        dataSourceStat.getResultSetStat().incrementCloseCounter();

        String sql = resultSet.getSql();
        if (sql != null) {
            JdbcSqlStat sqlStat = dataSourceStat.getSqlStatMap().get(sql);
            if (sqlStat != null) {
                sqlStat.addFetchRowCount(fetchCount);
            }
        }

        super.resultSet_close(chain, resultSet);
    }
View Full Code Here

        return dataSource.getUrl();
    }

    public JdbcSqlStat createSqlStat(StatementProxy statement, String sql) {
        final ConcurrentMap<String, JdbcSqlStat> sqlStatMap = dataSourceStat.getSqlStatMap();
        JdbcSqlStat sqlStat = sqlStatMap.get(sql);
        if (sqlStat == null) {
            if (dataSourceStat.getSqlStatMap().size() >= maxSqlStatCount) {
                return null;
            }

            JdbcSqlStat newSqlStat = new JdbcSqlStat(sql);
            if (dataSourceStat.getSqlStatMap().putIfAbsent(sql, newSqlStat) == null) {
                newSqlStat.setId(JdbcStatManager.getInstance().generateSqlId());
                newSqlStat.setDataSource(this.dataSource.getUrl());
            }

            sqlStat = dataSourceStat.getSqlStatMap().get(sql);
        }
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.getReaderOpenCount());

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

        conn.close();

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

        sqlStat.reset();
        Assert.assertEquals(0, sqlStat.getReaderOpenCount());
    }
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.getReaderOpenCount());

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

        conn.close();

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

        sqlStat.reset();
        Assert.assertEquals(0, sqlStat.getReaderOpenCount());
    }
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.