Search in sources :

Example 51 with ConnectionPoolDataSource

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

the class cdsXid method testConnectionFlowCommit.

/**
 * check whether commit without statement will flow by checking its transaction id
 * on client. This test is run only for client where commits without an
 * active transactions will not flow to the server.
 * DERBY-4653
 *
 * @throws SQLException
 */
public void testConnectionFlowCommit() throws SQLException {
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
    PooledConnection pc = ds.getPooledConnection();
    Connection conn = pc.getConnection();
    testConnectionFlowCommitWork(conn);
    conn.close();
    // Test for XADataSource
    XADataSource xs = J2EEDataSource.getXADataSource();
    XAConnection xc = xs.getXAConnection();
    conn = xc.getConnection();
    testConnectionFlowCommitWork(conn);
    conn.close();
    // Test for DataSource
    DataSource jds = JDBCDataSource.getDataSource();
    conn = jds.getConnection();
    testConnectionFlowCommitWork(conn);
    conn.close();
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection) XADataSource(javax.sql.XADataSource) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) XAConnection(javax.sql.XAConnection) XADataSource(javax.sql.XADataSource) J2EEDataSource(org.apache.derbyTesting.junit.J2EEDataSource) DataSource(javax.sql.DataSource) ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) JDBCDataSource(org.apache.derbyTesting.junit.JDBCDataSource)

Example 52 with ConnectionPoolDataSource

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

the class cdsXid method testConnectionLeakInDatabaseMetaData.

/**
 * Tests that DatabaseMetaData.getConnection does not leak references to
 * physical connections or other logical connections.
 *
 * @throws SQLException if something goes wrong
 */
public void testConnectionLeakInDatabaseMetaData() throws SQLException {
    ConnectionPoolDataSource cpDs = J2EEDataSource.getConnectionPoolDataSource();
    PooledConnection pc = cpDs.getPooledConnection();
    // Get first logical connection and a meta data object.
    Connection con1 = pc.getConnection();
    DatabaseMetaData dmd1 = con1.getMetaData();
    assertSame(con1, dmd1.getConnection());
    con1.close();
    // Get second logical connection and a meta data object.
    Connection con2 = pc.getConnection();
    DatabaseMetaData dmd2 = con2.getMetaData();
    // The first meta data object should not return a reference to the
    // second logical connection.
    assertSame(con2, dmd2.getConnection());
    try {
        dmd1.getConnection();
        fail("Should have thrown no current connection exception");
    } catch (SQLException sqle) {
        assertSQLState("08003", sqle);
    }
    con2.close();
    pc.close();
    try {
        dmd2.getConnection();
        fail("Should have thrown no current connection exception");
    } catch (SQLException sqle) {
        assertSQLState("08003", sqle);
    }
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection) SQLException(java.sql.SQLException) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 53 with ConnectionPoolDataSource

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

the class cdsXid method testSchemaIsReset.

/**
 * Verifies that the schema is reset when creating a new logical connection.
 * <p>
 * The test is run in a non-statement pooling configuration first,
 * and then with statement pooling enabled if the environment supports it.
 * <p>
 * Relevant Jira issue: DERBY-3690.
 * <p>
 * The current role also needs to be reset, but can't be tested here since
 * we need to run with SQL authorization.
 *
 * @see org.apache.derbyTesting.functionTests.tests.lang.RolesTest#testCurrentRoleIsReset
 *
 * @throws SQLException if something goes wrong
 */
public void testSchemaIsReset() throws SQLException {
    final String userSchema = "USERSCHEMA";
    ConnectionPoolDataSource cpDs = J2EEDataSource.getConnectionPoolDataSource();
    J2EEDataSource.setBeanProperty(cpDs, "createDatabase", "create");
    // Connect with a user specified, which should cause the schema to be
    // set to the user name.
    // Test without statement pooling first.
    doTestSchemaIsReset(cpDs.getPooledConnection(userSchema, "secret"), userSchema);
    // This is currently only implemented in the client driver.
    if (usingDerbyNetClient()) {
        J2EEDataSource.setBeanProperty(cpDs, "maxStatements", 7);
        doTestSchemaIsReset(cpDs.getPooledConnection(userSchema, "secret"), userSchema);
    }
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource)

Example 54 with ConnectionPoolDataSource

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

the class cdsXid method testIsolationWithFourConnections.

/**
 * Check setTransactioIsolation and with four connection in connection pool
 * for DERBY-4343 case
 *
 * @throws SQLException
 */
public void testIsolationWithFourConnections() throws SQLException {
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
    PooledConnection pc = ds.getPooledConnection();
    // First connection
    Connection conn = pc.getConnection();
    conn.setAutoCommit(false);
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    Statement s = conn.createStatement();
    ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM SYS.SYSTABLES");
    rs.next();
    int ri = rs.getInt(1);
    rs.close();
    conn.rollback();
    conn.close();
    // Second connection
    conn = pc.getConnection();
    conn.close();
    // Third connection
    conn = pc.getConnection();
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    assertEquals(Connection.TRANSACTION_READ_COMMITTED, conn.getTransactionIsolation());
    conn.close();
    // Fourth connetion
    conn = pc.getConnection();
    conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    assertEquals(Connection.TRANSACTION_READ_UNCOMMITTED, conn.getTransactionIsolation());
    conn.close();
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection) ResultSet(java.sql.ResultSet) Savepoint(java.sql.Savepoint)

Example 55 with ConnectionPoolDataSource

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

the class cdsXid method testCloseActiveConnection_CP.

/**
 * Test that connections retrieved from {@code ConnectionPoolDataSource}
 * behave as expected when {@code close()} is called and the transaction is
 * active.
 */
public void testCloseActiveConnection_CP() throws SQLException {
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
    PooledConnection pc = ds.getPooledConnection();
    testCloseActiveConnection(pc.getConnection(), true, false);
    Connection c = pc.getConnection();
    c.setAutoCommit(false);
    testCloseActiveConnection(c, false, false);
    pc.close();
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PooledConnection(javax.sql.PooledConnection)

Aggregations

ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)63 PooledConnection (javax.sql.PooledConnection)29 SQLException (java.sql.SQLException)25 Connection (java.sql.Connection)17 XAConnection (javax.sql.XAConnection)15 XADataSource (javax.sql.XADataSource)12 CallableStatement (java.sql.CallableStatement)7 Statement (java.sql.Statement)7 DataSource (javax.sql.DataSource)7 PreparedStatement (java.sql.PreparedStatement)6 J2EEDataSource (org.apache.derbyTesting.junit.J2EEDataSource)6 JDBCDataSource (org.apache.derbyTesting.junit.JDBCDataSource)6 ResultSet (java.sql.ResultSet)5 Context (javax.naming.Context)3 InitialContext (javax.naming.InitialContext)3 Test (org.junit.Test)3 Savepoint (java.sql.Savepoint)2 Properties (java.util.Properties)2 JTAEnvironmentBean (com.arjuna.ats.jta.common.JTAEnvironmentBean)1 AbstractTest (com.microsoft.sqlserver.testframework.AbstractTest)1