コード例 #1
0
  /**
   * Fires a new connection event on all listeners.
   *
   * @param closed <code>true</code> if <code>close</code> has been called on the connection; <code>
   *     false</code> if the <code>sqlException</code> represents an error where the connection may
   *     not longer be used.
   * @param sqlException the SQLException to pass to the listeners
   */
  public synchronized void fireConnectionEvent(boolean closed, SQLException sqlException) {
    if (_listeners.size() > 0) {
      ConnectionEvent connectionEvent = new ConnectionEvent(this, sqlException);
      Iterator iterator = _listeners.iterator();

      while (iterator.hasNext()) {
        ConnectionEventListener listener = (ConnectionEventListener) iterator.next();

        if (closed) {
          listener.connectionClosed(connectionEvent);
        } else {
          listener.connectionErrorOccurred(connectionEvent);
        }
      }
    }
  }
コード例 #2
0
  /**
   * Fires a new connection event on all listeners.
   *
   * @param closed <code>true</code> if <code>close</code> has been called on the connection; <code>
   *     false</code> if the <code>sqlException</code> represents an error where the connection may
   *     not longer be used.
   * @param sqlException the SQLException to pass to the listeners
   */
  public synchronized void fireConnectionEvent(boolean closed, SQLException sqlException) {
    if (listeners.size() > 0) {
      ConnectionEvent connectionEvent = new ConnectionEvent(this, sqlException);
      Iterator iterator = listeners.iterator();

      while (iterator.hasNext()) {
        ConnectionEventListener listener = (ConnectionEventListener) iterator.next();

        if (closed) {
          listener.connectionClosed(connectionEvent);
        } else {
          try {
            if (connection == null || connection.isClosed()) {
              listener.connectionErrorOccurred(connectionEvent);
            }
          } catch (SQLException ex) {
            // Will never occur
          }
        }
      }
    }
  }
コード例 #3
0
 public void fireConnectionEvent(int event) {
   ConnectionEvent connnectionEvent = new ConnectionEvent(this, event);
   connnectionEvent.setConnectionHandle(this.fileConnection);
   for (ConnectionEventListener listener : this.listeners) {
     switch (event) {
       case LOCAL_TRANSACTION_STARTED:
         listener.localTransactionStarted(connnectionEvent);
         break;
       case LOCAL_TRANSACTION_COMMITTED:
         listener.localTransactionCommitted(connnectionEvent);
         break;
       case LOCAL_TRANSACTION_ROLLEDBACK:
         listener.localTransactionRolledback(connnectionEvent);
         break;
       case CONNECTION_CLOSED:
         listener.connectionClosed(connnectionEvent);
         break;
       default:
         throw new IllegalArgumentException("Unknown event: " + event);
     }
   }
 }