Java Code Examples for javax.sql.ConnectionEventListener#connectionClosed()

The following examples show how to use javax.sql.ConnectionEventListener#connectionClosed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: 1205753_EmbedPooledConnection_0_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 2
Source File: 1205753_EmbedPooledConnection_0_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 3
Source File: 1205753_EmbedPooledConnection_0_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 4
Source File: 1205753_EmbedPooledConnection_0_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 5
Source File: 1205753_EmbedPooledConnection_0_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 6
Source File: 1205753_EmbedPooledConnection_0_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 7
Source File: 1205753_EmbedPooledConnection_0_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 8
Source File: 1205753_EmbedPooledConnection_0_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 9
Source File: 1205753_EmbedPooledConnection_0_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 10
Source File: 1205753_EmbedPooledConnection_0_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 11
Source File: ClientPooledConnection.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * 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 (!listeners_.isEmpty()) {
        final ConnectionEvent event = (exception == null) ?
            new ConnectionEvent(this) :
            new ConnectionEvent(this, exception.getSQLException(
                physicalConnection_ != null ? physicalConnection_
                    .agent_ : null /* GemStoneAddition */));
        eventIterators++;
        try {
            for (Iterator it = listeners_.iterator(); it.hasNext(); ) {
                final ConnectionEventListener listener =
                    (ConnectionEventListener) it.next();
                if (exception == null) {
                    listener.connectionClosed(event);
                } else {
                    listener.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 12
Source File: MysqlPooledConnection.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Notifies all registered ConnectionEventListeners of ConnectionEvents.
 * Instantiates a new ConnectionEvent which wraps sqlException and invokes
 * either connectionClose or connectionErrorOccurred on listener as
 * appropriate.
 * 
 * @param eventType
 *            value indicating whether connectionClosed or
 *            connectionErrorOccurred called
 * @param sqlException
 *            the exception being thrown
 */
protected synchronized void callConnectionEventListeners(int eventType, SQLException sqlException) {

    if (this.connectionEventListeners == null) {

        return;
    }

    Iterator<Map.Entry<ConnectionEventListener, ConnectionEventListener>> iterator = this.connectionEventListeners.entrySet().iterator();

    ConnectionEvent connectionevent = new ConnectionEvent(this, sqlException);

    while (iterator.hasNext()) {

        ConnectionEventListener connectioneventlistener = iterator.next().getValue();

        if (eventType == CONNECTION_CLOSED_EVENT) {
            connectioneventlistener.connectionClosed(connectionevent);
        } else if (eventType == CONNECTION_ERROR_EVENT) {
            connectioneventlistener.connectionErrorOccurred(connectionevent);
        }
    }
}
 
Example 13
Source File: 1205753_EmbedPooledConnection_0_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 14
Source File: 1205753_EmbedPooledConnection_0_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 15
Source File: MysqlPooledConnection.java    From Komondor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Notifies all registered ConnectionEventListeners of ConnectionEvents.
 * Instantiates a new ConnectionEvent which wraps sqlException and invokes
 * either connectionClose or connectionErrorOccurred on listener as
 * appropriate.
 * 
 * @param eventType
 *            value indicating whether connectionClosed or
 *            connectionErrorOccurred called
 * @param sqlException
 *            the exception being thrown
 */
protected synchronized void callConnectionEventListeners(int eventType, SQLException sqlException) {

    if (this.connectionEventListeners == null) {

        return;
    }

    Iterator<Map.Entry<ConnectionEventListener, ConnectionEventListener>> iterator = this.connectionEventListeners.entrySet().iterator();

    ConnectionEvent connectionevent = new ConnectionEvent(this, sqlException);

    while (iterator.hasNext()) {

        ConnectionEventListener connectioneventlistener = iterator.next().getValue();

        if (eventType == CONNECTION_CLOSED_EVENT) {
            connectioneventlistener.connectionClosed(connectionevent);
        } else if (eventType == CONNECTION_ERROR_EVENT) {
            connectioneventlistener.connectionErrorOccurred(connectionevent);
        }
    }
}
 
Example 16
Source File: 1205753_EmbedPooledConnection_0_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 17
Source File: 1205753_EmbedPooledConnection_0_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 (Iterator it = eventListener.iterator(); it.hasNext();) {
                ConnectionEventListener l =
                        (ConnectionEventListener) it.next();
                if (exception == null) {
                    l.connectionClosed(event);
                } else {
                    l.connectionErrorOccurred(event);
                }
            }
        } finally {
            eventIterators--;
        }
    }
}
 
Example 18
Source File: XAConnectionImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void connectionClosed(ConnectionEvent event) {
	Iterator<ConnectionEventListener> itr = this.connectionEventListeners.iterator();
	while (itr.hasNext()) {
		ConnectionEventListener listener = itr.next();
		SQLException sqlException = event.getSQLException();
		ConnectionEvent connectionEvent = new ConnectionEvent(this, sqlException);
		try {
			listener.connectionClosed(connectionEvent);
		} catch (RuntimeException error) {
			logger.warn("Error occurred!", error);
		}
	} // end-while (itr.hasNext())
}
 
Example 19
Source File: FBPooledConnection.java    From jaybird with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Helper method to fire the connectionClosed event.
 */
protected void fireConnectionClosed() {
    ConnectionEvent evt = new ConnectionEvent(this);
    for (ConnectionEventListener listener : connectionEventListeners) {
        listener.connectionClosed(evt);
    }
}
 
Example 20
Source File: JDBCPooledConnection.java    From evosql with Apache License 2.0 3 votes vote down vote up
synchronized public void connectionClosed() {

        ConnectionEvent event = new ConnectionEvent(this);

        userConnection = null;

        reset();

        for (int i = 0; i < listeners.size(); i++) {
            ConnectionEventListener connectionEventListener =
                (ConnectionEventListener) listeners.get(i);

            connectionEventListener.connectionClosed(event);
        }
    }