Example usage for org.apache.commons.configuration ConfigurationException printStackTrace

List of usage examples for org.apache.commons.configuration ConfigurationException printStackTrace

Introduction

In this page you can find the example usage for org.apache.commons.configuration ConfigurationException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Usage

From source file:jdbc.pool.JDBCPoolTestCase.java

/**
 * Test case for ResultSet leak.//from w  w w .j  a  v  a  2  s . c  o  m
 */
public void testResultSetLeak() {
    System.out.println("testResultSetLeak Start.");
    CConnectionPoolManager manager = null;
    Connection con = null; //It has 3 iniital connections.
    PreparedStatement st;
    try {
        manager = create();
        con = manager.getConnection("ORACLE");
        st = con.prepareStatement("SELECT 'A' FROM DUAL UNION SELECT 'B' FROM DUAL");
        ResultSet rs = st.executeQuery();
        while (rs.next()) {
            //do nothing
        }
        st.close();
        CPoolStatisticsBean bean = manager.getPoolStatistics("ORACLE");
        assertEquals("Pool Name", "ORACLE", bean.getPoolName());
        assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount());
        assertEquals("Connections High Count", 1, bean.getConnectionsHighCount());
        assertEquals("Current Free Connections", 0, bean.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 1, bean.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 1, bean.getLeakedResultSetCount());
        st = con.prepareStatement("SELECT 'A' FROM DUAL UNION SELECT 'B' FROM DUAL");
        rs = st.executeQuery();
        while (rs.next()) {
            //do nothing
        }
        st.close();
        bean = manager.getPoolStatistics("ORACLE");
        assertEquals("Pool Name", "ORACLE", bean.getPoolName());
        assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount());
        assertEquals("Connections High Count", 1, bean.getConnectionsHighCount());
        assertEquals("Current Free Connections", 0, bean.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 1, bean.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 2, bean.getLeakedResultSetCount());
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail("Caught ConfigurationException");
    } catch (ParseException e) {
        e.printStackTrace();
        fail("Caught ParseException");
    } catch (IOException e) {
        e.printStackTrace();
        fail("Caught IOException");
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Caught SQLException");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        fail("Caught ClassNotFoundException");
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (manager != null) {
            manager.destroy(true);
        }
    }
    System.out.println("testStatementCaching End.");
}

From source file:jdbc.pool.JDBCPoolOracleConnectionTest.java

/**
 * Test case for FIFO Algorithm with Maximum JDBC Usage parameter.
 *//*from w w w  .  j  ava2 s .c o m*/
public void testFIFOAlgorithm() {
    System.out.println("testFIFOAlgorithm with Maximum Usage Counter Start.");
    testGetInstanceNull();
    try {
        CConnectionPoolManager manager = create();
        Connection realCon = null;
        Connection con = manager.getConnection("FIFO"); //It has 3 iniital connections.
        if (con instanceof ConnectionWrapper) {
            ConnectionWrapper wrapper = (ConnectionWrapper) con;
            realCon = wrapper.realConnection();
        } else {
            fail("Connection returned is not an instance of ConnectionWrapper");
        }
        con.close();
        for (int i = 2; i <= (3 * 4) - 3; i++) { // 3 (no. of con) * 4 (max jdbc usage) - 2 (to bring the original on top.)
            con = manager.getConnection("FIFO");
            con.close();
            assertFalse("Connection must be active #" + i, realCon.isClosed());
        }
        con = manager.getConnection("FIFO");
        con.close();
        assertTrue("Connection must be active", realCon.isClosed());
        manager.destroy(true);
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail("Caught ConfigurationException");
    } catch (ParseException e) {
        e.printStackTrace();
        fail("Caught ParseException");
    } catch (IOException e) {
        e.printStackTrace();
        fail("Caught IOException");
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Caught SQLException");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        fail("Caught ClassNotFoundException");
    }
    System.out.println("testFIFOAlgorithm with Maximum Usage Counter End.");
}

From source file:jdbc.pool.JDBCPoolOracleConnectionTest.java

/**
 * Validates whether the connection received from the pool is as per the
 * JDBC driver specified in the configuration file.
 * //from w w w.ja  va2  s. c om
 */
public void testValidateConnectionForJDBCDriver() {
    System.out.println("validateConnectionForJDBCDriver Start");
    testGetInstanceNull();
    try {
        CConnectionPoolManager manager = create();
        Connection con = manager.getConnection("ORACLE");
        if (con instanceof ConnectionWrapper) {
            ConnectionWrapper wrapper = (ConnectionWrapper) con;
            assertTrue("real connection from Oracle pool is of Oracle",
                    wrapper.realConnection() instanceof oracle.jdbc.OracleConnection);
        } else {
            fail("Connection returned is not an instance of ConnectionWrapper");
        }
        con.close();
        con = manager.getConnection("MYSQL");
        if (con instanceof ConnectionWrapper) {
            ConnectionWrapper wrapper = (ConnectionWrapper) con;
            assertTrue("real connection from MYSQL pool is of MySQL",
                    wrapper.realConnection() instanceof com.mysql.jdbc.Connection);
        } else {
            fail("Connection returned is not an instance of ConnectionWrapper");
        }
        con.close();
        manager.destroy(true);
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail("Caught ConfigurationException");
    } catch (ParseException e) {
        e.printStackTrace();
        fail("Caught ParseException");
    } catch (IOException e) {
        e.printStackTrace();
        fail("Caught IOException");
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Caught SQLException");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        fail("Caught ClassNotFoundException");
    }
    System.out.println("validateConnectionForJDBCDriver end");
}

From source file:jdbc.pool.JDBCPoolOracleConnectionTest.java

/**
 * Test case for LIFO Algorithm with Maximum JDBC Usage parameter.
 *//*from w  ww.  j  ava 2 s . c o m*/
public void testLIFOAlgorithm() {
    System.out.println("testLIFOAlgorithm with Maximum Usage Counter Start.");
    testGetInstanceNull();
    try {
        CConnectionPoolManager manager = create();
        Connection realCon = null;
        Connection con = manager.getConnection("LIFO"); //It has 3 iniital connections.
        if (con instanceof ConnectionWrapper) {
            ConnectionWrapper wrapper = (ConnectionWrapper) con;
            realCon = wrapper.realConnection();
        } else {
            fail("Connection returned is not an instance of ConnectionWrapper");
        }
        con.close();
        con = manager.getConnection("LIFO");
        con.close();
        assertFalse("Connection must be active", realCon.isClosed());
        con = manager.getConnection("LIFO");
        con.close();
        assertFalse("Connection must be active", realCon.isClosed());
        con = manager.getConnection("LIFO");
        con.close();
        assertTrue("Connection must be active", realCon.isClosed());
        manager.destroy(true);
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail("Caught ConfigurationException");
    } catch (ParseException e) {
        e.printStackTrace();
        fail("Caught ParseException");
    } catch (IOException e) {
        e.printStackTrace();
        fail("Caught IOException");
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Caught SQLException");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        fail("Caught ClassNotFoundException");
    }
    System.out.println("testLIFOAlgorithm with Maximum Usage Counter End.");
}

From source file:jdbc.pool.JDBCPoolTestCase.java

/**
 * Tests the capacity increament of the pool.
 * //from  ww w. j a v a 2s.c om
 */
public void testCapacityIncreament() {
    System.out.println("testCapacityIncreament Start");
    try {
        CConnectionPoolManager manager = create();
        // capacity increament Oracle 1
        Connection conOracle1 = manager.getConnection("ORACLE");
        CPoolStatisticsBean bean = manager.getPoolStatistics("ORACLE");
        assertEquals("Pool Name", "ORACLE", bean.getPoolName());
        assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount());
        assertEquals("Connections High Count", 1, bean.getConnectionsHighCount());
        assertEquals("Current Free Connections", 0, bean.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 1, bean.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 0, bean.getLeakedResultSetCount());

        Connection conOracle2 = manager.getConnection("ORACLE");
        bean = manager.getPoolStatistics("ORACLE");
        assertEquals("Pool Name", "ORACLE", bean.getPoolName());
        assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount());
        assertEquals("Connections High Count", 2, bean.getConnectionsHighCount());
        assertEquals("Current Free Connections", 0, bean.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 2, bean.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 0, bean.getLeakedResultSetCount());
        conOracle2.close();
        conOracle1.close();
        // capacity increament MySQL 2
        Connection conMysql1 = manager.getConnection("MYSQL");
        Connection conMysql2 = manager.getConnection("MYSQL");
        Connection conMysql3 = manager.getConnection("MYSQL");
        bean = manager.getPoolStatistics("MYSQL");
        assertEquals("Pool Name", "MYSQL", bean.getPoolName());
        assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount());
        assertEquals("Connections High Count", 3, bean.getConnectionsHighCount());
        assertEquals("Current Free Connections", 0, bean.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 3, bean.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 0, bean.getLeakedResultSetCount());
        Connection conMysql4 = manager.getConnection("MYSQL");
        bean = manager.getPoolStatistics("MYSQL");
        assertEquals("Pool Name", "MYSQL", bean.getPoolName());
        assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount());
        assertEquals("Connections High Count", 4, bean.getConnectionsHighCount());
        assertEquals("Current Free Connections", 1, bean.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 4, bean.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 0, bean.getLeakedResultSetCount());
        conMysql1.close();
        conMysql2.close();
        conMysql3.close();
        conMysql4.close();
        manager.destroy(true);
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail("Caught ConfigurationException");
    } catch (ParseException e) {
        e.printStackTrace();
        fail("Caught ParseException");
    } catch (IOException e) {
        e.printStackTrace();
        fail("Caught IOException");
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Caught SQLException");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        fail("Caught ClassNotFoundException");
    }
    System.out.println("testCapacityIncreament end.");
}

From source file:jdbc.pool.JDBCPoolOracleConnectionTest.java

public void testGetAllPoolStatistics() {
    testGetInstanceNull();//w ww  . j a v a 2s.co m
    System.out.println("testGetAllPoolStatistics Started");
    try {
        CConnectionPoolManager manager = null;
        manager = create();
        Connection con = manager.getConnection("ORACLE");
        CPoolStatisticsBean beanOracle = manager.getPoolStatistics("ORACLE");
        assertEquals("pool name", "ORACLE", beanOracle.getPoolName());
        assertEquals("Bad Connections Count", 0, beanOracle.getBadConnectionCount());
        assertEquals("Connections High Count", 1, beanOracle.getConnectionsHighCount());
        assertEquals("Current Free Connections", 0, beanOracle.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 1, beanOracle.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, beanOracle.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, beanOracle.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 0, beanOracle.getLeakedResultSetCount());

        //
        CPoolStatisticsBean beanMySQL = manager.getPoolStatistics("MYSQL");
        assertEquals("pool name", "MYSQL", beanMySQL.getPoolName());
        assertEquals("Bad Connections Count", 0, beanMySQL.getBadConnectionCount());
        assertEquals("Connections High Count", 0, beanMySQL.getConnectionsHighCount());
        assertEquals("Current Free Connections", 3, beanMySQL.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 0, beanMySQL.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, beanMySQL.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, beanMySQL.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 0, beanMySQL.getLeakedResultSetCount());
        con.close();
        manager.destroy(true);
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail("Caught ConfigurationException");
    } catch (ParseException e) {
        e.printStackTrace();
        fail("Caught ParseException");
    } catch (IOException e) {
        e.printStackTrace();
        fail("Caught IOException");
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Caught SQLException");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        fail("Caught ClassNotFoundException");
    }
    System.out.println("testGetAllPoolStatistics end");
}

From source file:jdbc.pool.JDBCPoolOracleConnectionTest.java

/**
 * Test if JDBC connection is getting closed after crossing the maximum
 * usage per JDBC connection.//from w  ww  . ja  va 2 s  .com
 * 
 */
public void testMaxUsagePerJDBCConnection() {
    System.out.println("testMaxUsagePerJDBCConnection start.");
    testGetInstanceNull();
    try {
        CConnectionPoolManager manager = create();
        Connection realCon = null;
        Connection con = manager.getConnection("ORACLE");
        if (con instanceof ConnectionWrapper) {
            ConnectionWrapper wrapper = (ConnectionWrapper) con;
            realCon = wrapper.realConnection();
        } else {
            fail("Connection returned is not an instance of ConnectionWrapper");
        }
        con.close();
        assertFalse("Connection must be active", realCon.isClosed());
        // 2
        con = manager.getConnection("ORACLE");
        con.close();
        assertFalse("Connection must be active", realCon.isClosed());
        // 3
        con = manager.getConnection("ORACLE");
        con.close();
        assertFalse("Connection must be active", realCon.isClosed());
        // 4
        con = manager.getConnection("ORACLE");
        con.close();
        assertTrue("Connection must be closed", realCon.isClosed());
        manager.destroy(true);
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail("Caught ConfigurationException");
    } catch (ParseException e) {
        e.printStackTrace();
        fail("Caught ParseException");
    } catch (IOException e) {
        e.printStackTrace();
        fail("Caught IOException");
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Caught SQLException");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        fail("Caught ClassNotFoundException");
    }
    System.out.println("testMaxUsagePerJDBCConnection end.");
}

From source file:jdbc.pool.JDBCPoolTestCase.java

public synchronized void testGetConnection() {
    System.out.println("testGetConnection Start.");
    CConnectionPoolManager manager = null;
    try {/*from www. j  a v a  2 s. c  o  m*/
        manager = create();
        CPoolStatisticsBean bean = manager.getPoolStatistics("MYSQL");
        assertEquals("Pool Name", "MYSQL", bean.getPoolName());
        assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount());
        assertEquals("Connections High Count", 0, bean.getConnectionsHighCount());
        assertEquals("Current Free Connections", 3, bean.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 0, bean.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 0, bean.getLeakedResultSetCount());

        Connection con = manager.getConnection("MYSQL");
        bean = manager.getPoolStatistics("MYSQL");
        assertEquals("Pool Name", "MYSQL", bean.getPoolName());
        assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount());
        assertEquals("Connections High Count", 1, bean.getConnectionsHighCount());
        assertEquals("Current Free Connections", 2, bean.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 1, bean.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 0, bean.getLeakedResultSetCount());
        con.close();
        bean = manager.getPoolStatistics("MYSQL");
        assertEquals("Pool Name", "MYSQL", bean.getPoolName());
        assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount());
        assertEquals("Connections High Count", 1, bean.getConnectionsHighCount());
        assertEquals("Current Free Connections", 3, bean.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 0, bean.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 0, bean.getLeakedResultSetCount());
        Connection con1 = manager.getConnection("MYSQL");
        Connection con2 = manager.getConnection("MYSQL");
        bean = manager.getPoolStatistics("MYSQL");
        assertEquals("Pool Name", "MYSQL", bean.getPoolName());
        assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount());
        assertEquals("Connections High Count", 2, bean.getConnectionsHighCount());
        assertEquals("Current Free Connections", 1, bean.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 2, bean.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 0, bean.getLeakedResultSetCount());
        con1.close();
        con2.close();
        bean = manager.getPoolStatistics("MYSQL");
        assertEquals("Pool Name", "MYSQL", bean.getPoolName());
        assertEquals("Bad Connections Count", 0, bean.getBadConnectionCount());
        assertEquals("Connections High Count", 2, bean.getConnectionsHighCount());
        assertEquals("Current Free Connections", 3, bean.getCurrentFreeConnectionCount());
        assertEquals("Current Used Connection count", 0, bean.getCurrentUsedConnectionCount());
        assertEquals("Leaked Connection Count", 0, bean.getLeakedConnectionCount());
        assertEquals("Leaked Statement Count", 0, bean.getLeakedStatementCount());
        assertEquals("Leaked ResultSet Count", 0, bean.getLeakedResultSetCount());

        manager.destroy(true);
        testGetInstanceNull();

    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail("Caught ConfigurationException");
    } catch (ParseException e) {
        e.printStackTrace();
        fail("Caught ParseException");
    } catch (IOException e) {
        e.printStackTrace();
        fail("Caught IOException");
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Caught SQLException");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        fail("Caught ClassNotFoundException");
    } finally {
        if (manager != null)
            manager.destroy(true);
        testGetInstanceNull();
    }
    System.out.println("testGetConnection end.");
}

From source file:jdbc.pool.JDBCPoolOracleConnectionTest.java

/**
 * Tests Inactive time out closing of the JDBC Connection.
 * /*from   w w  w  .  j  a  v a2  s.c  om*/
 * Check whether the connection returns back to the pool.
 */
public void testInactiveTimeout() {
    System.out.println("testInactiveTimeout Start.");
    testGetInstanceNull();
    CConnectionPoolManager manager = null;
    try {
        manager = create();
        Connection conOra1 = manager.getConnection("ORACLE");
        Connection realCon = null;
        Connection conOra2 = manager.getConnection("ORACLE");
        if (conOra2 instanceof ConnectionWrapper) {
            ConnectionWrapper wrapper = (ConnectionWrapper) conOra2;
            realCon = wrapper.realConnection();
        } else {
            fail("Connection returned is not an instance of ConnectionWrapper");
        }
        conOra2.close();
        try {
            // 4 = 1 + 3 + (1) As the maximum time in which the con will be
            // closed is 4 have an additional 1 minute extra
            Thread.sleep(5 * 60 * 1000); // Shrink Pool Interval 1 minute + Inactive timeout 3 mins.
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }
        assertTrue("Real Connection is closed", realCon.isClosed());
        conOra1.close();
        CPoolStatisticsBean bean = manager.getPoolStatistics("ORACLE");
        assertEquals("Pool Name", "ORACLE", bean.getPoolName());
        System.out.println("********************************************************");
        ArrayList al = manager.getPoolStatisticsHistory("ORACLE");
        assertTrue("Statistics History Count", 5 >= al.size());
        for (Iterator iter = al.iterator(); iter.hasNext();) {
            CPoolStatisticsBean element = (CPoolStatisticsBean) iter.next();
            System.out.println(element.toString());
        }
        System.out.println("********************************************************");
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail("Caught ConfigurationException");
    } catch (ParseException e) {
        e.printStackTrace();
        fail("Caught ParseException");
    } catch (IOException e) {
        e.printStackTrace();
        fail("Caught IOException");
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Caught SQLException");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        fail("Caught ClassNotFoundException");
    } finally {
        manager.destroy(true);
    }
    System.out.println("testInactiveTimeout end.");
}

From source file:jdbc.pool.JDBCPoolOracleConnectionTest.java

/**
 * Test case for Statement Caching./*w ww  . j  av  a2 s.  com*/
 */
public void testStatementCaching() {
    System.out.println("testStatementCaching Start.");
    testGetInstanceNull();
    CConnectionPoolManager manager = null;
    Connection con = null; //It has 3 iniital connections.
    PreparedStatement st;
    PreparedStatement st1;
    try {
        manager = create();
        con = manager.getConnection("ORACLE");
        st = con.prepareStatement("SELECT count(*) FROM DUAL");
        PreparedStatement realPsm = null;
        if (st instanceof PreparedStatementWrapper) {
            PreparedStatementWrapper wrapper = (PreparedStatementWrapper) st;
            realPsm = (PreparedStatement) wrapper.realStatement();
        } else {
            fail("Instanceof failed");
        }
        st.execute();
        st1 = con.prepareStatement("SELECT count(*) FROM DUAL");
        if (st1 instanceof PreparedStatementWrapper) {
            PreparedStatementWrapper wrapper = (PreparedStatementWrapper) st1;
            realPsm = (PreparedStatement) wrapper.realStatement();
            assertEquals("Statement Cache", realPsm, (PreparedStatement) wrapper.realStatement());
        } else {
            con.close();
            fail("Instanceof failed");
        }
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail("Caught ConfigurationException");
    } catch (ParseException e) {
        e.printStackTrace();
        fail("Caught ParseException");
    } catch (IOException e) {
        e.printStackTrace();
        fail("Caught IOException");
    } catch (SQLException e) {
        e.printStackTrace();
        fail("Caught SQLException");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        fail("Caught ClassNotFoundException");
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (manager != null) {
            manager.destroy(true);
        }
    }
    System.out.println("testStatementCaching End.");
}