openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1342685 - in /openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa: event/ kernel/ meta/ validation/
Date Fri, 25 May 2012 15:36:29 GMT
Author: curtisr7
Date: Fri May 25 15:36:29 2012
New Revision: 1342685

URL: http://svn.apache.org/viewvc?rev=1342685&view=rev
Log:
OPENJPA-2168: Merge changes from trunk.

Modified:
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/LifecycleMetaData.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/validation/ValidatingLifecycleEventManager.java

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java?rev=1342685&r1=1342684&r2=1342685&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java
Fri May 25 15:36:29 2012
@@ -64,6 +64,18 @@ public class LifecycleEventManager
     private boolean _firing = false;
     private boolean _fail = false;
     private boolean _failFast = false;
+    private boolean _activated = false;  // set to true once modified
+
+    /**
+     * Whether this LifeCycleEventManager has had at least one listener or callback
+     * registered.  Used for a quick test when firing events.
+     * @return boolean
+     */
+    public boolean isActive(ClassMetaData meta) {
+        return _activated ||
+            meta.getLifecycleMetaData().is_activated() ||
+            meta.getRepository().is_systemListenersActivated();
+    }
 
     /**
      * Whether to fail after first exception when firing events to listeners.
@@ -88,6 +100,7 @@ public class LifecycleEventManager
             return;
         if (classes != null && classes.length == 0)
             return;
+        _activated = true;
         if (_firing) {
             _addListeners.add(listener);
             _addListeners.add(classes);

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java?rev=1342685&r1=1342684&r2=1342685&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
Fri May 25 15:36:29 2012
@@ -793,6 +793,8 @@ public class BrokerImpl
         int eventType) {
         if (_lifeEventManager == null)
             return false;
+        if (!_lifeEventManager.isActive(meta))
+            return false;
 
         lock();
         Exception[] exs;

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/LifecycleMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/LifecycleMetaData.java?rev=1342685&r1=1342684&r2=1342685&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/LifecycleMetaData.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/LifecycleMetaData.java
Fri May 25 15:36:29 2012
@@ -53,6 +53,7 @@ public class LifecycleMetaData
     private boolean _resolved = false;
     private boolean _ignoreSystem = false;
     private int _ignoreSups = 0;
+    private boolean _activated = false;
 
     /**
      * Construct with owning metadata.
@@ -62,6 +63,15 @@ public class LifecycleMetaData
     }
 
     /**
+     * Whether the LifeCycleMetaData has had any callbacks or listeners registered.  Used
+     * for a quick test to determine whether to attempt to fire any events.
+     * @return boolean 
+     */
+    public boolean is_activated() {
+        return _activated;
+    }
+
+    /**
      * Whether to exclude system listeners from events.
      */
     public boolean getIgnoreSystemListeners() {
@@ -127,6 +137,7 @@ public class LifecycleMetaData
         }
         _declared[eventType] = callbacks;
         _high[eventType] = highPriority;
+        _activated = true;
     }
 
     /**
@@ -160,6 +171,7 @@ public class LifecycleMetaData
         }
         _super[eventType] = callbacks;
         _superHigh[eventType] = highPriority;
+        _activated = true;
     }
 
     /**

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?rev=1342685&r1=1342684&r2=1342685&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
Fri May 25 15:36:29 2012
@@ -150,6 +150,7 @@ public class MetaDataRepository implemen
 
     // system listeners
     private LifecycleEventManager.ListenerList _listeners = new LifecycleEventManager.ListenerList(3);
+    private boolean _systemListenersActivated = false;
 
     protected boolean _preload = false;
     protected boolean _preloadComplete = false;
@@ -2271,6 +2272,15 @@ public class MetaDataRepository implemen
     }
 
     /**
+     * Whether any system (default) listeners have been registered.  Used as a quick test
to
+     * determine whether the callback/listener mechanism has been enabled.
+     * @return boolean
+     */
+    public boolean is_systemListenersActivated() {
+        return _systemListenersActivated;
+    }
+
+    /**
      * Add the given system lifecycle listener.
      */
     public void addSystemListener(Object listener) {
@@ -2281,11 +2291,13 @@ public class MetaDataRepository implemen
                 LifecycleEventManager.ListenerList listeners = new LifecycleEventManager.ListenerList(_listeners);
                 listeners.add(listener);
                 _listeners = listeners;
+                _systemListenersActivated = true;
             }
         } else {
             LifecycleEventManager.ListenerList listeners = new LifecycleEventManager.ListenerList(_listeners);
             listeners.add(listener);
             _listeners = listeners;
+            _systemListenersActivated = true;
         }
     }
 

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/validation/ValidatingLifecycleEventManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/validation/ValidatingLifecycleEventManager.java?rev=1342685&r1=1342684&r2=1342685&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/validation/ValidatingLifecycleEventManager.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/validation/ValidatingLifecycleEventManager.java
Fri May 25 15:36:29 2012
@@ -97,7 +97,7 @@ public class ValidatingLifecycleEventMan
         return _validator.validating(source, LifecycleEvent.BEFORE_DELETE) ||
             super.hasDeleteListeners(source, meta);
     }
-
+    
     @Override
     public Exception[] fireEvent(Object source,
         ClassMetaData meta, int type) {
@@ -139,6 +139,16 @@ public class ValidatingLifecycleEventMan
         return evx;
     }
 
+    /**
+     * Whether this LifeCycleEventManager has had at least one listener or callback
+     * registered.  Used for a quick test when firing events.
+     * @return boolean
+     */
+    @Override
+    public boolean isActive(ClassMetaData meta) {
+        return isValidationEnabled() || super.isActive(meta);
+    }
+
     public boolean isValidationEnabled() {
         return _validationEnabled;
     }



Mime
View raw message