Search in sources :

Example 21 with MockPreparedStatement

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

the class ConnectionTest4 method test_prepCall.

public void test_prepCall() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    MockPreparedStatement raw = null;
    {
        PreparedStatement stmt = conn.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
        raw = stmt.unwrap(MockPreparedStatement.class);
        stmt.close();
    }
    {
        PreparedStatement stmt = conn.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
        Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class));
        stmt.close();
    }
    conn.close();
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) PreparedStatement(java.sql.PreparedStatement) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement)

Example 22 with MockPreparedStatement

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

the class ConnectionTest4 method test_prepareStatement_2.

public void test_prepareStatement_2() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    MockPreparedStatement raw = null;
    {
        PreparedStatement stmt = conn.prepareStatement("SELECT 1", new int[0]);
        raw = stmt.unwrap(MockPreparedStatement.class);
        stmt.close();
    }
    {
        PreparedStatement stmt = conn.prepareStatement("SELECT 1", new int[0]);
        Assert.assertEquals(raw, stmt.unwrap(MockPreparedStatement.class));
        stmt.close();
    }
    conn.close();
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) PreparedStatement(java.sql.PreparedStatement) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement)

Example 23 with MockPreparedStatement

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

the class PSCacheTest5 method test_0.

public void test_0() throws Exception {
    MockPreparedStatement mockStmt = null;
    {
        Connection conn = dataSource.getConnection();
        PreparedStatement ps = conn.prepareStatement("select 1");
        mockStmt = ps.unwrap(MockPreparedStatement.class);
        ps.execute();
        conn.close();
    }
    for (int i = 0; i < 1000; ++i) {
        Connection conn = dataSource.getConnection();
        PreparedStatement ps = conn.prepareStatement("select 1");
        Assert.assertSame(mockStmt, ps.unwrap(MockPreparedStatement.class));
        ps.execute();
        ps.close();
        conn.close();
    }
}
Also used : Connection(java.sql.Connection) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) PreparedStatement(java.sql.PreparedStatement) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement)

Example 24 with MockPreparedStatement

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

the class TestPSCache method unwrap.

public static MockPreparedStatement unwrap(PreparedStatement stmt) throws Exception {
    if (stmt instanceof NewProxyPreparedStatement) {
        Field field = NewProxyPreparedStatement.class.getDeclaredField("inner");
        field.setAccessible(true);
        return (MockPreparedStatement) field.get(stmt);
    }
    MockPreparedStatement mockStmt = stmt.unwrap(MockPreparedStatement.class);
    return mockStmt;
}
Also used : Field(java.lang.reflect.Field) NewProxyPreparedStatement(com.mchange.v2.c3p0.impl.NewProxyPreparedStatement) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement)

Aggregations

MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)24 PreparedStatement (java.sql.PreparedStatement)14 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)10 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)9 Connection (java.sql.Connection)8 MockConnection (com.alibaba.druid.mock.MockConnection)6 MockDriver (com.alibaba.druid.mock.MockDriver)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 MockResultSet (com.alibaba.druid.mock.MockResultSet)4 MockStatement (com.alibaba.druid.mock.MockStatement)4 Statement (java.sql.Statement)4 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)2 MockStatementBase (com.alibaba.druid.mock.MockStatementBase)2 DruidConnectionHolder (com.alibaba.druid.pool.DruidConnectionHolder)2 PreparedStatementKey (com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey)2 PreparedStatementHolder (com.alibaba.druid.pool.PreparedStatementHolder)2 DruidNativeJdbcExtractor (com.alibaba.druid.support.spring.DruidNativeJdbcExtractor)2 EncodingConvertFilter (com.alibaba.druid.filter.encoding.EncodingConvertFilter)1 MockResultSetMetaData (com.alibaba.druid.mock.MockResultSetMetaData)1