cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r429162 - in /incubator/cayenne/main/trunk/core/cayenne-jpa/src: main/java/org/apache/cayenne/jpa/conf/ main/java/org/apache/cayenne/jpa/map/ main/java/org/apache/cayenne/util/ test/java/org/apache/cayenne/jpa/map/
Date Sun, 06 Aug 2006 17:25:58 GMT
Author: aadamchik
Date: Sun Aug  6 10:25:57 2006
New Revision: 429162

URL: http://svn.apache.org/viewvc?rev=429162&view=rev
Log:
fixing defaults tests

Added:
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/map/EntityMapTraversalTest.java
Modified:
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributes.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManagedClass.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/util/BaseTreeVisitor.java
    incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/util/HierarchicalTreeVisitor.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java?rev=429162&r1=429161&r2=429162&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/conf/EntityMapDefaultsProcessor.java
Sun Aug  6 10:25:57 2006
@@ -82,6 +82,7 @@
 
         AbstractEntityVisitor() {
             BaseTreeVisitor attributeVisitor = new BaseTreeVisitor();
+            attributeVisitor.addChildVisitor(JpaId.class, new IdVisitor());
             attributeVisitor.addChildVisitor(JpaBasic.class, new BasicVisitor());
             attributeVisitor.addChildVisitor(JpaManyToOne.class, new FKVisitor());
             attributeVisitor.addChildVisitor(JpaOneToOne.class, new FKVisitor());
@@ -274,7 +275,7 @@
                 JpaColumn column = new JpaColumn(AnnotationPrototypes.getColumn());
                 column.setName(id.getName());
 
-                JpaEntity entity = (JpaEntity) path.getObjectParent();
+                JpaEntity entity = (JpaEntity) path.firstInstanceOf(JpaEntity.class);
                 column.setTable(entity.getTable().getName());
                 id.setColumn(column);
             }

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributes.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributes.java?rev=429162&r1=429161&r2=429162&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributes.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaAttributes.java
Sun Aug  6 10:25:57 2006
@@ -216,6 +216,7 @@
         return ids;
     }
 
+    @TreeNodeChild
     public JpaEmbeddedId getEmbeddedId() {
         return embeddedId;
     }
@@ -224,6 +225,7 @@
         this.embeddedId = embeddedId;
     }
 
+    @TreeNodeChild(type = JpaBasic.class)
     public Collection<JpaBasic> getBasicAttributes() {
         if (basicAttributes == null) {
             basicAttributes = new ArrayList<JpaBasic>();
@@ -231,6 +233,7 @@
         return basicAttributes;
     }
 
+    @TreeNodeChild(type = JpaEmbedded.class)
     public Collection<JpaEmbedded> getEmbeddedAttributes() {
         if (embeddedAttributes == null) {
             embeddedAttributes = new ArrayList<JpaEmbedded>();
@@ -254,6 +257,7 @@
         return null;
     }
 
+    @TreeNodeChild(type = JpaManyToMany.class)
     public Collection<JpaManyToMany> getManyToManyRelationships() {
         if (manyToManyRelationships == null) {
             manyToManyRelationships = new ArrayList<JpaManyToMany>();
@@ -277,6 +281,7 @@
         return null;
     }
 
+    @TreeNodeChild(type = JpaManyToOne.class)
     public Collection<JpaManyToOne> getManyToOneRelationships() {
         if (manyToOneRelationships == null) {
             manyToOneRelationships = new ArrayList<JpaManyToOne>();
@@ -284,6 +289,7 @@
         return manyToOneRelationships;
     }
 
+    @TreeNodeChild(type = JpaOneToMany.class)
     public Collection<JpaOneToMany> getOneToManyRelationships() {
         if (oneToManyRelationships == null) {
             oneToManyRelationships = new ArrayList<JpaOneToMany>();
@@ -291,6 +297,7 @@
         return oneToManyRelationships;
     }
 
+    @TreeNodeChild(type = JpaOneToOne.class)
     public Collection<JpaOneToOne> getOneToOneRelationships() {
         if (oneToOneRelationships == null) {
             oneToOneRelationships = new ArrayList<JpaOneToOne>();
@@ -314,6 +321,7 @@
         return null;
     }
 
+    @TreeNodeChild(type = JpaTransient.class)
     public Collection<JpaTransient> getTransientAttributes() {
         if (transientAttributes == null) {
             transientAttributes = new ArrayList<JpaTransient>();
@@ -340,6 +348,7 @@
         return null;
     }
 
+    @TreeNodeChild(type = JpaVersion.class)
     public Collection<JpaVersion> getVersionAttributes() {
         if (versionAttributes == null) {
             versionAttributes = new ArrayList<JpaVersion>();

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManagedClass.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManagedClass.java?rev=429162&r1=429161&r2=429162&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManagedClass.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/jpa/map/JpaManagedClass.java
Sun Aug  6 10:25:57 2006
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.jpa.map;
 
+import org.apache.cayenne.util.TreeNodeChild;
+
 public abstract class JpaManagedClass {
 
     protected JpaClassDescriptor classDescriptor;
@@ -70,6 +72,7 @@
         this.description = description;
     }
 
+    @TreeNodeChild
     public JpaAttributes getAttributes() {
         if (attributes == null) {
             attributes = new JpaAttributes();

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/util/BaseTreeVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/util/BaseTreeVisitor.java?rev=429162&r1=429161&r2=429162&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/util/BaseTreeVisitor.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/util/BaseTreeVisitor.java
Sun Aug  6 10:25:57 2006
@@ -17,7 +17,6 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.util;
 
 import java.util.HashMap;

Modified: incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/util/HierarchicalTreeVisitor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/util/HierarchicalTreeVisitor.java?rev=429162&r1=429161&r2=429162&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/util/HierarchicalTreeVisitor.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/main/java/org/apache/cayenne/util/HierarchicalTreeVisitor.java
Sun Aug  6 10:25:57 2006
@@ -17,7 +17,6 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.util;
 
 import org.apache.cayenne.project.ProjectPath;
@@ -27,7 +26,7 @@
  * 
  * @author Andrus Adamchik
  */
-//TODO, andrus, 4/24/2006 - move to Cayenne core in 2.0
+// TODO, andrus, 4/24/2006 - move to Cayenne core in 2.0
 public interface HierarchicalTreeVisitor {
 
     /**

Added: incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/map/EntityMapTraversalTest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/map/EntityMapTraversalTest.java?rev=429162&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/map/EntityMapTraversalTest.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jpa/src/test/java/org/apache/cayenne/jpa/map/EntityMapTraversalTest.java
Sun Aug  6 10:25:57 2006
@@ -0,0 +1,90 @@
+/*****************************************************************
+ *   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.jpa.map;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.project.ProjectPath;
+import org.apache.cayenne.util.HierarchicalTreeVisitor;
+import org.apache.cayenne.util.TraversalUtil;
+
+/**
+ * Tests traversal annotations.
+ * 
+ * @author Andrus Adamchik
+ */
+public class EntityMapTraversalTest extends TestCase {
+
+    public void testTraversal() {
+        JpaEntityMap map = new JpaEntityMap();
+
+        JpaEntity e1 = new JpaEntity();
+        map.getEntities().add(e1);
+
+        JpaBasic a1 = new JpaBasic();
+        e1.getAttributes().getBasicAttributes().add(a1);
+
+        JpaId a2 = new JpaId();
+        e1.getAttributes().getIds().add(a2);
+        
+        JpaColumn c1 = new JpaColumn();
+        a1.setColumn(c1);
+        
+        JpaColumn c2 = new JpaColumn();
+        a2.setColumn(c2);
+
+        JpaMappedSuperclass m1 = new JpaMappedSuperclass();
+        map.getMappedSuperclasses().add(m1);
+
+        TestVisitor visitor = new TestVisitor();
+        TraversalUtil.traverse(map, visitor);
+
+        assertTrue(visitor.isVisited(map));
+        assertTrue(visitor.isVisited(e1));
+        assertTrue(visitor.isVisited(a1));
+        assertTrue(visitor.isVisited(a2));
+        assertTrue(visitor.isVisited(c1));
+        assertTrue(visitor.isVisited(c2));
+        assertTrue(visitor.isVisited(m1));
+    }
+
+    class TestVisitor implements HierarchicalTreeVisitor {
+
+        protected Collection visitedNodes = new ArrayList();
+
+        public HierarchicalTreeVisitor childVisitor(ProjectPath path, Class childType) {
+            return this;
+        }
+
+        public boolean isVisited(Object node) {
+            return visitedNodes.contains(node);
+        }
+
+        public void onFinishNode(ProjectPath path) {
+            visitedNodes.add(path.getObject());
+        }
+
+        public boolean onStartNode(ProjectPath path) {
+            return true;
+        }
+    }
+}



Mime
View raw message