Search in sources :

Example 46 with ConnectionPoolDataSource

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

the class cdsXid method timeoutTestDerby1144PooledDS.

/**
 * Tests for DERBY-1144
 *
 * This test tests that holdability, autocomit, and transactionIsolation
 * are reset on getConnection for PooledConnections obtaind from
 * connectionPoolDataSources
 *
 * DERBY-1134 has been filed for more comprehensive testing of client
 * connection state.
 *
 * @throws SQLException
 */
public void timeoutTestDerby1144PooledDS() throws SQLException {
    PooledConnection pc1 = null;
    // Test holdability
    ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
    pc1 = ds.getPooledConnection();
    assertPooledConnHoldability("PooledConnection", pc1);
    pc1.close();
    // Test autocommit
    pc1 = ds.getPooledConnection();
    assertPooledConnAutoCommit("PooledConnection", pc1);
    pc1.close();
    // Test pooled connection isolation
    pc1 = ds.getPooledConnection();
    assertPooledConnIso("PooledConnection", pc1);
    pc1.close();
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection)

Example 47 with ConnectionPoolDataSource

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

the class cdsXid method testClientTraceFileDSConnectionAttribute.

/**
 * Check that traceFile connection attribute functions correctly.
 * tracefile was tested in checkDriver, but not for DataSources.
 * tracefile= was used in datasourcepermissions_net, but that's
 * incorrect syntax. Note that we're not checking the contents of
 * the tracefile.
 *
 * Note also that this test cannot run against a remote server.
 * <p>
 * This is also a regression test for DERBY-4717.
 *
 * @throws SQLException
 */
public void testClientTraceFileDSConnectionAttribute() throws SQLException {
    String traceFile;
    // with ConnectionPoolDataSource
    ConnectionPoolDataSource cpds = J2EEDataSource.getConnectionPoolDataSource();
    traceFile = "trace3.out";
    JDBCDataSource.setBeanProperty(cpds, "connectionAttributes", "traceFile=" + traceFile);
    // DERBY-2468 - trace3.out does not get created
    ((PooledConnection) getPhysicalConnection(cpds)).close();
    JDBCDataSource.clearStringBeanProperty(cpds, "connectionAttributes");
    traceFile = "trace4.out";
    JDBCDataSource.setBeanProperty(cpds, "traceFile", traceFile);
    ((PooledConnection) getPhysicalConnection(cpds)).close();
    cpds = null;
    // now with XADataSource
    XADataSource xads = J2EEDataSource.getXADataSource();
    traceFile = "trace5.out";
    JDBCDataSource.setBeanProperty(xads, "connectionAttributes", "traceFile=" + traceFile);
    ((XAConnection) getPhysicalConnection(xads)).close();
    // DERBY-2468 - trace5.out does not get created
    JDBCDataSource.clearStringBeanProperty(xads, "connectionAttributes");
    traceFile = "trace6.out";
    JDBCDataSource.setBeanProperty(xads, "traceFile", traceFile);
    ((XAConnection) getPhysicalConnection(xads)).close();
    assertTraceFilesExistAndCanBeDeleted();
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection) XADataSource(javax.sql.XADataSource) XAConnection(javax.sql.XAConnection)

Example 48 with ConnectionPoolDataSource

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

the class PoolDSAuthenticationTest method assertConnectionOK.

protected void assertConnectionOK(String dbName, String user, String password) throws SQLException {
    ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
    JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
    pds.getPooledConnection(user, password).close();
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource)

Example 49 with ConnectionPoolDataSource

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

the class PoolDSAuthenticationTest method assertShutdownWOUPOK.

protected void assertShutdownWOUPOK(String dbName, String user, String password) throws SQLException {
    ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
    JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(pds, "user", user);
    JDBCDataSource.setBeanProperty(pds, "password", password);
    JDBCDataSource.setBeanProperty(pds, "shutdownDatabase", "shutdown");
    try {
        pds.getPooledConnection();
        fail("expected a failed shutdown connection");
    } catch (SQLException e) {
        // expect 08006 on successful shutdown
        assertSQLState("08006", e);
    }
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) SQLException(java.sql.SQLException)

Example 50 with ConnectionPoolDataSource

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

the class PoolDSAuthenticationTest method assertSystemShutdownOK.

// using an empty dbName is interpreted as system shutdown
protected void assertSystemShutdownOK(String dbName, String user, String password) throws SQLException {
    ConnectionPoolDataSource pds = J2EEDataSource.getConnectionPoolDataSource();
    JDBCDataSource.clearStringBeanProperty(pds, "databaseName");
    JDBCDataSource.setBeanProperty(pds, "shutdownDatabase", "shutdown");
    JDBCDataSource.setBeanProperty(pds, "databaseName", dbName);
    JDBCDataSource.setBeanProperty(pds, "user", user);
    JDBCDataSource.setBeanProperty(pds, "password", password);
    try {
        pds.getPooledConnection();
        fail("expected system shutdown resulting in XJ015 error");
    } catch (SQLException e) {
        // expect XJ015, system shutdown, on successful shutdown
        assertSQLState("XJ015", e);
    }
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) SQLException(java.sql.SQLException)

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