Search in sources :

Example 16 with DruidPooledConnection

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

the class DataSourceTest3 method test_error_5.

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

Example 17 with DruidPooledConnection

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

the class DataSourceTest3 method test_error_4.

@SuppressWarnings("deprecation")
public void test_error_4() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    conn.close();
    dataSource.setMaxIdle(1);
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection)

Example 18 with DruidPooledConnection

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

the class DataSourceTest3 method test_setConnectionInitSqls.

public void test_setConnectionInitSqls() throws Exception {
    DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
    conn.close();
    dataSource.setConnectionInitSqls(null);
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection)

Example 19 with DruidPooledConnection

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

the class TestDataSourceBasic method test_prepare.

public void test_prepare() throws Exception {
    Connection conn = dataSource.getConnection();
    {
        DruidPooledConnection wrap = conn.unwrap(DruidPooledConnection.class);
        Assert.assertTrue(conn.isWrapperFor(DruidPooledConnection.class));
        Assert.assertNotNull(wrap);
    }
    {
        Statement wrap = conn.unwrap(Statement.class);
        Assert.assertTrue(!conn.isWrapperFor(Statement.class));
        Assert.assertNull(wrap);
    }
    conn.setAutoCommit(false);
    conn.setAutoCommit(false);
    Statement stmt = conn.createStatement();
    stmt.execute("SELECT 1");
    stmt.close();
    Assert.assertEquals(1, dataSource.getActiveConnectionStackTrace().size());
    Assert.assertEquals(1, dataSource.getActiveConnections().size());
    conn.commit();
    conn.close();
    Assert.assertEquals(1, dataSource.getStartTransactionCount());
    Assert.assertEquals(1, dataSource.getCommitCount());
    Assert.assertEquals(0, dataSource.getRollbackCount());
    Assert.assertEquals(0, dataSource.getActiveConnectionStackTrace().size());
    Assert.assertEquals(0, dataSource.getActiveConnections().size());
}
Also used : DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) Statement(java.sql.Statement) DruidPooledConnection(com.alibaba.druid.pool.DruidPooledConnection) Connection(java.sql.Connection)

Example 20 with DruidPooledConnection

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

the class ConnectionTest5 method test_setClientInfo_1.

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

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