openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r551849 - in /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa: event/BrokerFactoryListener.java kernel/AbstractBrokerFactory.java kernel/BrokerFactory.java kernel/DelegatingBrokerFactory.java
Date Fri, 29 Jun 2007 11:04:52 GMT
Author: pcl
Date: Fri Jun 29 04:04:51 2007
New Revision: 551849

URL: http://svn.apache.org/viewvc?view=rev&rev=551849
Log:
OPENJPA-262. Added transaction callback registry to BrokerFactory as well, to parallel lifecycle
callback structure

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryListener.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryListener.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryListener.java?view=diff&rev=551849&r1=551848&r2=551849
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryListener.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/BrokerFactoryListener.java
Fri Jun 29 04:04:51 2007
@@ -28,7 +28,7 @@
 public interface BrokerFactoryListener {
 
     /**
-     * Invoked after a {@link AbstractBrokerFactory} has been fully created.
+     * Invoked after a {@link BrokerFactory} has been fully created.
      * This happens after the factory has been made read-only.
      */
     public void afterBrokerFactoryCreate(BrokerFactoryEvent event);

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?view=diff&rev=551849&r1=551848&r2=551849
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
Fri Jun 29 04:04:51 2007
@@ -26,6 +26,8 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
+import java.util.LinkedList;
+import java.util.List;
 import javax.transaction.Status;
 import javax.transaction.Synchronization;
 import javax.transaction.Transaction;
@@ -91,6 +93,9 @@
     // lifecycle listeners to pass to each broker
     private transient Map _lifecycleListeners = null;
 
+    // transaction listeners to pass to each broker
+    private transient List _transactionListeners = null;
+
     /**
      * Return the pooled factory matching the given configuration, or null
      * if none.
@@ -174,7 +179,7 @@
 
                 broker = newBrokerImpl(user, pass);
                 broker.initialize(this, dsm, managed, connRetainMode);
-                addLifecycleListeners(broker);
+                addListeners(broker);
 
                 // if we're using remote events, register the event manager so
                 // that it can broadcast commit notifications from the broker
@@ -198,16 +203,24 @@
     /**
      * Add factory-registered lifecycle listeners to the broker.
      */
-    protected void addLifecycleListeners(BrokerImpl broker) {
-        if (_lifecycleListeners == null || _lifecycleListeners.isEmpty())
-            return;
+    protected void addListeners(BrokerImpl broker) {
+        if (_lifecycleListeners != null && !_lifecycleListeners.isEmpty()) {
+            Map.Entry entry;
+            for (Iterator itr = _lifecycleListeners.entrySet().iterator();
+                itr.hasNext();) {
+                entry = (Map.Entry) itr.next();
+                broker.addLifecycleListener(entry.getKey(), (Class[])
+                    entry.getValue());
+            }
+        }
 
-        Map.Entry entry;
-        for (Iterator itr = _lifecycleListeners.entrySet().iterator();
-            itr.hasNext();) {
-            entry = (Map.Entry) itr.next();
-            broker.addLifecycleListener(entry.getKey(), (Class[])
-                entry.getValue());
+        if (_transactionListeners != null && !_transactionListeners.isEmpty()) {
+            Map.Entry entry;
+            for (Iterator itr = _transactionListeners.iterator();
+                itr.hasNext(); ) {
+                entry = (Map.Entry) itr.next();
+                broker.addTransactionListener(entry.getKey());
+            }
         }
     }
 
@@ -269,6 +282,29 @@
             assertOpen();
             if (_lifecycleListeners != null)
                 _lifecycleListeners.remove(listener);
+        } finally {
+            unlock();
+        }
+    }
+
+    public void addTransactionListener(Object listener) {
+        lock();
+        try {
+            assertOpen();
+            if (_transactionListeners == null)
+                _transactionListeners = new LinkedList();
+            _transactionListeners.add(listener);
+        } finally {
+            unlock();
+        }
+    }
+
+    public void removeTransactionListener(Object listener) {
+        lock();
+        try {
+            assertOpen();
+            if (_transactionListeners != null)
+                _transactionListeners.remove(listener);
         } finally {
             unlock();
         }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java?view=diff&rev=551849&r1=551848&r2=551849
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerFactory.java
Fri Jun 29 04:04:51 2007
@@ -83,6 +83,23 @@
     public void removeLifecycleListener(Object listener);
 
     /**
+     * Register a listener for transaction-related events on the specified
+     * classes. It will be registered with all {@link Broker}s created
+     * from this instance moving forward.
+     *
+     * @since 1.0.0
+     */
+    public void addTransactionListener(Object listener);
+
+    /**
+     * Remove a listener for transaction-related events. It will no longer
+     * be registered with new {@link Broker}s created from this instance.
+     *
+     * @since 1.0.0
+     */
+    public void removeTransactionListener(Object listener);
+
+    /**
      * Close the factory.
      */
     public void close();

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java?view=diff&rev=551849&r1=551848&r2=551849
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/DelegatingBrokerFactory.java
Fri Jun 29 04:04:51 2007
@@ -162,6 +162,22 @@
         }
     }
 
+    public void addTransactionListener(Object listener) {
+        try {
+            _factory.addTransactionListener(listener);
+        } catch (RuntimeException re) {
+            throw translate(re);
+        }
+    }
+
+    public void removeTransactionListener(Object listener) {
+        try {
+            _factory.removeTransactionListener(listener);
+        } catch (RuntimeException re) {
+            throw translate(re);
+        }
+    }
+
     public void close() {
         try {
             _factory.close();



Mime
View raw message