use of javax.sql.ConnectionEventListener in project druid by alibaba.
the class DruidDataSourceTest_getPooledConnection method test_event_error.
public void test_event_error() throws Exception {
DruidPooledConnection conn = (DruidPooledConnection) dataSource.getPooledConnection();
final AtomicInteger errorCount = new AtomicInteger();
conn.addConnectionEventListener(new ConnectionEventListener() {
@Override
public void connectionErrorOccurred(ConnectionEvent event) {
errorCount.incrementAndGet();
}
@Override
public void connectionClosed(ConnectionEvent event) {
}
});
PreparedStatement stmt = conn.prepareStatement("select ?");
try {
stmt.executeQuery();
} catch (SQLException e) {
}
Assert.assertEquals(1, errorCount.get());
conn.close();
}
use of javax.sql.ConnectionEventListener in project druid by alibaba.
the class ConnectionTest5 method test_handleException_5.
public void test_handleException_5() throws Exception {
DruidPooledConnection conn = dataSource.getConnection().unwrap(DruidPooledConnection.class);
conn.addConnectionEventListener(new ConnectionEventListener() {
@Override
public void connectionClosed(ConnectionEvent event) {
}
@Override
public void connectionErrorOccurred(ConnectionEvent event) {
}
});
conn.close();
{
SQLException error = null;
try {
conn.handleException(new RuntimeException());
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
}
use of javax.sql.ConnectionEventListener in project voltdb by VoltDB.
the class LifeTimeConnectionWrapper method fireSqlExceptionEvent.
protected void fireSqlExceptionEvent(SQLException e) {
ConnectionEvent event = new ConnectionEvent(this.pooledConnection, e);
for (Iterator iterator = connectionListeners.iterator(); iterator.hasNext(); ) {
ConnectionEventListener connectionEventListener = (ConnectionEventListener) iterator.next();
connectionEventListener.connectionErrorOccurred(event);
}
}
Aggregations