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);
}
}
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);
}
}
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();
}
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();
}
use of javax.sql.ConnectionPoolDataSource in project derby by apache.
the class ConnectionMethodsTest method testAbortPooled.
/**
* Test the JDBC 4.1 Connection.abort(Executor) method on pooled connections.
*/
public void testAbortPooled() throws Exception {
//
if (!TestConfiguration.loadingFromJars()) {
return;
}
ConnectionPoolDataSource cpDs = J2EEDataSource.getConnectionPoolDataSource();
PooledConnection conn0 = getPooledConnection(cpDs, "user0");
PooledConnection conn1 = getPooledConnection(cpDs, "user1");
PooledConnection conn2 = getPooledConnection(cpDs, "user2");
abortVetter(conn0.getConnection(), conn1.getConnection(), conn2.getConnection());
// verify that the underlying physical connection is closed
try {
conn1.getConnection();
fail("Expected physical connection to be closed.");
} catch (SQLException se) {
assertSQLState(CLOSED_CONNECTION, se);
}
}
Aggregations