Search in sources :

Example 1 with CallableStatementProxy

use of com.alibaba.druid.proxy.jdbc.CallableStatementProxy 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 2 with CallableStatementProxy

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

the class WallFilter method connection_prepareCall.

@Override
public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql) throws SQLException {
    String dbType = connection.getDirectDataSource().getDbType();
    WallContext.create(dbType);
    try {
        sql = check(sql);
        CallableStatementProxy stmt = chain.connection_prepareCall(connection, sql);
        setSqlStatAttribute(stmt);
        return stmt;
    } finally {
        WallContext.clearContext();
    }
}
Also used : CallableStatementProxy(com.alibaba.druid.proxy.jdbc.CallableStatementProxy)

Example 3 with CallableStatementProxy

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

the class DruidPooledCallableStatementTest 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() {

        public boolean callableStatement_wasNull(FilterChain chain, CallableStatementProxy statement) throws SQLException {
            if (throwError) {
                throw new SQLException();
            } else {
                return chain.callableStatement_wasNull(statement);
            }
        }
    });
}
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)

Example 4 with CallableStatementProxy

use of com.alibaba.druid.proxy.jdbc.CallableStatementProxy 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 CallableStatementProxy

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

the class FilterEventAdapter method connection_prepareCall.

@Override
public CallableStatementProxy connection_prepareCall(FilterChain chain, ConnectionProxy connection, String sql) throws SQLException {
    CallableStatementProxy statement = super.connection_prepareCall(chain, connection, sql);
    statementPrepareCallAfter(statement);
    return statement;
}
Also used : CallableStatementProxy(com.alibaba.druid.proxy.jdbc.CallableStatementProxy)

Aggregations

CallableStatementProxy (com.alibaba.druid.proxy.jdbc.CallableStatementProxy)8 PreparedStatementProxy (com.alibaba.druid.proxy.jdbc.PreparedStatementProxy)3 SQLException (java.sql.SQLException)3 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)2 FilterChain (com.alibaba.druid.filter.FilterChain)2 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)2 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)1 PreparedStatement (java.sql.PreparedStatement)1