Search in sources :

Example 1 with PreparedStatementProxy

use of com.alibaba.druid.proxy.jdbc.PreparedStatementProxy in project druid by alibaba.

the class FilterEventAdapter method connection_prepareStatement.

@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
    PreparedStatementProxy statement = super.connection_prepareStatement(chain, connection, sql, resultSetType, resultSetConcurrency, resultSetHoldability);
    statementPrepareAfter(statement);
    return statement;
}
Also used : PreparedStatementProxy(com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)

Example 2 with PreparedStatementProxy

use of com.alibaba.druid.proxy.jdbc.PreparedStatementProxy in project druid by alibaba.

the class FilterEventAdapter method connection_prepareStatement.

@Override
public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int[] columnIndexes) throws SQLException {
    PreparedStatementProxy statement = super.connection_prepareStatement(chain, connection, sql, columnIndexes);
    statementPrepareAfter(statement);
    return statement;
}
Also used : PreparedStatementProxy(com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)

Example 3 with PreparedStatementProxy

use of com.alibaba.druid.proxy.jdbc.PreparedStatementProxy in project druid by alibaba.

the class PreparedStatementPool method put.

public void put(PreparedStatementHolder stmtHolder) throws SQLException {
    PreparedStatement stmt = stmtHolder.statement;
    if (stmt == null) {
        return;
    }
    if (dataSource.isOracle() && dataSource.isUseOracleImplicitCache()) {
        OracleUtils.enterImplicitCache(stmt);
        stmtHolder.setEnterOracleImplicitCache(true);
    } else {
        stmtHolder.setEnterOracleImplicitCache(false);
    }
    PreparedStatementHolder oldStmtHolder = map.put(stmtHolder.key, stmtHolder);
    if (oldStmtHolder == stmtHolder) {
        return;
    }
    if (oldStmtHolder != null) {
        oldStmtHolder.setPooling(false);
        closeRemovedStatement(oldStmtHolder);
    } else {
        if (stmtHolder.getHitCount() == 0) {
            dataSource.incrementCachedPreparedStatementCount();
        }
    }
    stmtHolder.setPooling(true);
    if (LOG.isDebugEnabled()) {
        String message = null;
        if (stmtHolder.statement instanceof PreparedStatementProxy) {
            PreparedStatementProxy stmtProxy = (PreparedStatementProxy) stmtHolder.statement;
            if (stmtProxy instanceof CallableStatementProxy) {
                message = "{conn-" + stmtProxy.getConnectionProxy().getId() + ", cstmt-" + stmtProxy.getId() + "} enter cache";
            } else {
                message = "{conn-" + stmtProxy.getConnectionProxy().getId() + ", pstmt-" + stmtProxy.getId() + "} enter cache";
            }
        } else {
            message = "stmt enter cache";
        }
        LOG.debug(message);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) CallableStatementProxy(com.alibaba.druid.proxy.jdbc.CallableStatementProxy) PreparedStatementProxy(com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)

Example 4 with PreparedStatementProxy

use of com.alibaba.druid.proxy.jdbc.PreparedStatementProxy in project druid by alibaba.

the class DruidPooledConnectionTest_prepareError method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setFilters("stat");
    dataSource.setPoolPreparedStatements(true);
    dataSource.getProxyFilters().add(new FilterAdapter() {

        @Override
        public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql) throws SQLException {
            throw new SQLException();
        }

        @Override
        public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int autoGeneratedKeys) throws SQLException {
            throw new SQLException();
        }

        @Override
        public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
            throw new SQLException();
        }

        @Override
        public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
            throw new SQLException();
        }

        @Override
        public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, int[] columnIndexes) throws SQLException {
            throw new SQLException();
        }

        @Override
        public PreparedStatementProxy connection_prepareStatement(FilterChain chain, ConnectionProxy connection, String sql, String[] columnNames) throws SQLException {
            throw new SQLException();
        }

        @Override
        public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql) throws SQLException {
            throw new SQLException();
        }

        @Override
        public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
            throw new SQLException();
        }

        @Override
        public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
            throw new SQLException();
        }
    });
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) CallableStatementProxy(com.alibaba.druid.proxy.jdbc.CallableStatementProxy) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) ConnectionProxy(com.alibaba.druid.proxy.jdbc.ConnectionProxy) PreparedStatementProxy(com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)

Example 5 with PreparedStatementProxy

use of com.alibaba.druid.proxy.jdbc.PreparedStatementProxy in project druid by alibaba.

the class DruidPooledPreparedStatementTest1 method setUp.

protected void setUp() throws Exception {
    dataSource = new DruidDataSource();
    dataSource.setUrl("jdbc:mock:xxx");
    dataSource.setTestOnBorrow(false);
    dataSource.setInitialSize(1);
    dataSource.getProxyFilters().add(new FilterAdapter() {

        @Override
        public boolean preparedStatement_execute(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
            throw new SQLException();
        }

        @Override
        public int preparedStatement_executeUpdate(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
            throw new SQLException();
        }

        public ResultSetProxy preparedStatement_executeQuery(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
            throw new SQLException();
        }

        public void preparedStatement_clearParameters(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
            throw new SQLException();
        }

        @Override
        public int[] statement_executeBatch(FilterChain chain, StatementProxy statement) throws SQLException {
            throw new SQLException();
        }

        @Override
        public ParameterMetaData preparedStatement_getParameterMetaData(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
            throw new SQLException();
        }
    });
}
Also used : SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) StatementProxy(com.alibaba.druid.proxy.jdbc.StatementProxy) PreparedStatementProxy(com.alibaba.druid.proxy.jdbc.PreparedStatementProxy) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) ResultSetProxy(com.alibaba.druid.proxy.jdbc.ResultSetProxy) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) PreparedStatementProxy(com.alibaba.druid.proxy.jdbc.PreparedStatementProxy) ParameterMetaData(java.sql.ParameterMetaData)

Aggregations

PreparedStatementProxy (com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)16 SQLException (java.sql.SQLException)5 FilterChain (com.alibaba.druid.filter.FilterChain)4 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)4 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)3 CallableStatementProxy (com.alibaba.druid.proxy.jdbc.CallableStatementProxy)3 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)3 StatementProxy (com.alibaba.druid.proxy.jdbc.StatementProxy)3 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)2 PreparedStatement (java.sql.PreparedStatement)2 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)1 FilterEventAdapter (com.alibaba.druid.filter.FilterEventAdapter)1 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)1 ConnectionProxyImpl (com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl)1 DataSourceProxy (com.alibaba.druid.proxy.jdbc.DataSourceProxy)1 DataSourceProxyConfig (com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig)1 DataSourceProxyImpl (com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl)1 PreparedStatementProxyImpl (com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl)1 ResultSetProxyImpl (com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl)1 BigDecimal (java.math.BigDecimal)1