cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r577428 - in /cayenne/main/trunk/framework/cayenne-jpa-unpublished/src: main/java/org/apache/cayenne/jpa/bridge/ main/java/org/apache/cayenne/jpa/map/ test/java/org/apache/cayenne/jpa/bridge/
Date Wed, 19 Sep 2007 20:00:29 GMT
Author: aadamchik
Date: Wed Sep 19 13:00:29 2007
New Revision: 577428

URL: http://svn.apache.org/viewvc?rev=577428&view=rev
Log:
(CAY-848) Support for mapping to-many as Maps and Sets and Collections
(passing jpa collection metadata to Cayenne runtime)

Modified:
    cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
    cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/map/JpaPropertyDescriptor.java
    cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterRelationshipsTest.java

Modified: cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java?rev=577428&r1=577427&r2=577428&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/bridge/DataMapConverter.java
Wed Sep 19 13:00:29 2007
@@ -492,7 +492,7 @@
             BaseTreeVisitor attributeVisitor = new BaseTreeVisitor();
             attributeVisitor.addChildVisitor(
                     JpaManyToOne.class,
-                    new JpaRelationshipVisitor());
+                    new JpaManyToOneVisitor());
             attributeVisitor.addChildVisitor(JpaOneToOne.class, new JpaOneToOneVisitor());
             attributeVisitor.addChildVisitor(
                     JpaOneToMany.class,
@@ -571,20 +571,32 @@
         }
     }
 
+    class JpaManyToOneVisitor extends JpaRelationshipVisitor {
+
+        @Override
+        Object createObject(ProjectPath path) {
+            ObjRelationship objRelationship = (ObjRelationship) super.createObject(path);
+            return objRelationship.getDbRelationships().get(0);
+        }
+    }
+
     class JpaOneToManyVisitor extends JpaRelationshipVisitor {
 
         @Override
         Object createObject(ProjectPath path) {
-            JpaDbRelationship relationship = (JpaDbRelationship) super.createObject(path);
+            ObjRelationship objRelationship = (ObjRelationship) super.createObject(path);
+            JpaDbRelationship relationship = (JpaDbRelationship) objRelationship
+                    .getDbRelationships()
+                    .get(0);
 
             if (relationship != null) {
                 JpaOneToMany jpaRelationship = (JpaOneToMany) path.getObject();
                 relationship.setMappedBy(jpaRelationship.getMappedBy());
-                
-                
-                if(jpaRelationship.getMapKey() != null) {
-                    
-                }
+                objRelationship.setMapKey(jpaRelationship.getMapKey());
+
+                objRelationship.setCollectionType(jpaRelationship
+                        .getPropertyDescriptor()
+                        .getType().getName());
             }
             return relationship;
         }
@@ -594,7 +606,10 @@
 
         @Override
         Object createObject(ProjectPath path) {
-            JpaDbRelationship relationship = (JpaDbRelationship) super.createObject(path);
+            ObjRelationship objRelationship = (ObjRelationship) super.createObject(path);
+            JpaDbRelationship relationship = (JpaDbRelationship) objRelationship
+                    .getDbRelationships()
+                    .get(0);
 
             if (relationship != null) {
                 JpaOneToOne jpaRelationship = (JpaOneToOne) path.getObject();
@@ -608,7 +623,10 @@
 
         @Override
         Object createObject(ProjectPath path) {
-            JpaDbRelationship relationship = (JpaDbRelationship) super.createObject(path);
+            ObjRelationship objRelationship = (ObjRelationship) super.createObject(path);
+            JpaDbRelationship relationship = (JpaDbRelationship) objRelationship
+                    .getDbRelationships()
+                    .get(0);
 
             if (relationship != null) {
                 JpaManyToMany jpaRelationship = (JpaManyToMany) path.getObject();
@@ -618,7 +636,7 @@
         }
     }
 
-    class JpaRelationshipVisitor extends NestedVisitor {
+    abstract class JpaRelationshipVisitor extends NestedVisitor {
 
         JpaRelationshipVisitor() {
             addChildVisitor(JpaJoinColumn.class, new JpaJoinColumnVisitor());
@@ -662,7 +680,7 @@
             cayenneSrcDbEntity.addRelationship(dbRelationship);
             cayenneRelationship.addDbRelationship(dbRelationship);
 
-            return dbRelationship;
+            return cayenneRelationship;
         }
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/map/JpaPropertyDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/map/JpaPropertyDescriptor.java?rev=577428&r1=577427&r2=577428&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/map/JpaPropertyDescriptor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/main/java/org/apache/cayenne/jpa/map/JpaPropertyDescriptor.java
Wed Sep 19 13:00:29 2007
@@ -47,7 +47,7 @@
         this.member = field;
         this.name = field.getName();
         this.type = field.getType();
-        this.genericType = field.getGenericType();
+        initTargetEntityType(field.getGenericType());
     }
 
     public JpaPropertyDescriptor(Method getter, String name) {
@@ -60,10 +60,10 @@
         this.member = getter;
         this.name = name;
         this.type = getter.getReturnType();
-        this.genericType = getter.getGenericReturnType();
+        initTargetEntityType(getter.getGenericReturnType());
     }
 
-    protected void processTargetEntityType() {
+    protected void initTargetEntityType(Type genericType) {
 
         this.targetEntityType = Void.TYPE;
 
@@ -79,6 +79,7 @@
             }
         }
         else if (Map.class.isAssignableFrom(type)) {
+
             if (genericType instanceof ParameterizedType) {
                 ParameterizedType pType = (ParameterizedType) genericType;
                 Type[] types = pType.getActualTypeArguments();
@@ -107,10 +108,6 @@
     }
 
     public Class getTargetEntityType() {
-        if (targetEntityType == null) {
-            processTargetEntityType();
-        }
-
         return Void.TYPE.equals(targetEntityType) ? null : targetEntityType;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterRelationshipsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterRelationshipsTest.java?rev=577428&r1=577427&r2=577428&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterRelationshipsTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jpa-unpublished/src/test/java/org/apache/cayenne/jpa/bridge/DataMapConverterRelationshipsTest.java
Wed Sep 19 13:00:29 2007
@@ -54,18 +54,19 @@
 
         assertEquals(1, e3.getRelationships().size());
         assertEquals(1, e4.getRelationships().size());
-        
+
         ObjRelationship or3 = (ObjRelationship) e3.getRelationship("entity4");
         ObjRelationship or4 = (ObjRelationship) e4.getRelationship("entity3s");
-        
+
         assertEquals("entity4", or3.getDbRelationshipPath());
         assertEquals("entity3s", or4.getDbRelationshipPath());
-        
+
         assertEquals("Entity4", or3.getTargetEntityName());
         assertEquals("Entity3", or4.getTargetEntityName());
-        
-       // assertEquals("key", or4.getMapKey());
-        
+
+        assertEquals("key", or4.getMapKey());
+        assertEquals("java.util.Map", or4.getCollectionType());
+
         DbEntity db3 = dataMap.getDbEntity("Entity3");
         DbEntity db4 = dataMap.getDbEntity("Entity4");
 



Mime
View raw message