Search in sources :

Example 96 with DruidPooledConnection

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

the class ConnectionTest3 method test_basic.

public void test_basic() throws Exception {
    DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
    conn.getTransactionInfo();
    conn.getMetaData();
    conn.setReadOnly(true);
    Assert.assertEquals(true, conn.isReadOnly());
    conn.setCatalog("xxx");
    Assert.assertEquals("xxx", conn.getCatalog());
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    Assert.assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn.getTransactionIsolation());
    conn.getWarnings();
    conn.clearWarnings();
    conn.getTypeMap();
    conn.setTypeMap(null);
    conn.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
    Assert.assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, conn.getHoldability());
    conn.setSavepoint();
    conn.setSavepoint("savepoint");
    conn.rollback();
    {
        Exception error = null;
        try {
            conn.rollback(null);
        } catch (SQLException e) {
            error = e;
        }
        Assert.assertNotNull(error);
    }
    {
        Exception error = null;
        try {
            conn.releaseSavepoint(null);
        } catch (SQLException e) {
            error = e;
        }
        Assert.assertNotNull(error);
    }
    conn.createBlob();
    conn.createClob();
    conn.createNClob();
    conn.createSQLXML();
    conn.isValid(200);
    conn.setClientInfo(new Properties());
    conn.setClientInfo("xx", "11");
    conn.getClientInfo("xx");
    conn.getClientInfo();
    conn.createArrayOf("int", new Object[0]);
    conn.createStruct("int", new Object[0]);
    conn.addConnectionEventListener(null);
    conn.removeConnectionEventListener(null);
    conn.addStatementEventListener(null);
    conn.removeStatementEventListener(null);
    conn.close();
}
Also used : SQLException(java.sql.SQLException) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) Properties(java.util.Properties) SQLException(java.sql.SQLException)

Example 97 with DruidPooledConnection

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

the class ConnectionTest5 method test_basic.

public void test_basic() throws Exception {
    DruidPooledConnection conn = (DruidPooledConnection) dataSource.getConnection();
    conn.close();
    Assert.assertEquals(true, dataSource.isResetStatEnable());
    dataSource.setResetStatEnable(false);
    Assert.assertEquals(false, dataSource.isResetStatEnable());
    Assert.assertEquals(1, dataSource.getConnectCount());
    dataSource.resetStat();
    Assert.assertEquals(1, dataSource.getConnectCount());
    dataSource.setResetStatEnable(true);
    dataSource.resetStat();
    Assert.assertEquals(0, dataSource.getConnectCount());
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection)

Example 98 with DruidPooledConnection

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

the class ConnectionTest5 method test_handleException_4.

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

Example 99 with DruidPooledConnection

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

the class ConnectionTest5 method test_handleException_3.

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

Example 100 with DruidPooledConnection

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

the class ConnectionTest5 method test_handleException_2.

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

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