Search in sources :

Example 26 with DruidPooledConnection

use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.

the class ConnectionTest4 method test_prepareStatement_1.

public void test_prepareStatement_1() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    MockPreparedStatement raw = null;
    {
        PreparedStatement stmt = conn.prepareStatement("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.prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
        Assert.assertSame(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 27 with DruidPooledConnection

use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.

the class ConnectionTest4 method test_releaseSavepoint_1.

public void test_releaseSavepoint_1() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    conn.getConnection().close();
    {
        SQLException error = null;
        try {
            conn.releaseSavepoint(null);
        } catch (SQLException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    conn.close();
}
Also used : SQLException(java.sql.SQLException) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection)

Example 28 with DruidPooledConnection

use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.

the class ConnectionTest4 method test_prepareStatement_error6.

public void test_prepareStatement_error6() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    conn.getConnection().close();
    {
        SQLException error = null;
        try {
            conn.prepareStatement("SELECT 1", new int[0]);
        } catch (SQLException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    conn.close();
}
Also used : SQLException(java.sql.SQLException) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection)

Example 29 with DruidPooledConnection

use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.

the class ConnectionTest4 method test_prepareStatement_error5.

public void test_prepareStatement_error5() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    {
        SQLException error = null;
        try {
            conn.prepareStatement(null, new int[0]);
        } catch (SQLException ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    conn.close();
}
Also used : SQLException(java.sql.SQLException) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection)

Example 30 with DruidPooledConnection

use of com.alibaba.druid.pool.DruidPooledConnection in project druid by alibaba.

the class ConnectionTest4 method test_prepareStatement_4.

public void test_prepareStatement_4() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    MockPreparedStatement raw = null;
    {
        PreparedStatement stmt = conn.prepareStatement("SELECT 1", 0);
        raw = stmt.unwrap(MockPreparedStatement.class);
        stmt.close();
    }
    {
        PreparedStatement stmt = conn.prepareStatement("SELECT 1", 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)

Aggregations

DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)152 SQLException (java.sql.SQLException)99 PreparedStatement (java.sql.PreparedStatement)61 MockConnection (com.alibaba.druid.mock.MockConnection)49 Statement (java.sql.Statement)46 Connection (java.sql.Connection)20 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)10 ConnectionProxy (com.alibaba.druid.proxy.jdbc.ConnectionProxy)7 DruidConnectionHolder (com.alibaba.druid.pool.DruidConnectionHolder)5 ResultSet (java.sql.ResultSet)5 DruidPooledPreparedStatement (com.alibaba.druid.pool.DruidPooledPreparedStatement)4 PreparedStatementHolder (com.alibaba.druid.pool.PreparedStatementHolder)4 Properties (java.util.Properties)4 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 EncodingConvertFilter (com.alibaba.druid.filter.encoding.EncodingConvertFilter)2 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)2 MockResultSet (com.alibaba.druid.mock.MockResultSet)2 PreparedStatementKey (com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey)2 PreparedStatementPool (com.alibaba.druid.pool.PreparedStatementPool)2 CountDownLatch (java.util.concurrent.CountDownLatch)2