cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r450545 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/map/ test/java/org/apache/cayenne/map/
Date Wed, 27 Sep 2006 19:12:52 GMT
Author: aadamchik
Date: Wed Sep 27 12:12:52 2006
New Revision: 450545

URL: http://svn.apache.org/viewvc?view=rev&rev=450545
Log:
CAY-660 - adding support for entity-level listener exclude policies

Added:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/map/MockLifecycleEventCallbackMap.java
Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/EntityResolver.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/LifecycleEventCallbackMap.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/ObjEntity.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/map/LifecycleEventCallbackMapTst.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/EntityResolver.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/EntityResolver.java?view=diff&rev=450545&r1=450544&r2=450545
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/EntityResolver.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/EntityResolver.java
Wed Sep 27 12:12:52 2006
@@ -95,11 +95,36 @@
             LifecycleEventCallbackMap[] lifecycleEventCallbacks = new LifecycleEventCallbackMap[7];
 
             for (int i = 0; i < lifecycleEventCallbacks.length; i++) {
-                lifecycleEventCallbacks[i] = new LifecycleEventCallbackMap();
+                lifecycleEventCallbacks[i] = new LifecycleEventCallbackMap() {
+
+                    protected boolean isExcludingDefaultListeners(Class objectClass) {
+                        return excludingDefaultListeners(objectClass);
+                    }
+
+                    protected boolean isExcludingSuperclassListeners(Class objectClass) {
+                        return excludingSuperclassListeners(objectClass);
+                    }
+                };
             }
 
             this.lifecycleEventCallbacks = lifecycleEventCallbacks;
         }
+    }
+
+    /**
+     * @since 3.0
+     */
+    boolean excludingDefaultListeners(Class objectClass) {
+        ObjEntity entity = lookupObjEntity(objectClass);
+        return entity != null && entity.isExcludingDefaultListeners();
+    }
+
+    /**
+     * @since 3.0
+     */
+    boolean excludingSuperclassListeners(Class objectClass) {
+        ObjEntity entity = lookupObjEntity(objectClass);
+        return entity != null && entity.isExcludingSuperclassListeners();
     }
 
     /**

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/LifecycleEventCallbackMap.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/LifecycleEventCallbackMap.java?view=diff&rev=450545&r1=450544&r2=450545
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/LifecycleEventCallbackMap.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/LifecycleEventCallbackMap.java
Wed Sep 27 12:12:52 2006
@@ -30,7 +30,7 @@
  * @since 3.0
  * @author Andrus Adamchik
  */
-public class LifecycleEventCallbackMap {
+public abstract class LifecycleEventCallbackMap {
 
     protected Map listeners;
     protected Collection defaultListeners;
@@ -40,6 +40,10 @@
         defaultListeners = new ArrayList();
     }
 
+    protected abstract boolean isExcludingDefaultListeners(Class objectClass);
+
+    protected abstract boolean isExcludingSuperclassListeners(Class objectClass);
+
     /**
      * Removes all listeners.
      */
@@ -108,9 +112,10 @@
      * Invokes callbacks for a given entity object.
      */
     public void performCallbacks(Object object) {
-        
+
         // default listeners are invoked first
-        if (!defaultListeners.isEmpty()) {
+        if (!defaultListeners.isEmpty()
+                && !isExcludingDefaultListeners(object.getClass())) {
             Iterator it = (Iterator) defaultListeners.iterator();
             while (it.hasNext()) {
                 ((LifecycleEventCallback) it.next()).performCallback(object);
@@ -131,7 +136,9 @@
         }
 
         // recursively perform super callbacks first
-        performCallbacks(object, callbackEntityClass.getSuperclass());
+        if (!isExcludingSuperclassListeners(callbackEntityClass)) {
+            performCallbacks(object, callbackEntityClass.getSuperclass());
+        }
 
         // perform callbacks on provided class
         String key = callbackEntityClass.getName();

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/ObjEntity.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/ObjEntity.java?view=diff&rev=450545&r1=450544&r2=450545
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/ObjEntity.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/ObjEntity.java
Wed Sep 27 12:12:52 2006
@@ -80,6 +80,9 @@
     protected String clientClassName;
     protected String clientSuperClassName;
 
+    protected boolean excludingDefaultListeners;
+    protected boolean excludingSuperclassListeners;
+
     public ObjEntity() {
         this(null);
     }
@@ -911,6 +914,34 @@
     /** Relationship has been removed. */
     public void objRelationshipRemoved(RelationshipEvent e) {
         // does nothing currently
+    }
+
+    /**
+     * Returns true if the default lifecycle listeners should not be notified of this
+     * entity lifecycle events.
+     * 
+     * @since 3.0
+     */
+    public boolean isExcludingDefaultListeners() {
+        return excludingDefaultListeners;
+    }
+
+    public void setExcludingDefaultListeners(boolean excludingDefaultListeners) {
+        this.excludingDefaultListeners = excludingDefaultListeners;
+    }
+
+    /**
+     * Returns true if the lifeycle listeners defined on the superclasses should not be
+     * notified of this entity lifecycle events.
+     * 
+     * @since 3.0
+     */
+    public boolean isExcludingSuperclassListeners() {
+        return excludingSuperclassListeners;
+    }
+
+    public void setExcludingSuperclassListeners(boolean excludingSuperclassListeners) {
+        this.excludingSuperclassListeners = excludingSuperclassListeners;
     }
 
 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/map/LifecycleEventCallbackMapTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/map/LifecycleEventCallbackMapTst.java?view=diff&rev=450545&r1=450544&r2=450545
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/map/LifecycleEventCallbackMapTst.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/map/LifecycleEventCallbackMapTst.java
Wed Sep 27 12:12:52 2006
@@ -27,7 +27,7 @@
 
     public void testDefaultListeners() {
 
-        LifecycleEventCallbackMap map = new LifecycleEventCallbackMap();
+        LifecycleEventCallbackMap map = new MockLifecycleEventCallbackMap();
         L1 l1 = new L1();
         map.addDefaultListener(l1, "callback");
 
@@ -41,7 +41,7 @@
 
     public void testDefaultListenersCallbackOrder() {
 
-        LifecycleEventCallbackMap map = new LifecycleEventCallbackMap();
+        LifecycleEventCallbackMap map = new MockLifecycleEventCallbackMap();
         L2 l1 = new L2();
         map.addListener(C1.class, l1, "callback");
 
@@ -53,7 +53,7 @@
         map.performCallbacks(c1);
         assertEquals(1, l1.callbackTimes.size());
         assertEquals(1, l2.callbackTimes.size());
-        
+
         Long t1 = (Long) l1.callbackTimes.get(0);
         Long t2 = (Long) l2.callbackTimes.get(0);
         assertTrue(t2.compareTo(t1) < 0);
@@ -61,7 +61,7 @@
 
     public void testCallbackOnSuperclass() {
 
-        LifecycleEventCallbackMap map = new LifecycleEventCallbackMap();
+        LifecycleEventCallbackMap map = new MockLifecycleEventCallbackMap();
         map.addListener(C1.class, "c1Callback");
 
         C3 subclass = new C3();
@@ -73,7 +73,7 @@
 
     public void testCallbackOnSuperclassWithSublcassOverrides() {
 
-        LifecycleEventCallbackMap map = new LifecycleEventCallbackMap();
+        LifecycleEventCallbackMap map = new MockLifecycleEventCallbackMap();
         map.addListener(C1.class, "c1Callback");
 
         C4 subclass = new C4();
@@ -86,7 +86,7 @@
 
     public void testCallbackOrderInInheritanceHierarchy() {
 
-        LifecycleEventCallbackMap map = new LifecycleEventCallbackMap();
+        LifecycleEventCallbackMap map = new MockLifecycleEventCallbackMap();
         map.addListener(C2.class, "c2Callback");
         map.addListener(C1.class, "c1Callback");
 

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/map/MockLifecycleEventCallbackMap.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/map/MockLifecycleEventCallbackMap.java?view=auto&rev=450545
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/map/MockLifecycleEventCallbackMap.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/map/MockLifecycleEventCallbackMap.java
Wed Sep 27 12:12:52 2006
@@ -0,0 +1,30 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.map;
+
+public class MockLifecycleEventCallbackMap extends LifecycleEventCallbackMap {
+
+    protected boolean isExcludingDefaultListeners(Class objectClass) {
+        return false;
+    }
+
+    protected boolean isExcludingSuperclassListeners(Class objectClass) {
+        return false;
+    }
+}



Mime
View raw message