cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r505835 - in /cayenne/main/branches/STABLE-1.2/cayenne: cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/ cayenne-java/src/tests/java/org/objectstyle/cayenne/unit/jira/ cayenne-java/src/tests/resources/cay743/ cayenne-other/release...
Date Sun, 11 Feb 2007 04:48:27 GMT
Author: aadamchik
Date: Sat Feb 10 20:48:26 2007
New Revision: 505835

URL: http://svn.apache.org/viewvc?view=rev&rev=505835
Log:
CAY-741 Indexing entities with inheritance across datamaps, CAY-743 Reordering mappings from
domain in xml resulting in StackOverflowException - 1.2 branch

Added:
    cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/unit/jira/CAY_743Tst.java
    cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/
    cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/cayenne.xml
    cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/map1.map.xml
    cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/map2.map.xml
Modified:
    cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/EntityResolver.java
    cayenne/main/branches/STABLE-1.2/cayenne/cayenne-other/release-notes/RELEASE-NOTES-1.2.3.txt

Modified: cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/EntityResolver.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/EntityResolver.java?view=diff&rev=505835&r1=505834&r2=505835
==============================================================================
--- cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/EntityResolver.java
(original)
+++ cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/cayenne/java/org/objectstyle/cayenne/map/EntityResolver.java
Sat Feb 10 20:48:26 2007
@@ -265,9 +265,23 @@
         clearCache();
 
         // rebuild index
-        Iterator mapIterator = maps.iterator();
-        while (mapIterator.hasNext()) {
-            DataMap map = (DataMap) mapIterator.next();
+
+        // index DbEntities separatly and before ObjEntities to avoid infinite loops when
+        // looking up DbEntities during ObjEntity index op
+        Iterator mapIterator0 = maps.iterator();
+        while (mapIterator0.hasNext()) {
+            DataMap map = (DataMap) mapIterator0.next();
+
+            Iterator dbEntities = map.getDbEntities().iterator();
+            while (dbEntities.hasNext()) {
+                DbEntity de = (DbEntity) dbEntities.next();
+                dbEntityCache.put(de.getName(), de);
+            }
+        }
+
+        Iterator mapIterator1 = maps.iterator();
+        while (mapIterator1.hasNext()) {
+            DataMap map = (DataMap) mapIterator1.next();
 
             // index ObjEntities
             Iterator objEntities = map.getObjEntities().iterator();
@@ -304,11 +318,10 @@
                         objEntityCache.put(entityClass, oe);
                     }
 
-                    // TODO: Andrus, 12/13/2005 - An invalid DbEntity name will cause
-                    // 'getDbEntity' to go into an
-                    // infinite loop as "getDbEntity" will try to resolve DbEntity via a
-                    // parent namespace (which will be this resolver).
-                    if (oe.getDbEntity() != null) {
+                    // lookup DbEntity in EntityResolver cache to take into account all
+                    // DataMaps in the namespace
+                    Object dbEntity = dbEntityCache.get(oe.getDbEntityName());
+                    if (dbEntity != null) {
                         Object existingDB = dbEntityCache.get(entityClass);
                         if (existingDB != null) {
 
@@ -317,14 +330,40 @@
                             }
                         }
                         else {
-                            dbEntityCache.put(entityClass, oe.getDbEntity());
+                            dbEntityCache.put(entityClass, dbEntity);
                         }
                     }
                 }
             }
 
+            // index stored procedures
+            Iterator procedures = map.getProcedures().iterator();
+            while (procedures.hasNext()) {
+                Procedure proc = (Procedure) procedures.next();
+                procedureCache.put(proc.getName(), proc);
+            }
+
+            // index queries
+            Iterator queries = map.getQueries().iterator();
+            while (queries.hasNext()) {
+                Query query = (Query) queries.next();
+                String name = query.getName();
+                Object existingQuery = queryCache.put(name, query);
+
+                if (existingQuery != null && query != existingQuery) {
+                    throw new CayenneRuntimeException("More than one Query for name"
+                            + name);
+                }
+            }
+        }
+
+        // restart the map iterator to index inheritance
+        Iterator mapIterator2 = maps.iterator();
+        while (mapIterator2.hasNext()) {
+            DataMap map = (DataMap) mapIterator2.next();
+
             // index ObjEntity inheritance
-            objEntities = map.getObjEntities().iterator();
+            Iterator objEntities = map.getObjEntities().iterator();
             while (objEntities.hasNext()) {
                 ObjEntity oe = (ObjEntity) objEntities.next();
 
@@ -359,33 +398,6 @@
                     }
 
                     superNode.addChildNode(node);
-                }
-            }
-
-            // index DbEntities
-            Iterator dbEntities = map.getDbEntities().iterator();
-            while (dbEntities.hasNext()) {
-                DbEntity de = (DbEntity) dbEntities.next();
-                dbEntityCache.put(de.getName(), de);
-            }
-
-            // index stored procedures
-            Iterator procedures = map.getProcedures().iterator();
-            while (procedures.hasNext()) {
-                Procedure proc = (Procedure) procedures.next();
-                procedureCache.put(proc.getName(), proc);
-            }
-
-            // index queries
-            Iterator queries = map.getQueries().iterator();
-            while (queries.hasNext()) {
-                Query query = (Query) queries.next();
-                String name = query.getName();
-                Object existingQuery = queryCache.put(name, query);
-
-                if (existingQuery != null && query != existingQuery) {
-                    throw new CayenneRuntimeException("More than one Query for name"
-                            + name);
                 }
             }
         }

Added: cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/unit/jira/CAY_743Tst.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/unit/jira/CAY_743Tst.java?view=auto&rev=505835
==============================================================================
--- cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/unit/jira/CAY_743Tst.java
(added)
+++ cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/java/org/objectstyle/cayenne/unit/jira/CAY_743Tst.java
Sat Feb 10 20:48:26 2007
@@ -0,0 +1,107 @@
+/* ====================================================================
+ *
+ * The ObjectStyle Group Software License, version 1.1
+ * ObjectStyle Group - http://objectstyle.org/
+ *
+ * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
+ * of the software. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any,
+ *    must include the following acknowlegement:
+ *    "This product includes software developed by independent contributors
+ *    and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
+ *    Alternately, this acknowlegement may appear in the software itself,
+ *    if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
+ *    or promote products derived from this software without prior written
+ *    permission. For written permission, email
+ *    "andrus at objectstyle dot org".
+ *
+ * 5. Products derived from this software may not be called "ObjectStyle"
+ *    or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
+ *    names without prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals and hosted on ObjectStyle Group web site.  For more
+ * information on the ObjectStyle Group, please see
+ * <http://objectstyle.org/>.
+ */
+package org.objectstyle.cayenne.unit.jira;
+
+import java.io.InputStream;
+
+import org.objectstyle.cayenne.access.DataDomain;
+import org.objectstyle.cayenne.conf.DefaultConfiguration;
+import org.objectstyle.cayenne.map.DataMap;
+import org.objectstyle.cayenne.map.ObjEntity;
+import junit.framework.TestCase;
+
+public class CAY_743Tst extends TestCase {
+
+    public void testLoad2MapsWithCrossMapInheritance() throws Exception {
+
+        DefaultConfiguration config = new DefaultConfiguration() {
+
+            protected InputStream getDomainConfiguration() {
+                return Thread
+                        .currentThread()
+                        .getContextClassLoader()
+                        .getResourceAsStream("cay743/cayenne.xml");
+            }
+
+            protected InputStream getMapConfiguration(String location) {
+                return Thread
+                        .currentThread()
+                        .getContextClassLoader()
+                        .getResourceAsStream("cay743/" + location);
+            }
+        };
+        config.initialize();
+
+        DataDomain domain = config.getDomain();
+        assertEquals(2, domain.getDataMaps().size());
+
+        DataMap m1 = domain.getMap("map1");
+        DataMap m2 = domain.getMap("map2");
+
+        ObjEntity oe11 = m1.getObjEntity("Entity11");
+        ObjEntity oe12 = m1.getObjEntity("Entity12");
+
+        ObjEntity oe21 = m2.getObjEntity("Entity21");
+        ObjEntity oe22 = m2.getObjEntity("Entity22");
+
+        // this causes StackOverflow per CAY-743
+        ObjEntity oe21Super = oe21.getSuperEntity();
+        ObjEntity oe12Super = oe12.getSuperEntity();
+
+        assertSame(oe12Super, oe22);
+        assertSame(oe21Super, oe11);
+    }
+}

Added: cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/cayenne.xml
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/cayenne.xml?view=auto&rev=505835
==============================================================================
--- cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/cayenne.xml
(added)
+++ cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/cayenne.xml
Sat Feb 10 20:48:26 2007
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<domains project-version="2.0">
+<domain name="domain">
+	<map name="map1" location="map1.map.xml"/>
+	<map name="map2" location="map2.map.xml"/>
+</domain>
+</domains>

Added: cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/map1.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/map1.map.xml?view=auto&rev=505835
==============================================================================
--- cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/map1.map.xml
(added)
+++ cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/map1.map.xml
Sat Feb 10 20:48:26 2007
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map project-version="2.0">
+	<obj-entity name="Entity11">
+	</obj-entity>
+	<obj-entity name="Entity12" superEntityName="Entity22">
+	</obj-entity>
+</data-map>

Added: cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/map2.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/map2.map.xml?view=auto&rev=505835
==============================================================================
--- cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/map2.map.xml
(added)
+++ cayenne/main/branches/STABLE-1.2/cayenne/cayenne-java/src/tests/resources/cay743/map2.map.xml
Sat Feb 10 20:48:26 2007
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map project-version="2.0">
+	<obj-entity name="Entity21" superEntityName="Entity11">
+	</obj-entity>
+	<obj-entity name="Entity22">
+	</obj-entity>
+</data-map>

Modified: cayenne/main/branches/STABLE-1.2/cayenne/cayenne-other/release-notes/RELEASE-NOTES-1.2.3.txt
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-1.2/cayenne/cayenne-other/release-notes/RELEASE-NOTES-1.2.3.txt?view=diff&rev=505835&r1=505834&r2=505835
==============================================================================
--- cayenne/main/branches/STABLE-1.2/cayenne/cayenne-other/release-notes/RELEASE-NOTES-1.2.3.txt
(original)
+++ cayenne/main/branches/STABLE-1.2/cayenne/cayenne-other/release-notes/RELEASE-NOTES-1.2.3.txt
Sat Feb 10 20:48:26 2007
@@ -10,4 +10,6 @@
 
 Bug Fixes:
 
+CAY-741 Indexing entities with inheritance across datamaps
+CAY-743 Reordering mappings from domain in xml resulting in StackOverflowException
 CAY-750 Stored procedures without parameters fail on Postgres 8



Mime
View raw message