Search in sources :

Example 71 with DruidPooledConnection

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

the class OracleExceptionSorterTest_stmt_getMaxRows method test_connect.

public void test_connect() throws Exception {
    String sql = "SELECT 1";
    {
        DruidPooledConnection conn = dataSource.getConnection();
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.execute();
        pstmt.close();
        conn.close();
    }
    DruidPooledConnection conn = dataSource.getConnection();
    MockConnection mockConn = conn.unwrap(MockConnection.class);
    Assert.assertNotNull(mockConn);
    Statement stmt = conn.createStatement();
    SQLException exception = new SQLException("xx", "xxx", 28);
    mockConn.setError(exception);
    SQLException stmtErrror = null;
    try {
        stmt.getMaxRows();
    } catch (SQLException ex) {
        stmtErrror = ex;
    }
    Assert.assertNotNull(stmtErrror);
    Assert.assertSame(exception, stmtErrror);
    SQLException commitError = null;
    try {
        conn.commit();
    } catch (SQLException ex) {
        commitError = ex;
    }
    Assert.assertNotNull(commitError);
    Assert.assertSame(exception, commitError.getCause());
    conn.close();
}
Also used : SQLException(java.sql.SQLException) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 72 with DruidPooledConnection

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

the class OracleExceptionSorterTest_stmt_getResultSet method test_connect.

public void test_connect() throws Exception {
    String sql = "SELECT 1";
    {
        DruidPooledConnection conn = dataSource.getConnection();
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.execute();
        pstmt.close();
        conn.close();
    }
    DruidPooledConnection conn = dataSource.getConnection();
    MockConnection mockConn = conn.unwrap(MockConnection.class);
    Assert.assertNotNull(mockConn);
    Statement stmt = conn.createStatement();
    stmt.execute(sql);
    SQLException exception = new SQLException("xx", "xxx", 28);
    mockConn.setError(exception);
    SQLException stmtErrror = null;
    try {
        stmt.getResultSet();
    } catch (SQLException ex) {
        stmtErrror = ex;
    }
    Assert.assertNotNull(stmtErrror);
    Assert.assertSame(exception, stmtErrror);
    SQLException commitError = null;
    try {
        conn.commit();
    } catch (SQLException ex) {
        commitError = ex;
    }
    Assert.assertNotNull(commitError);
    Assert.assertSame(exception, commitError.getCause());
    conn.close();
}
Also used : SQLException(java.sql.SQLException) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 73 with DruidPooledConnection

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

the class OracleExceptionSorterTest_stmt_getResultSetHoldability method test_connect.

public void test_connect() throws Exception {
    String sql = "SELECT 1";
    {
        DruidPooledConnection conn = dataSource.getConnection();
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.execute();
        pstmt.close();
        conn.close();
    }
    DruidPooledConnection conn = dataSource.getConnection();
    MockConnection mockConn = conn.unwrap(MockConnection.class);
    Assert.assertNotNull(mockConn);
    Statement stmt = conn.createStatement();
    SQLException exception = new SQLException("xx", "xxx", 28);
    mockConn.setError(exception);
    SQLException stmtErrror = null;
    try {
        stmt.getResultSetHoldability();
    } catch (SQLException ex) {
        stmtErrror = ex;
    }
    Assert.assertNotNull(stmtErrror);
    Assert.assertSame(exception, stmtErrror);
    SQLException commitError = null;
    try {
        conn.commit();
    } catch (SQLException ex) {
        commitError = ex;
    }
    Assert.assertNotNull(commitError);
    Assert.assertSame(exception, commitError.getCause());
    conn.close();
}
Also used : SQLException(java.sql.SQLException) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 74 with DruidPooledConnection

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

the class OracleExceptionSorterTest_stmt_executeUpdate_2 method test_connect.

public void test_connect() throws Exception {
    String sql = "SELECT 1";
    {
        DruidPooledConnection conn = dataSource.getConnection();
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.execute();
        pstmt.close();
        conn.close();
    }
    DruidPooledConnection conn = dataSource.getConnection();
    MockConnection mockConn = conn.unwrap(MockConnection.class);
    Assert.assertNotNull(mockConn);
    Statement stmt = conn.createStatement();
    SQLException exception = new SQLException("xx", "xxx", 28);
    mockConn.setError(exception);
    SQLException execErrror = null;
    try {
        stmt.executeUpdate(sql, new int[0]);
    } catch (SQLException ex) {
        execErrror = ex;
    }
    Assert.assertNotNull(execErrror);
    Assert.assertSame(exception, execErrror);
    SQLException commitError = null;
    try {
        conn.commit();
    } catch (SQLException ex) {
        commitError = ex;
    }
    Assert.assertNotNull(commitError);
    Assert.assertSame(exception, commitError.getCause());
    conn.close();
}
Also used : SQLException(java.sql.SQLException) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 75 with DruidPooledConnection

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

the class OracleExceptionSorterTest_setReadOnly method test_connect.

public void test_connect() throws Exception {
    String sql = "SELECT 1";
    {
        DruidPooledConnection conn = dataSource.getConnection();
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.execute();
        pstmt.close();
        conn.close();
        Assert.assertEquals(0, dataSource.getActiveCount());
        Assert.assertEquals(1, dataSource.getPoolingCount());
        Assert.assertEquals(1, dataSource.getCreateCount());
    }
    DruidPooledConnection conn = dataSource.getConnection();
    MockConnection mockConn = conn.unwrap(MockConnection.class);
    Assert.assertNotNull(mockConn);
    SQLException exception = new SQLException("xx", "xxx", 28);
    mockConn.setError(exception);
    Exception setError = null;
    try {
        conn.setReadOnly(true);
    } catch (Exception ex) {
        setError = ex;
    }
    Assert.assertNotNull(setError);
    conn.close();
    {
        Connection conn2 = dataSource.getConnection();
        conn2.close();
    }
    Assert.assertEquals(0, dataSource.getActiveCount());
    Assert.assertEquals(1, dataSource.getPoolingCount());
    Assert.assertEquals(2, dataSource.getCreateCount());
}
Also used : SQLException(java.sql.SQLException) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) Connection(java.sql.Connection) MockConnection(com.alibaba.druid.mock.MockConnection) PreparedStatement(java.sql.PreparedStatement) MockConnection(com.alibaba.druid.mock.MockConnection) SQLException(java.sql.SQLException)

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