cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r821324 - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ cayenne-jdk1.5-unpublished/src/main/resources/org/apache/cayenne/schema/3.0/ cayenne-jdk1.5-unpublished/src/test/java/org/apache...
Date Sat, 03 Oct 2009 14:16:06 GMT
Author: aadamchik
Date: Sat Oct  3 14:16:06 2009
New Revision: 821324

URL: http://svn.apache.org/viewvc?rev=821324&view=rev
Log:
CAY-1281 Lifecycle callbacks reorganization

implementing new pre-persist

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/org/apache/cayenne/schema/3.0/modelMap.xsd
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Artist.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Painting.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextCallbacksTest.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java?rev=821324&r1=821323&r2=821324&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataChannelSyncCallbackAction.java
Sat Oct  3 14:16:06 2009
@@ -159,6 +159,7 @@
         @Override
         protected boolean hasListeners() {
             return !(callbackRegistry.isEmpty(LifecycleEvent.PRE_UPDATE)
+                    && callbackRegistry.isEmpty(LifecycleEvent.PRE_PERSIST)
                     && callbackRegistry.isEmpty(LifecycleEvent.POST_UPDATE)
                     && callbackRegistry.isEmpty(LifecycleEvent.POST_REMOVE) &&
callbackRegistry
                     .isEmpty(LifecycleEvent.POST_PERSIST));
@@ -166,6 +167,7 @@
 
         @Override
         void applyPreCommit() {
+            apply(LifecycleEvent.PRE_PERSIST, persisted);
             apply(LifecycleEvent.PRE_UPDATE, updated);
         }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/org/apache/cayenne/schema/3.0/modelMap.xsd
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/org/apache/cayenne/schema/3.0/modelMap.xsd?rev=821324&r1=821323&r2=821324&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/org/apache/cayenne/schema/3.0/modelMap.xsd
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/org/apache/cayenne/schema/3.0/modelMap.xsd
Sat Oct  3 14:16:06 2009
@@ -41,7 +41,7 @@
 				<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:query"/>
 				<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:entity-listener"/>
 			</xs:sequence>
-			<xs:attribute name="project-version" use="required" type="xs:decimal"/>
+			<xs:attribute name="project-version" use="required" type="xs:string"/>
 		</xs:complexType>
 	</xs:element>
 	<xs:element name="db-entity">
@@ -90,6 +90,7 @@
 				<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:entity-listener"/>
 				
 				<!--  Callbacks -->
+				<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:pre-add"/>
 				<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:pre-persist"/>
 				<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:post-persist"/>
 				<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:pre-update"/>
@@ -268,6 +269,7 @@
 	<xs:element name="entity-listener">
 		<xs:complexType>
 			<xs:sequence>
+				<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:pre-add"/>
 				<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:pre-persist"/>
 				<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:post-persist"/>
 				<xs:element minOccurs="0" maxOccurs="unbounded" ref="cay:pre-update"/>
@@ -294,6 +296,11 @@
 			<xs:attribute name="method-name" use="required" type="xs:string"/>
 		</xs:complexType>
 	</xs:element>
+	<xs:element name="pre-add">
+		<xs:complexType>
+			<xs:attribute name="method-name" use="required" type="xs:string"/>
+		</xs:complexType>
+	</xs:element>
 	<xs:element name="pre-persist">
 		<xs:complexType>
 			<xs:attribute name="method-name" use="required" type="xs:string"/>

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Artist.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Artist.java?rev=821324&r1=821323&r2=821324&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Artist.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Artist.java
Sat Oct  3 14:16:06 2009
@@ -26,6 +26,7 @@
 
     protected transient ValidationDelegate validationDelegate;
     protected boolean validateForSaveCalled;
+    protected boolean preAdded;
     protected boolean prePersisted;
     protected boolean preRemoved;
     protected boolean preUpdated;
@@ -51,6 +52,7 @@
     }
 
     public void resetCallbackFlags() {
+        preAdded = false;
         prePersisted = false;
         preRemoved = false;
         preUpdated = false;
@@ -69,6 +71,10 @@
         super.validateForSave(validationResult);
     }
 
+    public void preAddCallback() {
+        preAdded = true;
+    }
+    
     public void prePersistCallback() {
         prePersisted = true;
     }
@@ -97,6 +103,10 @@
         postLoaded++;
     }
 
+    public boolean isPreAdded() {
+        return preAdded;
+    }
+    
     public boolean isPrePersisted() {
         return prePersisted;
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Painting.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Painting.java?rev=821324&r1=821323&r2=821324&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Painting.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/art/Painting.java
Sat Oct  3 14:16:06 2009
@@ -24,18 +24,18 @@
 public class Painting extends org.apache.art.auto._Painting {
     protected boolean validateForSaveCalled;
 
-    protected boolean prePersisted;
+    protected boolean preAdded;
     protected boolean preRemoved;
     protected boolean preUpdated;
 
     public void resetCallbackFlags() {
-        prePersisted = false;
+        preAdded = false;
         preRemoved = false;
         preUpdated = false;
     }
 
-    public void prePersistCallback() {
-        prePersisted = true;
+    public void preAddCallback() {
+        preAdded = true;
     }
 
     public void preRemoveCallback() {
@@ -46,8 +46,8 @@
         preUpdated = true;
     }
 
-    public boolean isPrePersisted() {
-        return prePersisted;
+    public boolean isPreAdded() {
+        return preAdded;
     }
 
     public boolean isPreRemoved() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextCallbacksTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextCallbacksTest.java?rev=821324&r1=821323&r2=821324&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextCallbacksTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextCallbacksTest.java
Sat Oct  3 14:16:06 2009
@@ -38,7 +38,7 @@
         resolver.getCallbackRegistry().clear();
     }
 
-    public void testPrePersistCallbacks() {
+    public void testPreAddCallbacks() {
         LifecycleCallbackRegistry registry = getDomain()
                 .getEntityResolver()
                 .getCallbackRegistry();
@@ -48,16 +48,13 @@
         // no callbacks
         Artist a1 = context.newObject(Artist.class);
         assertNotNull(a1);
-        assertFalse(a1.isPrePersisted());
+        assertFalse(a1.isPreAdded());
 
-        registry.addListener(
-                LifecycleEvent.PRE_ADD,
-                Artist.class,
-                "prePersistCallback");
+        registry.addListener(LifecycleEvent.PRE_ADD, Artist.class, "preAddCallback");
 
         Artist a2 = context.newObject(Artist.class);
         assertNotNull(a2);
-        assertTrue(a2.isPrePersisted());
+        assertTrue(a2.isPreAdded());
 
         MockCallingBackListener listener2 = new MockCallingBackListener();
         registry.addListener(
@@ -68,13 +65,52 @@
 
         Artist a3 = context.newObject(Artist.class);
         assertNotNull(a3);
-        assertTrue(a3.isPrePersisted());
+        assertTrue(a3.isPreAdded());
 
         assertSame(a3, listener2.getPublicCalledbackEntity());
 
         Painting p3 = context.newObject(Painting.class);
         assertNotNull(p3);
-        assertFalse(p3.isPrePersisted());
+        assertFalse(p3.isPreAdded());
+        assertSame(a3, listener2.getPublicCalledbackEntity());
+    }
+
+    public void testPrePersistCallbacks() {
+        LifecycleCallbackRegistry registry = getDomain()
+                .getEntityResolver()
+                .getCallbackRegistry();
+
+        DataContext context = createDataContext();
+
+        // no callbacks
+        Artist a1 = context.newObject(Artist.class);
+        a1.setArtistName("1");
+        assertFalse(a1.isPrePersisted());
+        context.commitChanges();
+        assertFalse(a1.isPrePersisted());
+
+        registry.addListener(
+                LifecycleEvent.PRE_PERSIST,
+                Artist.class,
+                "prePersistCallback");
+
+        Artist a2 = context.newObject(Artist.class);
+        a2.setArtistName("2");
+        assertFalse(a2.isPrePersisted());
+        context.commitChanges();
+        assertTrue(a2.isPrePersisted());
+
+        MockCallingBackListener listener2 = new MockCallingBackListener();
+        registry.addListener(
+                LifecycleEvent.PRE_PERSIST,
+                Artist.class,
+                listener2,
+                "publicCallback");
+
+        Artist a3 = context.newObject(Artist.class);
+        a3.setArtistName("3");
+        assertNull(listener2.getPublicCalledbackEntity());
+        context.commitChanges();
         assertSame(a3, listener2.getPublicCalledbackEntity());
     }
 
@@ -90,7 +126,7 @@
         a1.setArtistName("XX");
         context.commitChanges();
         context.deleteObject(a1);
-        assertFalse(a1.isPrePersisted());
+        assertFalse(a1.isPreAdded());
         assertFalse(a1.isPreRemoved());
 
         registry
@@ -100,7 +136,7 @@
         a2.setArtistName("XX");
         context.commitChanges();
         context.deleteObject(a2);
-        assertFalse(a2.isPrePersisted());
+        assertFalse(a2.isPreAdded());
         assertTrue(a2.isPreRemoved());
 
         MockCallingBackListener listener2 = new MockCallingBackListener();
@@ -114,7 +150,7 @@
         a3.setArtistName("XX");
         context.commitChanges();
         context.deleteObject(a3);
-        assertFalse(a3.isPrePersisted());
+        assertFalse(a3.isPreAdded());
         assertTrue(a3.isPreRemoved());
 
         assertSame(a3, listener2.getPublicCalledbackEntity());
@@ -123,7 +159,7 @@
         p3.setPaintingTitle("XX");
         context.commitChanges();
         context.deleteObject(p3);
-        assertFalse(p3.isPrePersisted());
+        assertFalse(p3.isPreAdded());
         assertFalse(p3.isPreRemoved());
         assertSame(a3, listener2.getPublicCalledbackEntity());
     }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java?rev=821324&r1=821323&r2=821324&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java
Sat Oct  3 14:16:06 2009
@@ -86,6 +86,7 @@
     protected JComboBox callbackTypeCombo = CayenneWidgetFactory.createComboBox(
             new Object[] {
                     new CallbackType(LifecycleEvent.PRE_ADD, "pre-add"),
+                    new CallbackType(LifecycleEvent.PRE_PERSIST, "pre-persist"),
                     new CallbackType(LifecycleEvent.POST_PERSIST, "post-persist"),
                     new CallbackType(LifecycleEvent.PRE_UPDATE, "pre-update"),
                     new CallbackType(LifecycleEvent.POST_UPDATE, "post-update"),



Mime
View raw message