Search in sources :

Example 6 with PreparedStatementProxy

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

the class StatFilterExecErrorTest method setUp.

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

        @Override
        public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
            throw new SQLException();
        }

        @Override
        public ResultSetProxy preparedStatement_executeQuery(FilterChain chain, PreparedStatementProxy statement) throws SQLException {
            throw new SQLException();
        }
    });
    dataSource.init();
}
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)

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

Example 8 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 9 with PreparedStatementProxy

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

the class PreparedStatementProxyImplTest method test_setObject.

public void test_setObject() throws Exception {
    String sql = "insert t values(?, ?, ?, ?, ?,  ?, ?, ?, ?, ?)";
    Connection conn = dataSource.getConnection();
    PreparedStatement stmt = conn.prepareStatement(sql);
    stmt.setObject(1, (byte) 1);
    stmt.setObject(2, (short) 1);
    stmt.setObject(3, (int) 1);
    stmt.setObject(4, (long) 1);
    stmt.setObject(5, (float) 1);
    stmt.setObject(6, (double) 1);
    stmt.setObject(7, new BigDecimal(1));
    stmt.setObject(8, true);
    stmt.setObject(9, "xxx");
    stmt.setObject(10, new java.sql.Date(System.currentTimeMillis()));
    stmt.setObject(11, new java.util.Date(System.currentTimeMillis()));
    stmt.setObject(12, new java.sql.Timestamp(System.currentTimeMillis()));
    stmt.setObject(13, new java.sql.Time(System.currentTimeMillis()));
    stmt.execute();
    PreparedStatementProxy stmtProxy = stmt.unwrap(PreparedStatementProxy.class);
    Assert.assertNotNull(stmtProxy);
    Assert.assertEquals(Types.TINYINT, stmtProxy.getParameter(0).getSqlType());
    Assert.assertEquals(Types.SMALLINT, stmtProxy.getParameter(1).getSqlType());
    Assert.assertEquals(Types.INTEGER, stmtProxy.getParameter(2).getSqlType());
    Assert.assertEquals(Types.BIGINT, stmtProxy.getParameter(3).getSqlType());
    Assert.assertEquals(Types.FLOAT, stmtProxy.getParameter(4).getSqlType());
    Assert.assertEquals(Types.DOUBLE, stmtProxy.getParameter(5).getSqlType());
    Assert.assertEquals(Types.DECIMAL, stmtProxy.getParameter(6).getSqlType());
    Assert.assertEquals(Types.BOOLEAN, stmtProxy.getParameter(7).getSqlType());
    Assert.assertEquals(Types.VARCHAR, stmtProxy.getParameter(8).getSqlType());
    Assert.assertEquals(Types.DATE, stmtProxy.getParameter(9).getSqlType());
    Assert.assertEquals(Types.DATE, stmtProxy.getParameter(10).getSqlType());
    Assert.assertEquals(Types.TIMESTAMP, stmtProxy.getParameter(11).getSqlType());
    Assert.assertEquals(Types.TIME, stmtProxy.getParameter(12).getSqlType());
    stmt.close();
    conn.close();
}
Also used : Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) PreparedStatementProxy(com.alibaba.druid.proxy.jdbc.PreparedStatementProxy) BigDecimal(java.math.BigDecimal)

Example 10 with PreparedStatementProxy

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

the class WallFilter method connection_prepareStatement.

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

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