openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwsut...@apache.org
Subject svn commit: r1308362 - in /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa: event/LifecycleEventManager.java kernel/BrokerImpl.java meta/LifecycleMetaData.java meta/MetaDataRepository.java validation/ValidatingLifecycleEventManager.java
Date Mon, 02 Apr 2012 14:25:26 GMT
Author: kwsutter
Date: Mon Apr  2 14:25:26 2012
New Revision: 1308362

URL: http://svn.apache.org/viewvc?rev=1308362&view=rev
Log:
OPENJPA-2168.  Modified the approach for detecting life cycle event processing.

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

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java?rev=1308362&r1=1308361&r2=1308362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/event/LifecycleEventManager.java
Mon Apr  2 14:25:26 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);
@@ -209,7 +222,7 @@ public class LifecycleEventManager
             || hasHandlers(source, meta, LifecycleEvent.AFTER_ATTACH);
     }
 
-    public boolean hasHandlers(Object source, ClassMetaData meta, int type) {
+    private boolean hasHandlers(Object source, ClassMetaData meta, int type) {
         return hasCallbacks(source, meta, type)
             || hasListeners(source, meta, type);
     }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java?rev=1308362&r1=1308361&r2=1308362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java (original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java Mon
Apr  2 14:25:26 2012
@@ -793,7 +793,7 @@ public class BrokerImpl
         int eventType) {
         if (_lifeEventManager == null)
             return false;
-        if (!_lifeEventManager.hasHandlers(src, meta, eventType))
+        if (!_lifeEventManager.isActive(meta))
             return false;
 
         lock();

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/LifecycleMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/LifecycleMetaData.java?rev=1308362&r1=1308361&r2=1308362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/LifecycleMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/LifecycleMetaData.java
Mon Apr  2 14:25:26 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/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java?rev=1308362&r1=1308361&r2=1308362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java
Mon Apr  2 14:25:26 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/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/validation/ValidatingLifecycleEventManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/validation/ValidatingLifecycleEventManager.java?rev=1308362&r1=1308361&r2=1308362&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/validation/ValidatingLifecycleEventManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/validation/ValidatingLifecycleEventManager.java
Mon Apr  2 14:25:26 2012
@@ -99,14 +99,6 @@ public class ValidatingLifecycleEventMan
     }
     
     @Override
-    public boolean hasHandlers(Object source, ClassMetaData meta, int type) {
-        if (_validator == null) {            
-            return super.hasHandlers(source, meta, type);
-        }
-        return true;
-    }
-
-    @Override
     public Exception[] fireEvent(Object source,
         ClassMetaData meta, int type) {
         
@@ -147,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();
+    }
+
     public boolean isValidationEnabled() {
         return _validationEnabled;
     }



Mime
View raw message