Search in sources :

Example 66 with MockConnection

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

the class DruidDataSourceTest_initSql method testDefault.

public void testDefault() throws Exception {
    Connection conn = dataSource.getConnection();
    MockConnection mockConn = conn.unwrap(MockConnection.class);
    Assert.assertEquals("select 123", mockConn.getLastSql());
    conn.close();
}
Also used : Connection(java.sql.Connection) MockConnection(com.alibaba.druid.mock.MockConnection) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 67 with MockConnection

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

the class PoolablePreparedStatementTest method setUp.

protected void setUp() throws Exception {
    DruidDataSource dataSource = new DruidDataSource();
    MockConnection mockConn = new MockConnection();
    DruidConnectionHolder connHolder = new DruidConnectionHolder(dataSource, mockConn, 0);
    DruidPooledConnection conn = new DruidPooledConnection(connHolder);
    raw = new MockPreparedStatement(null, null);
    stmt = new DruidPooledPreparedStatement(conn, new PreparedStatementHolder(new PreparedStatementKey("", null, null, 0, 0, 0), raw)) {

        protected SQLException checkException(Throwable error) throws SQLException {
            if (error instanceof SQLException) {
                return (SQLException) error;
            }
            return new SQLException(error);
        }
    };
}
Also used : PreparedStatementHolder(com.alibaba.druid.pool.PreparedStatementHolder) SQLException(java.sql.SQLException) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) DruidPooledPreparedStatement(com.alibaba.druid.pool.DruidPooledPreparedStatement) DruidConnectionHolder(com.alibaba.druid.pool.DruidConnectionHolder) MockPreparedStatement(com.alibaba.druid.mock.MockPreparedStatement) PreparedStatementKey(com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) MockConnection(com.alibaba.druid.mock.MockConnection)

Example 68 with MockConnection

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

the class OracleExceptionSorterTest_stmt_setFetchDirection 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.setFetchDirection(ResultSet.FETCH_FORWARD);
    } 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 69 with MockConnection

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

the class OracleExceptionSorterTest_stmt_setFetchSize 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.setFetchSize(10);
    } 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 70 with MockConnection

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

the class OracleExceptionSorterTest_stmt_setMaxField 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.setMaxFieldSize(10);
    } 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)

Aggregations

MockConnection (com.alibaba.druid.mock.MockConnection)74 SQLException (java.sql.SQLException)54 PreparedStatement (java.sql.PreparedStatement)53 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)49 Statement (java.sql.Statement)38 Connection (java.sql.Connection)22 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)13 MockDriver (com.alibaba.druid.mock.MockDriver)8 MockPreparedStatement (com.alibaba.druid.mock.MockPreparedStatement)6 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)4 MockStatement (com.alibaba.druid.mock.MockStatement)4 DruidConnectionHolder (com.alibaba.druid.pool.DruidConnectionHolder)3 PreparedStatementKey (com.alibaba.druid.pool.DruidPooledPreparedStatement.PreparedStatementKey)3 PreparedStatementHolder (com.alibaba.druid.pool.PreparedStatementHolder)3 MSSQLValidConnectionChecker (com.alibaba.druid.pool.vendor.MSSQLValidConnectionChecker)3 ResultSet (java.sql.ResultSet)3 PoolableWrapper (com.alibaba.druid.pool.PoolableWrapper)2 DruidNativeJdbcExtractor (com.alibaba.druid.support.spring.DruidNativeJdbcExtractor)2 ConnectionHandle (com.jolbox.bonecp.ConnectionHandle)2 NewProxyConnection (com.mchange.v2.c3p0.impl.NewProxyConnection)2