Esempio n. 1
0
  public synchronized void syncClose() throws SQLException {
    if (this.disable) {
      return;
    }

    DruidConnectionHolder holder = this.holder;
    if (holder == null) {
      if (dupCloseLogEnable) {
        LOG.error("dup close");
      }
      return;
    }

    for (ConnectionEventListener listener : holder.getConnectionEventListeners()) {
      listener.connectionClosed(new ConnectionEvent(this));
    }

    DruidAbstractDataSource dataSource = holder.getDataSource();
    List<Filter> filters = dataSource.getProxyFilters();
    if (filters.size() > 0) {
      FilterChainImpl filterChain = new FilterChainImpl(dataSource);
      filterChain.dataSource_recycle(this);
    } else {
      recycle();
    }

    this.disable = true;
  }
 /** sends a connectionClosed event. */
 void notifyListeners() {
   ConnectionEvent event = new ConnectionEvent(this);
   Object[] listeners = eventListeners.toArray();
   for (Object listener : listeners) {
     ((ConnectionEventListener) listener).connectionClosed(event);
   }
 }
  /**
   * 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);
        }
      }
    }
  }
  /**
   * 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
          }
        }
      }
    }
  }