Search in sources :

Example 6 with MockClob

use of com.alibaba.druid.mock.MockClob in project druid by alibaba.

the class StatFilterClobTest method test_clob.

public void test_clob() throws Exception {
    String sql = "select ?";
    Connection conn = dataSource.getConnection();
    PreparedStatement stmt = conn.prepareStatement(sql);
    MockClob clob = new MockClob();
    stmt.setClob(1, clob);
    ResultSet rs = stmt.executeQuery();
    rs.next();
    Assert.assertTrue(rs.getObject(1) instanceof ClobProxy);
    rs.close();
    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());
}
Also used : ClobProxy(com.alibaba.druid.proxy.jdbc.ClobProxy) JdbcSqlStat(com.alibaba.druid.stat.JdbcSqlStat) MockClob(com.alibaba.druid.mock.MockClob) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 7 with MockClob

use of com.alibaba.druid.mock.MockClob in project druid by alibaba.

the class StatFilterOpenClobCountTest 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 Clob resultSet_getClob(FilterChain chain, ResultSetProxy result, int columnIndex) throws SQLException {
            return new ClobProxyImpl(result.getStatementProxy().getConnectionProxy().getDirectDataSource(), result.getStatementProxy().getConnectionProxy(), new MockClob());
        }

        @Override
        public Clob resultSet_getClob(FilterChain chain, ResultSetProxy result, String columnLabel) throws SQLException {
            return new ClobProxyImpl(result.getStatementProxy().getConnectionProxy().getDirectDataSource(), result.getStatementProxy().getConnectionProxy(), new MockClob());
        }
    });
    dataSource.init();
}
Also used : ClobProxyImpl(com.alibaba.druid.proxy.jdbc.ClobProxyImpl) SQLException(java.sql.SQLException) FilterChain(com.alibaba.druid.filter.FilterChain) MockClob(com.alibaba.druid.mock.MockClob) FilterAdapter(com.alibaba.druid.filter.FilterAdapter) ResultSetProxy(com.alibaba.druid.proxy.jdbc.ResultSetProxy) MockClob(com.alibaba.druid.mock.MockClob) Clob(java.sql.Clob) DruidDataSource(com.alibaba.druid.pool.DruidDataSource)

Aggregations

MockClob (com.alibaba.druid.mock.MockClob)7 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)4 SQLException (java.sql.SQLException)3 FilterAdapter (com.alibaba.druid.filter.FilterAdapter)2 FilterChain (com.alibaba.druid.filter.FilterChain)2 MockBlob (com.alibaba.druid.mock.MockBlob)2 MockResultSet (com.alibaba.druid.mock.MockResultSet)2 ClobProxyImpl (com.alibaba.druid.proxy.jdbc.ClobProxyImpl)2 ConnectionProxyImpl (com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl)2 ResultSetProxy (com.alibaba.druid.proxy.jdbc.ResultSetProxy)2 JdbcSqlStat (com.alibaba.druid.stat.JdbcSqlStat)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)1 MockNClob (com.alibaba.druid.mock.MockNClob)1 MockRowId (com.alibaba.druid.mock.MockRowId)1 CallableStatementProxyImpl (com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl)1 ClobProxy (com.alibaba.druid.proxy.jdbc.ClobProxy)1 StatementProxyImpl (com.alibaba.druid.proxy.jdbc.StatementProxyImpl)1