Search in sources :

Example 21 with ConnectionPoolDataSource

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

the class PoolDSAuthenticationTest method assertShutdownWOUPFail.

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

Example 22 with ConnectionPoolDataSource

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

the class RolesTest method testCurrentRoleIsReset.

/**
 * Verifies that the current role 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>
 * The test pattern is borrowed from the test case in J2EEDataSourceTest.
 *
 * @see org.apache.derbyTesting.functionTests.tests.jdbcapi.J2EEDataSourceTest#testSchemaIsReset
 *
 * @throws SQLException if something goes wrong
 */
private void testCurrentRoleIsReset() throws SQLException {
    if (_authLevel == SQLAUTHORIZATION && isDbo()) /* once is enough */
    {
        final String user = "DonaldDuck";
        final String passwd = user.concat(pwSuffix);
        ConnectionPoolDataSource cpDs = J2EEDataSource.getConnectionPoolDataSource();
        // Test without statement pooling first.
        doTestCurrentRoleIsReset(cpDs.getPooledConnection(user, passwd), user);
        // This is currently only implemented in the client driver.
        if (usingDerbyNetClient()) {
            J2EEDataSource.setBeanProperty(cpDs, "maxStatements", 7);
            doTestCurrentRoleIsReset(cpDs.getPooledConnection(user, passwd), user);
        }
    }
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource)

Example 23 with ConnectionPoolDataSource

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

the class ConnectionPoolDataSourceConnector method singleUseDS.

/**
 * Get a connection from a single use ConnectionPoolDataSource configured
 * from the configuration but with the passed in property set.
 */
private ConnectionPoolDataSource singleUseDS(HashMap hm) throws SQLException {
    ConnectionPoolDataSource sds = J2EEDataSource.getConnectionPoolDataSource(config, hm);
    // Enable statement pooling by default for single-use data sources
    // too, just like it's enabled for the default data source in
    // setConfiguration().
    enableStatementPooling(sds);
    return sds;
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource)

Example 24 with ConnectionPoolDataSource

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

the class ConnectionPoolDataSourceConnector method shutEngine.

public void shutEngine(boolean deregisterDriver) throws SQLException {
    if (SanityManager.DEBUG) {
        // "false" only used with driver manager
        SanityManager.ASSERT(deregisterDriver);
    }
    ConnectionPoolDataSource tmpDs = singleUseDS(DataSourceConnector.makeShutdownDBAttributes(config));
    JDBCDataSource.setBeanProperty(tmpDs, "databaseName", "");
    tmpDs.getPooledConnection();
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource)

Example 25 with ConnectionPoolDataSource

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

the class NSSecurityMechanismTest method assertSecMecWithConnPoolingOK.

/**
 * Test a deferred connection reset. When connection pooling is done
 * and connection is reset, the client sends EXCSAT,ACCSEC and followed
 * by SECCHK and ACCRDB. Test if the security mechanism related information
 * is correctly reset or not. This method was added to help simulate
 * regression test for DERBY-1080. It is called from testDerby1080.
 * @param user username
 * @param password password for connection
 * @param secmec security mechanism for datasource
 * @throws Exception
 */
private void assertSecMecWithConnPoolingOK(String user, String password, Short secmec) throws Exception {
    ConnectionPoolDataSource cpds = getCPDS(user, password);
    // call setSecurityMechanism with secmec.
    JDBCDataSource.setBeanProperty(cpds, "SecurityMechanism", secmec);
    // simulate case when connection will be re-used by getting
    // a connection, closing it and then the next call to
    // getConnection will re-use the previous connection.
    PooledConnection pc = cpds.getPooledConnection();
    Connection conn = pc.getConnection();
    conn.close();
    conn = pc.getConnection();
    assertConnectionOK(conn);
    pc.close();
    conn.close();
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) PooledConnection(javax.sql.PooledConnection) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection)

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