Search in sources :

Example 6 with ClobProxy

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

the class FilterChainTest_Clob_2 method test_getObject.

public void test_getObject() throws Exception {
    FilterChainImpl chain = new FilterChainImpl(dataSource);
    Clob clob = (Clob) chain.callableStatement_getObject(statement, 1);
    Assert.assertTrue(clob instanceof ClobProxy);
    Assert.assertEquals(1, invokeCount);
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) ClobProxy(com.alibaba.druid.proxy.jdbc.ClobProxy) MockClob(com.alibaba.druid.mock.MockClob) Clob(java.sql.Clob)

Example 7 with ClobProxy

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

the class FilterChainTest_Clob_2 method test_getObject_1.

public void test_getObject_1() throws Exception {
    FilterChainImpl chain = new FilterChainImpl(dataSource);
    Clob clob = (Clob) chain.callableStatement_getObject(statement, "1");
    Assert.assertTrue(clob instanceof ClobProxy);
    Assert.assertEquals(1, invokeCount);
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) ClobProxy(com.alibaba.druid.proxy.jdbc.ClobProxy) MockClob(com.alibaba.druid.mock.MockClob) Clob(java.sql.Clob)

Example 8 with ClobProxy

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

the class FilterChainTest_Clob_2 method test_getClob_1.

public void test_getClob_1() throws Exception {
    FilterChainImpl chain = new FilterChainImpl(dataSource);
    Clob clob = chain.callableStatement_getClob(statement, "1");
    Assert.assertTrue(clob instanceof ClobProxy);
    Assert.assertEquals(1, invokeCount);
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) ClobProxy(com.alibaba.druid.proxy.jdbc.ClobProxy) MockClob(com.alibaba.druid.mock.MockClob) Clob(java.sql.Clob)

Example 9 with ClobProxy

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

the class FilterChainTest_Clob_2 method test_getObject_3.

public void test_getObject_3() throws Exception {
    FilterChainImpl chain = new FilterChainImpl(dataSource);
    Clob clob = (Clob) chain.callableStatement_getObject(statement, "1", Collections.<String, Class<?>>emptyMap());
    Assert.assertTrue(clob instanceof ClobProxy);
    Assert.assertEquals(1, invokeCount);
}
Also used : FilterChainImpl(com.alibaba.druid.filter.FilterChainImpl) ClobProxy(com.alibaba.druid.proxy.jdbc.ClobProxy) MockClob(com.alibaba.druid.mock.MockClob) Clob(java.sql.Clob)

Example 10 with ClobProxy

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

the class ClobTest method test_clob.

public void test_clob() throws Exception {
    Connection conn = null;
    PreparedStatement pstmt = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        conn = DriverManager.getConnection(create_url);
        pstmt = conn.prepareStatement("INSERT INTO T_CLOB (ID, DATA) VALUES (?, ?)");
        Clob clob = conn.createClob();
        ClobProxy clobWrapper = (ClobProxy) clob;
        Assert.assertNotNull(clobWrapper.getConnectionWrapper());
        clob.setAsciiStream(1);
        clob.setCharacterStream(1);
        clob.setString(1, "ABCAAAAAAAAAAA");
        clob.setString(1, "ABCAAAAAAAAAAA", 1, 5);
        pstmt.setInt(1, 1);
        pstmt.setClob(2, clob);
        int updateCount = pstmt.executeUpdate();
        Assert.assertEquals(1, updateCount);
        pstmt.setInt(1, 1);
        pstmt.setClob(2, new StringReader("XXXXXXX"));
        updateCount = pstmt.executeUpdate();
        Assert.assertEquals(1, updateCount);
        pstmt.setInt(1, 1);
        pstmt.setClob(2, new StringReader("ABCAAAAAAAAAAABCAAAAAAAAAAAAABCAAAAAAAAAAABCAAAAAAAAAAAA"), "ABCAAAAAAAAAAABCAAAAAAAAAAAAABCAAAAAAAAAAABCAAAAAAAAAAAA".length());
        updateCount = pstmt.executeUpdate();
        Assert.assertEquals(1, updateCount);
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);
        // //////
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        // just call
        rs.getStatement();
        while (rs.next()) {
            Clob readClob = rs.getClob(2);
            readClob.length();
            readClob.position("abc", 1);
            readClob.getCharacterStream().close();
            readClob.getAsciiStream().close();
            readClob.getCharacterStream(1, 1).close();
            readClob.getSubString(1, 2);
            readClob.truncate(2);
            readClob.free();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.getCharacterStream(2).close();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.getCharacterStream("DATA").close();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            Clob searchstr = conn.createClob();
            searchstr.setString(1, "AB");
            Clob x = rs.getClob("DATA");
            x.position(searchstr, 1);
            x.free();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.getAsciiStream(2).close();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.getAsciiStream("DATA").close();
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            Clob x = conn.createClob();
            x.setString(1, "XXSDDSLF");
            rs.updateClob(2, x);
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            Clob x = conn.createClob();
            x.setString(1, "XXSDDSLF");
            rs.updateClob("DATA", x);
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.updateClob(2, new StringReader("XDSFLA"));
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.updateClob("DATA", new StringReader("XDSFLA"));
        }
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.updateClob(2, new StringReader("XDSFLA"), "XDSFLA".length());
        }
        JdbcUtils.close(rs);
        rs = stmt.executeQuery("SELECT ID, DATA FROM T_CLOB");
        while (rs.next()) {
            rs.updateClob("DATA", new StringReader("XDSFLA"), "XDSFLA".length());
        }
        JdbcUtils.close(rs);
    } finally {
        JdbcUtils.close(rs);
        JdbcUtils.close(stmt);
        JdbcUtils.close(pstmt);
        JdbcUtils.close(conn);
    }
}
Also used : ClobProxy(com.alibaba.druid.proxy.jdbc.ClobProxy) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) StringReader(java.io.StringReader) PreparedStatement(java.sql.PreparedStatement) Clob(java.sql.Clob)

Aggregations

ClobProxy (com.alibaba.druid.proxy.jdbc.ClobProxy)14 MockClob (com.alibaba.druid.mock.MockClob)13 Clob (java.sql.Clob)13 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)12 ResultSetProxyImpl (com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl)6 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 JdbcSqlStat (com.alibaba.druid.stat.JdbcSqlStat)1 StringReader (java.io.StringReader)1 Statement (java.sql.Statement)1