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);
}
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);
}
}
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();
}
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());
}
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);
}
Aggregations