boolean closeAndRemoveResourcesInSet(Set s, Method closeMethod) {
    boolean okay = true;

    Set temp;
    synchronized (s) {
      temp = new HashSet(s);
    }

    for (Iterator ii = temp.iterator(); ii.hasNext(); ) {
      Object rsrc = ii.next();
      try {
        closeMethod.invoke(rsrc, CLOSE_ARGS);
      } catch (Exception e) {
        Throwable t = e;
        if (t instanceof InvocationTargetException)
          t = ((InvocationTargetException) e).getTargetException();
        logger.log(MLevel.WARNING, "An exception occurred while cleaning up a resource.", t);
        // t.printStackTrace();
        okay = false;
      } finally {
        s.remove(rsrc);
      }
    }

    // We had to abandon the idea of simply iterating over s directly, because
    // our resource close methods sometimes try to remove the resource from
    // its parent Set. This is important (when the user closes the resources
    // directly), but leads to ConcurrenModificationExceptions while we are
    // iterating over the Set to close. So, now we iterate over a copy, but remove
    // from the original Set. Since removal is idempotent, it don't matter if
    // the close method already provoked a remove. Sucks that we have to copy
    // the set though.
    //
    // Original (direct iteration) version:
    //
    //  	synchronized (s)
    //  	    {
    //  		for (Iterator ii = s.iterator(); ii.hasNext(); )
    //  		    {
    //  			Object rsrc = ii.next();
    //  			try
    //  			    { closeMethod.invoke(rsrc, CLOSE_ARGS); }
    //  			catch (Exception e)
    //  			    {
    //  				Throwable t = e;
    //  				if (t instanceof InvocationTargetException)
    //  				    t = ((InvocationTargetException) e).getTargetException();
    //  				t.printStackTrace();
    //  				okay = false;
    //  			    }
    //  			finally
    //  			    { ii.remove(); }
    //  		    }
    //  	    }

    return okay;
  }
  public void fireStatementErrorOccurred(PreparedStatement ps, SQLException error) {
    Set mlCopy;

    synchronized (this) {
      mlCopy = (Set) mlisteners.clone();
    }

    StatementEvent evt = new StatementEvent(source, ps, error);
    for (Iterator i = mlCopy.iterator(); i.hasNext(); ) {
      StatementEventListener cl = (StatementEventListener) i.next();
      cl.statementErrorOccurred(evt);
    }
  }
 boolean closeAndRemoveResultSets(Set rsSet) {
   boolean okay = true;
   synchronized (rsSet) {
     for (Iterator ii = rsSet.iterator(); ii.hasNext(); ) {
       ResultSet rs = (ResultSet) ii.next();
       try {
         rs.close();
       } catch (SQLException e) {
         if (Debug.DEBUG)
           logger.log(MLevel.WARNING, "An exception occurred while cleaning up a ResultSet.", e);
         // e.printStackTrace();
         okay = false;
       } finally {
         ii.remove();
       }
     }
   }
   return okay;
 }
    private Exception doSilentClose(
        Object proxyConnection, boolean pooled_connection_is_dead, boolean known_resolved_txn) {
      if (activeConnection != null) {
        synchronized (
            C3P0PooledConnection
                .this) // uh oh... this is a nested lock acq... is there a deadlock hazard here?
        {
          if (C3P0PooledConnection.this.exposedProxy == proxyConnection) {
            C3P0PooledConnection.this.exposedProxy = null;
            // System.err.println("Reset exposed proxy.");

            // DEBUG
            // origGet = null;
          } else // else case -- DEBUG only
          logger.warning(
                "(c3p0 issue) doSilentClose( ... ) called on a proxyConnection "
                    + "other than the current exposed proxy for its PooledConnection. [exposedProxy: "
                    + exposedProxy
                    + ", proxyConnection: "
                    + proxyConnection);
          // 				System.err.println("[DEBUG] WARNING: doSilentClose( ... ) called on a
          // proxyConnection " +
          // 						   "other than the current exposed proxy for its PooledConnection. [exposedProxy:
          // " +
          // 						   exposedProxy + ", proxyConnection: " + proxyConnection);
        }

        Exception out = null;

        Exception exc1 = null, exc2 = null, exc3 = null, exc4 = null;
        try {
          if (!pooled_connection_is_dead) C3P0PooledConnection.this.reset(known_resolved_txn);
        } catch (Exception e) {
          exc1 = e;
          // 		    if (Debug.DEBUG)
          // 			{
          // 			    System.err.print("exc1 -- ");
          // 			    exc1.printStackTrace();
          // 			}
        }

        exc2 = cleanupUncachedActiveStatements();
        // 	    if (Debug.DEBUG && exc2 != null)
        // 		{
        // 		    System.err.print("exc2 -- ");
        // 		    exc2.printStackTrace();
        // 		}
        String errSource;
        if (doRawResultSets != null) {
          activeMetaDataResultSets.addAll(doRawResultSets);
          errSource = "DataBaseMetaData or raw Connection operation";
        } else errSource = "DataBaseMetaData";

        if (!closeAndRemoveResultSets(activeMetaDataResultSets))
          exc3 = new SQLException("Failed to close some " + errSource + " Result Sets.");
        // 	    if (Debug.DEBUG && exc3 != null)
        // 		{
        // 		    System.err.print("exc3 -- ");
        // 		    exc3.printStackTrace();
        // 		}
        if (scache != null) {
          try {
            scache.checkinAll(physicalConnection);
          } catch (Exception e) {
            exc4 = e;
          }
          // 		    if (Debug.DEBUG && exc4 != null)
          // 			{
          // 			    System.err.print("exc4 -- ");
          // 			    exc4.printStackTrace();
          // 			}
        }

        if (exc1 != null) {
          handleMaybeFatalToPooledConnection(exc1, proxyConnection, true);
          out = exc1;
        } else if (exc2 != null) {
          handleMaybeFatalToPooledConnection(exc2, proxyConnection, true);
          out = exc2;
        } else if (exc3 != null) {
          handleMaybeFatalToPooledConnection(exc3, proxyConnection, true);
          out = exc3;
        } else if (exc4 != null) {
          handleMaybeFatalToPooledConnection(exc4, proxyConnection, true);
          out = exc4;
        }

        // 	    if (out != null)
        // 		{
        // 		    System.err.print("out -- ");
        // 		    out.printStackTrace();
        // 		}

        activeConnection = null;
        return out;
      } else return null;
    }