Search in sources :

Example 1 with ConnectionEvent

use of javax.sql.ConnectionEvent in project voltdb by VoltDB.

the class LifeTimeConnectionWrapper method fireCloseEvent.

protected void fireCloseEvent() {
    ConnectionEvent connectionEvent = new ConnectionEvent(this.pooledConnection);
    for (Iterator iterator = connectionListeners.iterator(); iterator.hasNext(); ) {
        ConnectionEventListener connectionListener = (ConnectionEventListener) iterator.next();
        connectionListener.connectionClosed(connectionEvent);
    }
}
Also used : ConnectionEvent(javax.sql.ConnectionEvent) Iterator(java.util.Iterator) ConnectionEventListener(javax.sql.ConnectionEventListener)

Example 2 with ConnectionEvent

use of javax.sql.ConnectionEvent in project datanucleus-rdbms by datanucleus.

the class PooledConnectionImpl method notifyListeners.

/**
 * Sends a connectionClosed event.
 */
void notifyListeners() {
    final ConnectionEvent event = new ConnectionEvent(this);
    final Object[] listeners = eventListeners.toArray();
    for (final Object listener : listeners) {
        ((ConnectionEventListener) listener).connectionClosed(event);
    }
}
Also used : ConnectionEvent(javax.sql.ConnectionEvent) PooledObject(org.datanucleus.store.rdbms.datasource.dbcp2.pool2.PooledObject) DefaultPooledObject(org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.DefaultPooledObject) ConnectionEventListener(javax.sql.ConnectionEventListener)

Example 3 with ConnectionEvent

use of javax.sql.ConnectionEvent in project mssql-jdbc by Microsoft.

the class SQLServerPooledConnection method notifyEvent.

// Notify any interested parties (e.g. pooling managers) of a ConnectionEvent activity
// on the connection. Calling notifyEvent with null event will place the
// connection back in the pool. Calling notifyEvent with a non-null event is
// used to notify the pooling manager that the connection is bad and should be removed
// from the pool.
void notifyEvent(SQLServerException e) {
    if (pcLogger.isLoggable(Level.FINER))
        pcLogger.finer(toString() + " Exception:" + e + safeCID());
    // close the proxy on fatal error event. Note exception is null then the event comes from the proxy close.
    if (null != e) {
        synchronized (this) {
            if (null != lastProxyConnection) {
                lastProxyConnection.internalClose();
                lastProxyConnection = null;
            }
        }
    }
    // A connection handle issued from this pooled connection is closing or an error occurred in the connection
    synchronized (listeners) {
        for (int i = 0; i < listeners.size(); i++) {
            ConnectionEventListener listener = listeners.elementAt(i);
            if (listener == null)
                continue;
            ConnectionEvent ev = new ConnectionEvent(this, e);
            if (null == e) {
                if (pcLogger.isLoggable(Level.FINER))
                    pcLogger.finer(toString() + " notifyEvent:connectionClosed " + safeCID());
                listener.connectionClosed(ev);
            } else {
                if (pcLogger.isLoggable(Level.FINER))
                    pcLogger.finer(toString() + " notifyEvent:connectionErrorOccurred " + safeCID());
                listener.connectionErrorOccurred(ev);
            }
        }
    }
}
Also used : ConnectionEvent(javax.sql.ConnectionEvent) ConnectionEventListener(javax.sql.ConnectionEventListener)

Example 4 with ConnectionEvent

use of javax.sql.ConnectionEvent in project h2database by h2database.

the class JdbcXAConnection method closedHandle.

/**
 * INTERNAL
 */
void closedHandle() {
    debugCode("closedHandle();");
    ConnectionEvent event = new ConnectionEvent(this);
    // (otherwise we need to clone the list)
    for (int i = listeners.size() - 1; i >= 0; i--) {
        ConnectionEventListener listener = listeners.get(i);
        listener.connectionClosed(event);
    }
    handleConn = null;
}
Also used : ConnectionEvent(javax.sql.ConnectionEvent) ConnectionEventListener(javax.sql.ConnectionEventListener)

Example 5 with ConnectionEvent

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

the class EmbedPooledConnection method fireConnectionEventListeners.

/**
 * Fire all the {@code ConnectionEventListener}s registered. Callers must
 * synchronize on {@code this} to prevent others from modifying the list of
 * listeners.
 *
 * @param exception the exception that caused the event, or {@code null} if
 * it is a close event
 */
private void fireConnectionEventListeners(SQLException exception) {
    if (eventListener != null && !eventListener.isEmpty()) {
        ConnectionEvent event = new ConnectionEvent(this, exception);
        eventIterators++;
        try {
            for (ConnectionEventListener l : eventListener) {
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
Also used : ConnectionEvent(javax.sql.ConnectionEvent) ConnectionEventListener(javax.sql.ConnectionEventListener)

Aggregations

ConnectionEvent (javax.sql.ConnectionEvent)27 ConnectionEventListener (javax.sql.ConnectionEventListener)23 SQLException (java.sql.SQLException)10 PooledConnection (javax.sql.PooledConnection)4 XAConnection (javax.sql.XAConnection)4 Connection (java.sql.Connection)3 Iterator (java.util.Iterator)3 XAResource (javax.transaction.xa.XAResource)3 Filter (com.alibaba.druid.filter.Filter)2 FilterChainImpl (com.alibaba.druid.filter.FilterChainImpl)2 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)2 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)1 PreparedStatement (java.sql.PreparedStatement)1 Savepoint (java.sql.Savepoint)1 Statement (java.sql.Statement)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Xid (javax.transaction.xa.Xid)1 PooledObject (org.apache.tomcat.dbcp.pool2.PooledObject)1 DefaultPooledObject (org.apache.tomcat.dbcp.pool2.impl.DefaultPooledObject)1