Search in sources :

Example 61 with ConnectionPoolDataSource

use of javax.sql.ConnectionPoolDataSource in project derby by apache.

the class DataSourceTest method test_jdbc4_1.

/**
 * <p>
 * Test the new method added by JDBC 4.1.
 * </p>
 */
public void test_jdbc4_1() throws Exception {
    DataSource ds = JDBCDataSource.getDataSource();
    ConnectionPoolDataSource cpds = J2EEDataSource.getConnectionPoolDataSource();
    XADataSource xads = J2EEDataSource.getXADataSource();
    vetDSjdbc4_1(ds);
    vetDSjdbc4_1(cpds);
    vetDSjdbc4_1(xads);
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) XADataSource(javax.sql.XADataSource) ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) XADataSource(javax.sql.XADataSource) J2EEDataSource(org.apache.derbyTesting.junit.J2EEDataSource) CommonDataSource(javax.sql.CommonDataSource) DataSource(javax.sql.DataSource) JDBCDataSource(org.apache.derbyTesting.junit.JDBCDataSource)

Example 62 with ConnectionPoolDataSource

use of javax.sql.ConnectionPoolDataSource in project derby by apache.

the class DataSourceTest method testUnwrapConnectionPoolDataSource.

public void testUnwrapConnectionPoolDataSource() {
    try {
        ConnectionPoolDataSource cpds = ds.unwrap(ConnectionPoolDataSource.class);
        fail("Unwrap didn't fail.");
    } catch (SQLException e) {
        assertSQLState("XJ128", e);
    }
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) SQLException(java.sql.SQLException)

Example 63 with ConnectionPoolDataSource

use of javax.sql.ConnectionPoolDataSource in project derby by apache.

the class DataSourceTest method testConnectionErrorEvent.

/**
 * Test case for DERBY-3172
 * When the Derby engine is shutdown or Network Server is brought down, any
 * api on JDBC Connection object should generate a Connection error event.
 */
public void testConnectionErrorEvent() throws SQLException, Exception {
    AssertEventCatcher aes12 = new AssertEventCatcher(12);
    // Get the correct ConnectionPoolDataSource object
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
    PooledConnection pc = ds.getPooledConnection();
    // Add a connection event listener to ConnectionPoolDataSource
    pc.addConnectionEventListener(aes12);
    Connection conn = pc.getConnection();
    dropTable(conn, "TAB1");
    // No event should have been generated at this point
    assertFalse(aes12.didConnectionClosedEventHappen());
    assertFalse(aes12.didConnectionErrorEventHappen());
    aes12.resetState();
    // mode we are running in.
    if (usingEmbedded()) {
        getTestConfiguration().shutdownDatabase();
    } else {
        getTestConfiguration().stopNetworkServer();
    }
    // before shutdown and they all should generate connection error event.
    try {
        conn.createArrayOf("junk", null);
    } catch (SQLException e) {
        assertSQLState("0A000", e);
    }
    try {
        conn.createNClob();
    } catch (SQLException e) {
        assertSQLState("0A000", e);
    }
    try {
        conn.createSQLXML();
    } catch (SQLException e) {
        assertSQLState("0A000", e);
    }
    try {
        conn.createStruct("junk", null);
    } catch (SQLException e) {
        assertSQLState("0A000", e);
    }
    try {
        conn.createBlob();
    } catch (SQLException e) {
        // meaning No current connection
        if (usingEmbedded())
            assertSQLState("08003", e);
        else
            assertSQLState("08006", e);
    }
    assertFalse(aes12.didConnectionClosedEventHappen());
    assertTrue(aes12.didConnectionErrorEventHappen());
    aes12.resetState();
    try {
        conn.createClob();
    } catch (SQLException e) {
        assertSQLState("08003", e);
    }
    assertFalse(aes12.didConnectionClosedEventHappen());
    assertTrue(aes12.didConnectionErrorEventHappen());
    aes12.resetState();
    try {
        conn.getClientInfo();
    } catch (SQLException e) {
        assertSQLState("08003", e);
    }
    assertFalse(aes12.didConnectionClosedEventHappen());
    assertTrue(aes12.didConnectionErrorEventHappen());
    aes12.resetState();
    try {
        conn.getClientInfo("junk");
    } catch (SQLException e) {
        assertSQLState("08003", e);
    }
    assertFalse(aes12.didConnectionClosedEventHappen());
    assertTrue(aes12.didConnectionErrorEventHappen());
    aes12.resetState();
    try {
        conn.setClientInfo(null);
    } catch (SQLException e) {
        assertSQLState("08003", e);
    }
    assertFalse(aes12.didConnectionClosedEventHappen());
    assertTrue(aes12.didConnectionErrorEventHappen());
    aes12.resetState();
    try {
        conn.setClientInfo("junk1", "junk2");
    } catch (SQLException e) {
        assertSQLState("08003", e);
    }
    assertFalse(aes12.didConnectionClosedEventHappen());
    assertTrue(aes12.didConnectionErrorEventHappen());
    aes12.resetState();
    try {
        conn.isWrapperFor(this.getClass());
    } catch (SQLException e) {
        assertSQLState("08003", e);
    }
    assertFalse(aes12.didConnectionClosedEventHappen());
    if (usingEmbedded())
        assertTrue(aes12.didConnectionErrorEventHappen());
    else
        // We do not make any call on underneath JDBC Connection
        // object for isWrapperFor and hence never get Connection
        // Error event
        assertFalse(aes12.didConnectionErrorEventHappen());
    aes12.resetState();
    try {
        conn.unwrap(this.getClass());
    } catch (SQLException e) {
        if (usingEmbedded())
            assertSQLState("08003", e);
        else
            // We do not make any call on underneath JDBC Connection
            // object for unwrap and hence never get Connection
            // closed exception. Instead we got exception because
            // client driver code is trying to unwrap this.getClass
            // and it can't do that
            assertSQLState("XJ128", e);
    }
    assertFalse(aes12.didConnectionClosedEventHappen());
    if (usingEmbedded())
        assertTrue(aes12.didConnectionErrorEventHappen());
    else
        // We do not make any call on underneath JDBC Connection
        // object for isWrapperFor and hence never get Connection
        // Error event
        assertFalse(aes12.didConnectionErrorEventHappen());
    aes12.resetState();
    try {
        conn.isValid(5);
    } catch (SQLException e) {
        assertSQLState("08003", e);
    }
    if (usingEmbedded())
        assertTrue(aes12.didConnectionClosedEventHappen());
    else
        assertFalse(aes12.didConnectionClosedEventHappen());
    // As per the JDBC definition, an exception and hence an event is raised
    // for isValid only if the param value is illegal
    assertFalse(aes12.didConnectionErrorEventHappen());
    aes12.resetState();
    Class<?> clazz;
    if (usingEmbedded()) {
        clazz = Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        clazz.getConstructor().newInstance();
    } else {
        getTestConfiguration().startNetworkServer();
    }
    // Get a new connection to the database
    conn = getConnection();
    conn.close();
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection) AssertEventCatcher(org.apache.derbyTesting.functionTests.tests.jdbcapi.AssertEventCatcher) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection)

Example 64 with ConnectionPoolDataSource

use of javax.sql.ConnectionPoolDataSource in project derby by apache.

the class JDBC4FromJDBC3DataSourceTest method testPooledConnection.

/**
 * Test that a JDBC 3 data source returns a JDBC 4 PooledConnection
 * when running with a JDBC 4 JDK.
 */
public void testPooledConnection() throws Exception {
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
    checkJDBC4Interface(ds.getPooledConnection());
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource)

Example 65 with ConnectionPoolDataSource

use of javax.sql.ConnectionPoolDataSource in project pgjdbc by pgjdbc.

the class PGDataSourceFactoryTest method testCreateConnectionPoolDataSourceDefault.

@Test
public void testCreateConnectionPoolDataSourceDefault() throws Exception {
    ConnectionPoolDataSource dataSource = dataSourceFactory.createConnectionPoolDataSource(null);
    Assert.assertNotNull(dataSource);
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) Test(org.junit.Test)

Aggregations

ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)72 PooledConnection (javax.sql.PooledConnection)34 SQLException (java.sql.SQLException)28 Connection (java.sql.Connection)19 XAConnection (javax.sql.XAConnection)15 XADataSource (javax.sql.XADataSource)12 Statement (java.sql.Statement)9 CallableStatement (java.sql.CallableStatement)7 DataSource (javax.sql.DataSource)7 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 J2EEDataSource (org.apache.derbyTesting.junit.J2EEDataSource)6 JDBCDataSource (org.apache.derbyTesting.junit.JDBCDataSource)6 Context (javax.naming.Context)5 InitialContext (javax.naming.InitialContext)5 Properties (java.util.Properties)3 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 Savepoint (java.sql.Savepoint)2 SQLiteConnectionPoolDataSource (org.sqlite.javax.SQLiteConnectionPoolDataSource)2