Return-Path: Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 87920 invoked by uid 500); 20 Aug 2003 18:25:20 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 87846 invoked by uid 500); 20 Aug 2003 18:25:18 -0000 Received: (qmail 87822 invoked from network); 20 Aug 2003 18:25:17 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 20 Aug 2003 18:25:17 -0000 Received: (qmail 90798 invoked by uid 1518); 20 Aug 2003 17:57:00 -0000 Date: 20 Aug 2003 17:57:00 -0000 Message-ID: <20030820175700.90797.qmail@minotaur.apache.org> From: mattbaird@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/jca/org/apache/ojb/otm/connector OTMJCAManagedConnection.java OTMJCAConnection.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N mattbaird 2003/08/20 10:57:00 Modified: src/jca/org/apache/ojb/otm/connector OTMJCAManagedConnection.java OTMJCAConnection.java Log: add event dispatches as per the spec. Revision Changes Path 1.3 +92 -19 db-ojb/src/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnection.java Index: OTMJCAManagedConnection.java =================================================================== RCS file: /home/cvs/db-ojb/src/jca/org/apache/ojb/otm/connector/OTMJCAManagedConnection.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- OTMJCAManagedConnection.java 2 Jul 2003 17:33:48 -0000 1.2 +++ OTMJCAManagedConnection.java 20 Aug 2003 17:57:00 -0000 1.3 @@ -103,7 +103,8 @@ { if (m_connection == null) { - throw new OTMConnectionRuntimeException("Connection is null."); + OTMConnectionRuntimeException ex = new OTMConnectionRuntimeException("Connection is null."); + sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null); } return m_connection; } @@ -153,18 +154,7 @@ { m_handles.remove(handle); } - ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED); - ce.setConnectionHandle(handle); - Collection copy = null; - synchronized (m_connectionEventListeners) - { - copy = new ArrayList(m_connectionEventListeners); - } - for (Iterator i = copy.iterator(); i.hasNext();) - { - ConnectionEventListener cel = (ConnectionEventListener) i.next(); - cel.connectionClosed(ce); - } + sendEvents(ConnectionEvent.CONNECTION_CLOSED, null, handle); } public void associateConnection(Object connection) @@ -260,16 +250,21 @@ { m_tx = m_managedConnectionFactory.getKit().getTransaction(m_connection); m_tx.begin(); + sendEvents(ConnectionEvent.LOCAL_TRANSACTION_STARTED, null,null); setManaged(true); } catch (TransactionException e) { - throw new ResourceException(e.getMessage()); + ResourceException ex = new ResourceException(e.getMessage()); + sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null); + throw ex; } } else { - throw new ResourceException("You probably called begin again without calling Commit or Rollback, OTM does not support nested Local Transactions."); + ResourceException ex = new ResourceException("You probably called begin again without calling Commit or Rollback, OTM does not support nested Local Transactions."); + sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null); + throw ex; } } @@ -282,16 +277,21 @@ { setManaged(false); m_tx.commit(); + sendEvents(ConnectionEvent.LOCAL_TRANSACTION_COMMITTED, null,null); } catch (TransactionException e) { m_tx.rollback(); - throw new ResourceException(e.getMessage()); + ResourceException ex = new ResourceException(e.getMessage()); + sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null); + throw ex; } } else { - throw new ResourceException("Cannot call commit when you are not in a Local Transaction."); + ResourceException ex = new ResourceException("Cannot call commit when you are not in a Local Transaction."); + sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null); + throw ex; } } @@ -303,16 +303,21 @@ try { m_tx.rollback(); + sendEvents(ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK, null,null); setManaged(false); } catch (TransactionException e) { - throw new ResourceException(e.getMessage()); + ResourceException ex = new ResourceException(e.getMessage()); + sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null); + throw ex; } } else { - throw new ResourceException("Cannot call rollback when you are not in a Local Transaction."); + ResourceException ex = new ResourceException("Cannot call rollback when you are not in a Local Transaction."); + sendEvents(ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex, null); + throw ex; } } @@ -324,5 +329,73 @@ private void setManaged(boolean flag) { m_managed = flag; + } + + /** + * Section 6.5.6 of the JCA 1.5 spec instructs ManagedConnection instances to notify connection listeners with + * close/error and local transaction-related events to its registered set of listeners. + * + * This method dispatchs all events to the listeners based on the eventType + * @param eventType as enumerated in the ConnectionEvents interface + * @param ex an optional exception if we are sending an error message + * @param connectionHandle an optional connectionHandle if we have access to it. + */ + private void sendEvents(int eventType, Exception ex, Object connectionHandle) + { + ConnectionEvent ce = null; + if (ex == null) + { + ce = new ConnectionEvent(this, eventType); + } + else + { + ce = new ConnectionEvent(this, eventType, ex); + } + ce.setConnectionHandle(connectionHandle); + Collection copy = null; + synchronized (m_connectionEventListeners) + { + copy = new ArrayList(m_connectionEventListeners); + } + switch (ce.getId()) + { + case ConnectionEvent.CONNECTION_CLOSED: + for (Iterator i = copy.iterator(); i.hasNext();) + { + ConnectionEventListener cel = (ConnectionEventListener) i.next(); + cel.connectionClosed(ce); + } + break; + case ConnectionEvent.LOCAL_TRANSACTION_STARTED: + for (Iterator i = copy.iterator(); i.hasNext();) + { + ConnectionEventListener cel = (ConnectionEventListener) i.next(); + cel.localTransactionStarted(ce); + } + break; + case ConnectionEvent.LOCAL_TRANSACTION_COMMITTED: + for (Iterator i = copy.iterator(); i.hasNext();) + { + ConnectionEventListener cel = (ConnectionEventListener) i.next(); + cel.localTransactionCommitted(ce); + } + break; + case ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK: + for (Iterator i = copy.iterator(); i.hasNext();) + { + ConnectionEventListener cel = (ConnectionEventListener) i.next(); + cel.localTransactionRolledback(ce); + } + break; + case ConnectionEvent.CONNECTION_ERROR_OCCURRED: + for (Iterator i = copy.iterator(); i.hasNext();) + { + ConnectionEventListener cel = (ConnectionEventListener) i.next(); + cel.connectionErrorOccurred(ce); + } + break; + default: + throw new IllegalArgumentException("Illegal eventType: " + ce.getId()); + } } } 1.9 +1 -0 db-ojb/src/jca/org/apache/ojb/otm/connector/OTMJCAConnection.java Index: OTMJCAConnection.java =================================================================== RCS file: /home/cvs/db-ojb/src/jca/org/apache/ojb/otm/connector/OTMJCAConnection.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- OTMJCAConnection.java 18 Aug 2003 16:29:16 -0000 1.8 +++ OTMJCAConnection.java 20 Aug 2003 17:57:00 -0000 1.9 @@ -230,6 +230,7 @@ OTMConnection getConnection() { + isValidUnderlyingConnection(); return m_managedConnection.getConnection(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org