cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r587482 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/map/ test/java/org/apache/art/ test/java/org/apache/art/auto/ test/java/org/apache/cayenne/map/ test/resources/
Date Tue, 23 Oct 2007 12:44:41 GMT
Author: aadamchik
Date: Tue Oct 23 05:44:40 2007
New Revision: 587482

URL: http://svn.apache.org/viewvc?rev=587482&view=rev
Log:
CAY-879 Storing lifecycle listebers and callbacks in the *.map.xml and loading them back
(patch submitted by Vasil Tarasevich)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/ArtistCallbackTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/EntityListenerDataMap.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/EntityListenerObjEntity.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/auto/_ArtistCallbackTest.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityListener.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/testmap.map.xml

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java?rev=587482&r1=587481&r2=587482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java
Tue Oct 23 05:44:40 2007
@@ -19,11 +19,7 @@
 package org.apache.cayenne.map;
 
 import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.*;
 
 /**
  * A mapping descriptor of a single callback event.
@@ -40,7 +36,7 @@
 
     public CallbackDescriptor(int callbackType) {
         setCallbackType(callbackType);
-        this.callbackMethods = new HashSet(3);
+        this.callbackMethods = new LinkedHashSet(3);
     }
 
     /**
@@ -52,6 +48,7 @@
 
     /**
      * Returns all callback methods for this callback event.
+     * @return Returns all callback methods
      */
     public Collection getCallbackMethods() {
         return Collections.unmodifiableCollection(callbackMethods);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java?rev=587482&r1=587481&r2=587482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java
Tue Oct 23 05:44:40 2007
@@ -19,8 +19,10 @@
 package org.apache.cayenne.map;
 
 import java.io.Serializable;
+import java.util.Iterator;
 
 import org.apache.cayenne.LifecycleListener;
+import org.apache.cayenne.util.XMLEncoder;
 
 /**
  * A generic descriptor of a set of standard lifecycle callbacks.
@@ -99,5 +101,25 @@
 
     public CallbackDescriptor getPreUpdate() {
         return preUpdate;
+    }
+
+    public void encodeCallbacksAsXML(XMLEncoder encoder) {
+        printMethods(prePersist, "pre-persist", encoder);
+        printMethods(postPersist, "post-persist", encoder);
+        printMethods(preUpdate, "pre-update", encoder);
+        printMethods(postUpdate, "post-update", encoder);
+        printMethods(preRemove, "pre-remove", encoder);
+        printMethods(postRemove, "post-remove", encoder);
+        printMethods(postLoad, "post-load", encoder);
+    }
+
+    private static void printMethods(CallbackDescriptor descriptor, String stringCallbackName,
XMLEncoder encoder) {
+        for (Iterator i = descriptor.getCallbackMethods().iterator(); i.hasNext();) {
+            encoder.print("<");
+            encoder.print(stringCallbackName);
+            encoder.print(" method-name=\"");
+            encoder.print((String)i.next());
+            encoder.println("\"/>");
+        }
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java?rev=587482&r1=587481&r2=587482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
Tue Oct 23 05:44:40 2007
@@ -311,6 +311,12 @@
         encodeOBJRelationshipsAsXML(getObjEntityMap(), encoder);
         encoder.print(getQueryMap());
 
+        //write entity listeners
+        for(Iterator i = getDefaultEntityListeners().iterator(); i.hasNext();) {
+            EntityListener entityListener = (EntityListener)i.next();
+            entityListener.encodeAsXML(encoder);
+        }
+
         encoder.indent(-1);
         encoder.println("</data-map>");
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityListener.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityListener.java?rev=587482&r1=587481&r2=587482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityListener.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/EntityListener.java
Tue Oct 23 05:44:40 2007
@@ -18,6 +18,9 @@
  ****************************************************************/
 package org.apache.cayenne.map;
 
+import org.apache.cayenne.util.XMLEncoder;
+import org.apache.cayenne.util.XMLSerializable;
+
 import java.io.Serializable;
 
 /**
@@ -27,7 +30,7 @@
  * @since 3.0
  * @author Andrus Adamchik
  */
-public class EntityListener implements Serializable {
+public class EntityListener implements Serializable, XMLSerializable {
 
     protected String className;
     protected CallbackMap callbacks;
@@ -51,8 +54,21 @@
 
     /**
      * Returns an object that stores callback methods of this listener.
+     * @return callback map
      */
     public CallbackMap getCallbackMap() {
         return callbacks;
+    }
+
+    public void encodeAsXML(XMLEncoder encoder) {
+        encoder.print("<entity-listener class=\"");
+        encoder.print(className);
+        encoder.println("\">");
+        encoder.indent(1);
+
+        getCallbackMap().encodeCallbacksAsXML(encoder);
+
+        encoder.indent(-1);
+        encoder.println("</entity-listener>");
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java?rev=587482&r1=587481&r2=587482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
Tue Oct 23 05:44:40 2007
@@ -89,6 +89,16 @@
     public static final String PROCEDURE_TAG = "procedure";
     public static final String PROCEDURE_PARAMETER_TAG = "procedure-parameter";
 
+    //lifecycle listeners and callbacks related
+    public static final String ENTITY_LISTENER_TAG = "entity-listener";
+    public static final String PRE_PERSIST_TAG = "pre-persist";
+    public static final String POST_PERSIST_TAG = "post-persist";
+    public static final String PRE_UPDATE_TAG = "pre-update";
+    public static final String POST_UPDATE_TAG = "post-update";
+    public static final String PRE_REMOVE_TAG = "pre-remove";
+    public static final String POST_REMOVE_TAG = "post-remove";
+    public static final String POST_LOAD_TAG = "post-load";    
+
     // Query-related
     public static final String QUERY_TAG = "query";
 
@@ -109,6 +119,7 @@
     private DataMap dataMap;
     private DbEntity dbEntity;
     private ObjEntity objEntity;
+    private EntityListener entityListener;
     private Embeddable embeddable;
     private EmbeddedAttribute embeddedAttribute;
     private DbRelationship dbRelationship;
@@ -286,6 +297,59 @@
             }
         });
 
+        startTagOpMap.put(ENTITY_LISTENER_TAG, new StartClosure() {
+            void execute(Attributes attributes) throws SAXException {
+                processStartEntitylistener(attributes);
+            }
+        });
+
+        startTagOpMap.put(PRE_PERSIST_TAG, new StartClosure() {
+            void execute(Attributes attributes) throws SAXException {
+                processStartPrePersist(attributes);
+            }
+        });
+
+        startTagOpMap.put(POST_PERSIST_TAG, new StartClosure() {
+            void execute(Attributes attributes) throws SAXException {
+                processStartPostPersist(attributes);
+            }
+        });
+
+        startTagOpMap.put(PRE_UPDATE_TAG, new StartClosure() {
+
+            void execute(Attributes attributes) throws SAXException {
+                processStartPreUpdate(attributes);
+            }
+        });
+
+        startTagOpMap.put(POST_UPDATE_TAG, new StartClosure() {
+
+            void execute(Attributes attributes) throws SAXException {
+                processStartPostUpdate(attributes);
+            }
+        });
+
+        startTagOpMap.put(PRE_REMOVE_TAG, new StartClosure() {
+
+            void execute(Attributes attributes) throws SAXException {
+                processStartPreRemove(attributes);
+            }
+        });
+
+        startTagOpMap.put(POST_REMOVE_TAG, new StartClosure() {
+
+            void execute(Attributes attributes) throws SAXException {
+                processStartPostRemove(attributes);
+            }
+        });
+
+        startTagOpMap.put(POST_LOAD_TAG, new StartClosure() {
+
+            void execute(Attributes attributes) throws SAXException {
+                processStartPostLoad(attributes);
+            }
+        });
+
         StartClosure resetBuffer = new StartClosure() {
 
             void execute(Attributes attributes) throws SAXException {
@@ -415,6 +479,101 @@
                 processEndQueryPrefetch();
             }
         });
+
+        endTagOpMap.put(ENTITY_LISTENER_TAG, new EndClosure() {
+            void execute() throws SAXException {
+                processEndEntitylistener();
+            }
+        });
+    }
+
+    private void processStartEntitylistener(Attributes attributes) {
+        entityListener = new EntityListener(attributes.getValue("", "class"));
+        if (objEntity != null) {
+            //we are inside of obj-entity tag
+            objEntity.addEntityListener(entityListener);
+        }
+        else if (dataMap != null) {
+            //we are inside of datamap tag
+            dataMap.addDefaultEntityListener(entityListener);
+        }
+    }
+
+    private void processEndEntitylistener() {
+        entityListener = null;
+    }
+
+
+    private void processStartPrePersist(Attributes attributes) {
+        String methodName = attributes.getValue("", "method-name");
+        if (entityListener != null) {
+            //new "entity-listener" tag as a child of "obj-entity"
+            entityListener.getCallbackMap().getPrePersist().addCallbackMethod(methodName);
+        }
+        else if (objEntity != null) {
+            //new callback tags - children of "obj-entity"
+            objEntity.getCallbackMap().getPrePersist().addCallbackMethod(methodName);
+        }
+    }
+
+    private void processStartPostPersist(Attributes attributes) {
+        String methodName = attributes.getValue("", "method-name");
+        if (entityListener != null) {
+            entityListener.getCallbackMap().getPostPersist().addCallbackMethod(methodName);
+        }
+        else if (objEntity != null) {
+            objEntity.getCallbackMap().getPostPersist().addCallbackMethod(methodName);
+        }
+    }
+
+    private void processStartPreUpdate(Attributes attributes) {
+        String methodName = attributes.getValue("", "method-name");
+        if (entityListener != null) {
+            entityListener.getCallbackMap().getPreUpdate().addCallbackMethod(methodName);
+        }
+        else if (objEntity != null) {
+            objEntity.getCallbackMap().getPreUpdate().addCallbackMethod(methodName);
+        }
+    }
+
+    private void processStartPostUpdate(Attributes attributes) {
+        String methodName = attributes.getValue("", "method-name");
+        if (entityListener != null) {
+            entityListener.getCallbackMap().getPostUpdate().addCallbackMethod(methodName);
+        }
+        else if (objEntity != null) {
+            objEntity.getCallbackMap().getPostUpdate().addCallbackMethod(methodName);
+        }
+    }
+
+    private void processStartPreRemove(Attributes attributes) {
+        String methodName = attributes.getValue("", "method-name");
+        if (entityListener != null) {
+            entityListener.getCallbackMap().getPreRemove().addCallbackMethod(methodName);
+        }
+        else if (objEntity != null) {
+            objEntity.getCallbackMap().getPreRemove().addCallbackMethod(methodName);
+        }
+    }
+
+    private void processStartPostRemove(Attributes attributes) {
+        String methodName = attributes.getValue("", "method-name"); 
+        if (entityListener != null) {
+            entityListener.getCallbackMap().getPostRemove().addCallbackMethod(methodName);
+        }
+        else if (objEntity != null) {
+            objEntity.getCallbackMap().getPostRemove().addCallbackMethod(methodName);
+        }
+    }
+
+    private void processStartPostLoad(Attributes attributes) {
+        String methodName = attributes.getValue("", "method-name");
+        if (entityListener != null) {
+            entityListener.getCallbackMap().getPostLoad().addCallbackMethod(methodName);
+        }
+        else if (objEntity != null) {
+            objEntity.getCallbackMap().getPostLoad().addCallbackMethod(methodName);
+        }
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java?rev=587482&r1=587481&r2=587482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
Tue Oct 23 05:44:40 2007
@@ -161,6 +161,15 @@
         // store attributes
         encoder.print(getDeclaredAttributes());
 
+        //write entity listeners
+        for(Iterator i = getEntityListeners().iterator(); i.hasNext();) {
+            EntityListener entityListener = (EntityListener)i.next();
+            entityListener.encodeAsXML(encoder);
+        }
+
+        //write entity-level callbacks
+        getCallbackMap().encodeCallbacksAsXML(encoder);
+
         encoder.indent(-1);
         encoder.println("</obj-entity>");
     }

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/ArtistCallbackTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/ArtistCallbackTest.java?rev=587482&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/ArtistCallbackTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/ArtistCallbackTest.java
Tue Oct 23 05:44:40 2007
@@ -0,0 +1,39 @@
+/*****************************************************************
+ *   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.art;
+
+import org.apache.art.auto._ArtistCallbackTest;
+
+/**
+ * Class for testing callbacks
+ *
+ * @author Vasil Tarasevich
+ * @version 1.0 Oct 22, 2007
+ */
+
+public class ArtistCallbackTest extends _ArtistCallbackTest {
+    public void prePersistEntityObjEntity() {}
+    public void postPersistEntityObjEntity() {}
+    public void preUpdateEntityObjEntity() {}
+    public void postUpdateEntityObjEntity() {}
+    public void preRemoveEntityObjEntity() {}
+    public void postRemoveEntityObjEntity() {}
+    public void postLoadEntityObjEntity() {}
+}
+

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/EntityListenerDataMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/EntityListenerDataMap.java?rev=587482&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/EntityListenerDataMap.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/EntityListenerDataMap.java
Tue Oct 23 05:44:40 2007
@@ -0,0 +1,51 @@
+/*****************************************************************
+ *   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.art;
+
+/**
+ * Class for testing callbacks on datamap level
+ * 
+ * @author Vasil Tarasevich
+ */
+public class EntityListenerDataMap {
+
+    public void prePersistDataMap1(Object entity) {
+    }
+
+    public void prePersistDataMap2(Object entity) {
+    }
+
+    public void postPersistDataMap(Object entity) {
+    }
+
+    public void preUpdateDataMap(Object entity) {
+    }
+
+    public void postUpdateDataMap(Object entity) {
+    }
+
+    public void preRemoveDataMap(Object entity) {
+    }
+
+    public void postRemoveDataMap(Object entity) {
+    }
+
+    public void postLoadDataMap(Object entity) {
+    }
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/EntityListenerObjEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/EntityListenerObjEntity.java?rev=587482&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/EntityListenerObjEntity.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/EntityListenerObjEntity.java
Tue Oct 23 05:44:40 2007
@@ -0,0 +1,37 @@
+/*****************************************************************
+ *   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.art;
+
+/**
+ * Class for testing callbacks on ObjEntity level
+ *
+ * @author Vasil Tarasevich
+ * @version 1.0 Oct 22, 2007
+ */
+
+public class EntityListenerObjEntity {
+    public void prePersistEntityListener(ArtistCallbackTest entity) {}
+    public void postPersistEntityListener(ArtistCallbackTest entity) {}
+    public void preUpdateEntityListener(ArtistCallbackTest entity) {}
+    public void postUpdateEntityListener(ArtistCallbackTest entity) {}
+    public void preRemoveEntityListener(ArtistCallbackTest entity) {}
+    public void postRemoveEntityListener(ArtistCallbackTest entity) {}
+    public void postLoadEntityListener(ArtistCallbackTest entity) {}
+}
+

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/auto/_ArtistCallbackTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/auto/_ArtistCallbackTest.java?rev=587482&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/auto/_ArtistCallbackTest.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/art/auto/_ArtistCallbackTest.java
Tue Oct 23 05:44:40 2007
@@ -0,0 +1,30 @@
+package org.apache.art.auto;
+
+/** Class _ArtistCallbackTest was generated by Cayenne.
+  * It is probably a good idea to avoid changing this class manually, 
+  * since it may be overwritten next time code is regenerated. 
+  * If you need to make any customizations, please use subclass. 
+  */
+public abstract class _ArtistCallbackTest extends org.apache.cayenne.CayenneDataObject {
+
+    public static final String ARTIST_NAME_PROPERTY = "artistName";
+    public static final String DATE_OF_BIRTH_PROPERTY = "dateOfBirth";
+
+
+    public void setArtistName(String artistName) {
+        writeProperty("artistName", artistName);
+    }
+    public String getArtistName() {
+        return (String)readProperty("artistName");
+    }
+    
+    
+    public void setDateOfBirth(java.util.Date dateOfBirth) {
+        writeProperty("dateOfBirth", dateOfBirth);
+    }
+    public java.util.Date getDateOfBirth() {
+        return (java.util.Date)readProperty("dateOfBirth");
+    }
+    
+    
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java?rev=587482&r1=587481&r2=587482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/map/MapLoaderLoadTest.java
Tue Oct 23 05:44:40 2007
@@ -20,6 +20,9 @@
 package org.apache.cayenne.map;
 
 import java.util.List;
+import java.io.PrintWriter;
+import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
 
 import junit.framework.TestCase;
 
@@ -111,6 +114,18 @@
         assertNotNull(ent.getSuperClassName());
 
         checkLoadedQueries(map);
+    }
+
+    public void testEncodeAsXML() throws FileNotFoundException {
+        //load map
+        MapLoader mapLoader = new MapLoader();
+        DataMap map = mapLoader.loadDataMap(getMapXml("testmap.map.xml"));
+        assertNotNull(map);
+
+        //endode map
+        PrintWriter pw = new PrintWriter(new FileOutputStream("testmap_generated.map.xml"));
+        map.encodeAsXML(pw);
+        pw.close();
     }
 
     private void checkLoadedQueries(DataMap map) throws Exception {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/testmap.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/testmap.map.xml?rev=587482&r1=587481&r2=587482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/testmap.map.xml
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/testmap.map.xml
Tue Oct 23 05:44:40 2007
@@ -26,11 +26,16 @@
 		<db-attribute name="NAME" type="VARCHAR" isMandatory="true" length="100"/>
 		<db-attribute name="PARENT_GROUP_ID" type="INTEGER"/>
 	</db-entity>
-	<db-entity name="ARTIST">
-		<db-attribute name="ARTIST_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
-		<db-attribute name="ARTIST_NAME" type="CHAR" isMandatory="true" length="254"/>
-		<db-attribute name="DATE_OF_BIRTH" type="DATE"/>
-	</db-entity>
+    <db-entity name="ARTIST">
+        <db-attribute name="ARTIST_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+        <db-attribute name="ARTIST_NAME" type="CHAR" isMandatory="true" length="254"/>
+        <db-attribute name="DATE_OF_BIRTH" type="DATE"/>
+    </db-entity>
+    <db-entity name="ARTIS_CT">
+        <db-attribute name="ARTIST_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+        <db-attribute name="ARTIST_NAME" type="CHAR" isMandatory="true" length="254"/>
+        <db-attribute name="DATE_OF_BIRTH" type="DATE"/>
+    </db-entity>
 	<db-entity name="ARTIST_EXHIBIT">
 		<db-attribute name="ARTIST_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
 		<db-attribute name="EXHIBIT_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
@@ -227,7 +232,7 @@
 	<obj-entity name="Artist" className="org.apache.art.Artist" dbEntityName="ARTIST">
 		<obj-attribute name="artistName" type="java.lang.String" db-attribute-path="ARTIST_NAME"/>
 		<obj-attribute name="dateOfBirth" type="java.util.Date" db-attribute-path="DATE_OF_BIRTH"/>
-	</obj-entity>
+    </obj-entity>
 	<obj-entity name="ArtistAssets" className="org.apache.art.ArtistAssets" dbEntityName="ARTIST_ASSETS">
 		<obj-attribute name="estimatedPrice" type="java.math.BigDecimal" db-attribute-path="ESTIMATED_PRICE"/>
 		<obj-attribute name="paintingsCount" type="java.lang.Integer" db-attribute-path="PAINTINGS_COUNT"/>
@@ -571,4 +576,38 @@
 	<query name="QueryWithSharedCache" factory="org.apache.cayenne.map.SelectQueryBuilder"
root="obj-entity" root-name="Artist">
 		<property name="cayenne.GenericSelectQuery.cachePolicy" value="sharedcache"/>
 	</query>
+
+    <obj-entity name="ArtistCallbackTest" className="org.apache.art.ArtistCallbackTest"
dbEntityName="ARTIST_CT">
+        <obj-attribute name="artistName" type="java.lang.String" db-attribute-path="ARTIST_NAME"/>
+        <obj-attribute name="dateOfBirth" type="java.util.Date" db-attribute-path="DATE_OF_BIRTH"/>
+
+        <entity-listener class="org.apache.art.EntityListenerObjEntity">
+            <pre-persist method-name="prePersistEntityListener"/>
+            <post-persist method-name="postPersistEntityListener"/>
+            <pre-update method-name="preUpdateEntityListener"/>
+            <post-update method-name="postUpdateEntityListener"/>
+            <pre-remove method-name="preRemoveEntityListener"/>
+            <post-remove method-name="postRemoveEntityListener"/>
+            <post-load method-name="postLoadEntityListener"/>
+        </entity-listener>
+
+        <pre-persist method-name="prePersistEntityObjEntity"/>
+        <post-persist method-name="postPersistEntityObjEntity"/>
+        <pre-update method-name="preUpdateEntityObjEntity"/>
+        <post-update method-name="postUpdateEntityObjEntity"/>
+        <pre-remove method-name="preRemoveEntityObjEntity"/>
+        <post-remove method-name="postRemoveEntityObjEntity"/>
+        <post-load method-name="postLoadEntityObjEntity"/>
+    </obj-entity>
+
+    <entity-listener class="org.apache.art.EntityListenerDataMap">
+        <pre-persist method-name="prePersistDataMap1"/>
+        <pre-persist method-name="prePersistDataMap2"/>
+        <post-persist method-name="postPersistDataMap"/>
+        <pre-update method-name="preUpdateDataMap"/>
+        <post-update method-name="postUpdateDataMap"/>
+        <pre-remove method-name="preRemoveDataMap"/>
+        <post-remove method-name="postRemoveDataMap"/>
+        <post-load method-name="postLoadDataMap"/>
+    </entity-listener>
 </data-map>



Mime
View raw message