cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r584509 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src: main/java/org/apache/cayenne/ main/resources/dotemplates/v1_2/ test/java/org/apache/cayenne/testdo/mt/ test/java/org/apache/cayenne/testdo/mt/auto/ test/resources/
Date Sun, 14 Oct 2007 08:26:32 GMT
Author: aadamchik
Date: Sun Oct 14 01:26:31 2007
New Revision: 584509

URL: http://svn.apache.org/viewvc?rev=584509&view=rev
Log:
CAY-848 Support for mapping to-many as Maps and Sets and Collections
(fixing ROP templates)

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/ClientMtMapToMany.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/ClientMtMapToManyTarget.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/MtMapToMany.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/MtMapToManyTarget.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtMapToMany.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtMapToManyTarget.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtMapToMany.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtMapToManyTarget.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/PersistentObject.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/resources/dotemplates/v1_2/client-superclass.vm
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/multi-tier.map.xml

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/PersistentObject.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/PersistentObject.java?rev=584509&r1=584508&r2=584509&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/PersistentObject.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/PersistentObject.java
Sun Oct 14 01:26:31 2007
@@ -19,6 +19,11 @@
 
 package org.apache.cayenne;
 
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.reflect.ClassDescriptor;
+import org.apache.cayenne.reflect.Property;
+import org.apache.cayenne.reflect.ToManyMapProperty;
+
 /**
  * A convenience base superclass for concrete Persistent objects. Provides implementation
  * of properties declared in Persistent interface.
@@ -71,6 +76,32 @@
 
     public void setObjectId(ObjectId objectId) {
         this.objectId = objectId;
+    }
+    
+    /**
+     * Returns a map key for a given to-many map relationship and a target object.
+     * 
+     * @since 3.0
+     */
+    protected Object getMapKey(String relationshipName, Object value) {
+
+        EntityResolver resolver = objectContext.getEntityResolver();
+        ClassDescriptor descriptor = resolver
+                .getClassDescriptor(objectId.getEntityName());
+
+        if (descriptor == null) {
+            throw new IllegalStateException("DataObject's entity is unmapped, objectId: "
+                    + objectId);
+        }
+
+        Property property = descriptor.getProperty(relationshipName);
+        if (property instanceof ToManyMapProperty) {
+            return ((ToManyMapProperty) property).getMapKey(value);
+        }
+
+        throw new IllegalArgumentException("Relationship '"
+                + relationshipName
+                + "' is not a to-many Map");
     }
 
     public String toString() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/resources/dotemplates/v1_2/client-superclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/resources/dotemplates/v1_2/client-superclass.vm?rev=584509&r1=584508&r2=584509&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/resources/dotemplates/v1_2/client-superclass.vm
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/resources/dotemplates/v1_2/client-superclass.vm
Sun Oct 14 01:26:31 2007
@@ -108,6 +108,22 @@
         return ${rel.Name};
     }
 #if ( ! $rel.ReadOnly )
+#if ( ${rel.CollectionType} == "java.util.Map")
+	public void addTo${stringUtils.capitalized($rel.Name)}($importUtils.formatJavaType(${rel.TargetEntity.ClientClassName})
object) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "${rel.Name}", true);
+        }
+        
+        this.${rel.Name}.put(getMapKey("${rel.Name}", object), object);
+    }
+    public void removeFrom${stringUtils.capitalized($rel.Name)}($importUtils.formatJavaType(${rel.TargetEntity.ClientClassName})
object) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "${rel.Name}", true);
+        }
+        
+        this.${rel.Name}.remove(getMapKey("${rel.Name}", object));
+    }
+#else
     public void addTo${stringUtils.capitalized($rel.Name)}($importUtils.formatJavaType(${rel.TargetEntity.ClientClassName})
object) {
         if(objectContext != null) {
             objectContext.prepareForAccess(this, "${rel.Name}", true);
@@ -122,6 +138,7 @@
         
         this.${rel.Name}.remove(object);
     }
+#end
 #end
 #else
     public $importUtils.formatJavaType(${rel.TargetEntity.ClientClassName}) get${stringUtils.capitalized($rel.Name)}()
{

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/ClientMtMapToMany.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/ClientMtMapToMany.java?rev=584509&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/ClientMtMapToMany.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/ClientMtMapToMany.java
Sun Oct 14 01:26:31 2007
@@ -0,0 +1,10 @@
+package org.apache.cayenne.testdo.mt;
+
+import org.apache.cayenne.testdo.mt.auto._ClientMtMapToMany;
+
+/**
+ * A persistent class mapped as "MtMapToMany" Cayenne entity.
+ */
+public class ClientMtMapToMany extends _ClientMtMapToMany {
+
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/ClientMtMapToManyTarget.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/ClientMtMapToManyTarget.java?rev=584509&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/ClientMtMapToManyTarget.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/ClientMtMapToManyTarget.java
Sun Oct 14 01:26:31 2007
@@ -0,0 +1,10 @@
+package org.apache.cayenne.testdo.mt;
+
+import org.apache.cayenne.testdo.mt.auto._ClientMtMapToManyTarget;
+
+/**
+ * A persistent class mapped as "MtMapToManyTarget" Cayenne entity.
+ */
+public class ClientMtMapToManyTarget extends _ClientMtMapToManyTarget {
+
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/MtMapToMany.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/MtMapToMany.java?rev=584509&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/MtMapToMany.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/MtMapToMany.java
Sun Oct 14 01:26:31 2007
@@ -0,0 +1,10 @@
+package org.apache.cayenne.testdo.mt;
+
+import org.apache.cayenne.testdo.mt.auto._MtMapToMany;
+
+public class MtMapToMany extends _MtMapToMany {
+
+}
+
+
+

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/MtMapToManyTarget.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/MtMapToManyTarget.java?rev=584509&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/MtMapToManyTarget.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/MtMapToManyTarget.java
Sun Oct 14 01:26:31 2007
@@ -0,0 +1,10 @@
+package org.apache.cayenne.testdo.mt;
+
+import org.apache.cayenne.testdo.mt.auto._MtMapToManyTarget;
+
+public class MtMapToManyTarget extends _MtMapToManyTarget {
+
+}
+
+
+

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtMapToMany.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtMapToMany.java?rev=584509&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtMapToMany.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtMapToMany.java
Sun Oct 14 01:26:31 2007
@@ -0,0 +1,39 @@
+package org.apache.cayenne.testdo.mt.auto;
+
+import org.apache.cayenne.PersistentObject;
+import org.apache.cayenne.testdo.mt.ClientMtMapToManyTarget;
+
+/**
+ * A generated persistent class mapped as "MtMapToMany" Cayenne entity. It is a good idea
to
+ * avoid changing this class manually, since it will be overwritten next time code is
+ * regenerated. If you need to make any customizations, put them in a subclass.
+ */
+public abstract class _ClientMtMapToMany extends PersistentObject {
+
+    public static final String TARGETS_PROPERTY = "targets";
+
+    protected java.util.Map targets;
+
+    public java.util.Map getTargets() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "targets", true);
+        }
+        
+        return targets;
+    }
+	public void addToTargets(ClientMtMapToManyTarget object) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "targets", true);
+        }
+        
+        this.targets.put(getMapKey("targets", object), object);
+    }
+    public void removeFromTargets(ClientMtMapToManyTarget object) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "targets", true);
+        }
+        
+        this.targets.remove(getMapKey("targets", object));
+    }
+    
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtMapToManyTarget.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtMapToManyTarget.java?rev=584509&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtMapToManyTarget.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_ClientMtMapToManyTarget.java
Sun Oct 14 01:26:31 2007
@@ -0,0 +1,33 @@
+package org.apache.cayenne.testdo.mt.auto;
+
+import org.apache.cayenne.PersistentObject;
+import org.apache.cayenne.ValueHolder;
+import org.apache.cayenne.testdo.mt.ClientMtMapToMany;
+
+/**
+ * A generated persistent class mapped as "MtMapToManyTarget" Cayenne entity. It is a good
idea to
+ * avoid changing this class manually, since it will be overwritten next time code is
+ * regenerated. If you need to make any customizations, put them in a subclass.
+ */
+public abstract class _ClientMtMapToManyTarget extends PersistentObject {
+
+    public static final String MAP_TO_MANY_PROPERTY = "mapToMany";
+
+    protected ValueHolder mapToMany;
+
+    public ClientMtMapToMany getMapToMany() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "mapToMany", true);
+        }
+        
+        return (ClientMtMapToMany) mapToMany.getValue();
+    }
+    public void setMapToMany(ClientMtMapToMany mapToMany) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "mapToMany", true);
+        }
+        
+        this.mapToMany.setValue(mapToMany);
+    }
+    
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtMapToMany.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtMapToMany.java?rev=584509&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtMapToMany.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtMapToMany.java
Sun Oct 14 01:26:31 2007
@@ -0,0 +1,25 @@
+package org.apache.cayenne.testdo.mt.auto;
+
+/** Class _MtMapToMany 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 _MtMapToMany extends org.apache.cayenne.CayenneDataObject {
+
+    public static final String TARGETS_PROPERTY = "targets";
+
+    public static final String ID_PK_COLUMN = "ID";
+
+    public void addToTargets(org.apache.cayenne.testdo.mt.MtMapToManyTarget obj) {
+        addToManyTarget("targets", obj, true);
+    }
+    public void removeFromTargets(org.apache.cayenne.testdo.mt.MtMapToManyTarget obj) {
+        removeToManyTarget("targets", obj, true);
+    }
+    public java.util.Map getTargets() {
+        return (java.util.Map)readProperty("targets");
+    }
+    
+    
+}

Added: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtMapToManyTarget.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtMapToManyTarget.java?rev=584509&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtMapToManyTarget.java
(added)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/java/org/apache/cayenne/testdo/mt/auto/_MtMapToManyTarget.java
Sun Oct 14 01:26:31 2007
@@ -0,0 +1,23 @@
+package org.apache.cayenne.testdo.mt.auto;
+
+/** Class _MtMapToManyTarget 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 _MtMapToManyTarget extends org.apache.cayenne.CayenneDataObject {
+
+    public static final String MAP_TO_MANY_PROPERTY = "mapToMany";
+
+    public static final String ID_PK_COLUMN = "ID";
+
+    public void setMapToMany(org.apache.cayenne.testdo.mt.MtMapToMany mapToMany) {
+        setToOneTarget("mapToMany", mapToMany, true);
+    }
+
+    public org.apache.cayenne.testdo.mt.MtMapToMany getMapToMany() {
+        return (org.apache.cayenne.testdo.mt.MtMapToMany)readProperty("mapToMany");
+    } 
+    
+    
+}

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/multi-tier.map.xml
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/multi-tier.map.xml?rev=584509&r1=584508&r2=584509&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/multi-tier.map.xml
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/test/resources/multi-tier.map.xml
Sun Oct 14 01:26:31 2007
@@ -26,6 +26,13 @@
 		<db-attribute name="TABLE4_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
 		<db-attribute name="TABLE5_ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
 	</db-entity>
+	<db-entity name="MT_MAP_TO_MANY">
+		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+	</db-entity>
+	<db-entity name="MT_MAP_TO_MANY_TARGET">
+		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+		<db-attribute name="MAP_TO_MANY_ID" type="INTEGER"/>
+	</db-entity>
 	<db-entity name="MT_REFLEXIVE">
 		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
 		<db-attribute name="NAME" type="VARCHAR" isMandatory="true" length="200"/>
@@ -65,6 +72,10 @@
 	<obj-entity name="MtDeleteRule" className="org.apache.cayenne.testdo.mt.MtDeleteRule"
clientClassName="org.apache.cayenne.testdo.mt.ClientMtDeleteRule" dbEntityName="MT_DELETE_RULE">
 		<obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
 	</obj-entity>
+	<obj-entity name="MtMapToMany" className="org.apache.cayenne.testdo.mt.MtMapToMany" clientClassName="org.apache.cayenne.testdo.mt.ClientMtMapToMany"
dbEntityName="MT_MAP_TO_MANY">
+	</obj-entity>
+	<obj-entity name="MtMapToManyTarget" className="org.apache.cayenne.testdo.mt.MtMapToManyTarget"
clientClassName="org.apache.cayenne.testdo.mt.ClientMtMapToManyTarget" dbEntityName="MT_MAP_TO_MANY_TARGET">
+	</obj-entity>
 	<obj-entity name="MtReflexive" className="org.apache.cayenne.testdo.mt.MtReflexive" clientClassName="org.apache.cayenne.testdo.mt.ClientMtReflexive"
dbEntityName="MT_REFLEXIVE">
 		<obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
 	</obj-entity>
@@ -111,6 +122,12 @@
 	<db-relationship name="toTable5" source="MT_JOIN45" target="MT_TABLE5" toMany="false">
 		<db-attribute-pair source="TABLE5_ID" target="ID"/>
 	</db-relationship>
+	<db-relationship name="targets" source="MT_MAP_TO_MANY" target="MT_MAP_TO_MANY_TARGET"
toMany="true">
+		<db-attribute-pair source="ID" target="MAP_TO_MANY_ID"/>
+	</db-relationship>
+	<db-relationship name="mapToMany" source="MT_MAP_TO_MANY_TARGET" target="MT_MAP_TO_MANY"
toMany="false">
+		<db-attribute-pair source="MAP_TO_MANY_ID" target="ID"/>
+	</db-relationship>
 	<db-relationship name="children" source="MT_REFLEXIVE" target="MT_REFLEXIVE" toMany="true">
 		<db-attribute-pair source="ID" target="PARENT_ID"/>
 	</db-relationship>
@@ -135,6 +152,8 @@
 	<obj-relationship name="fromCascade" source="MtDeleteRule" target="MtDeleteCascade" db-relationship-path="fromCascade"/>
 	<obj-relationship name="fromDeny" source="MtDeleteRule" target="MtDeleteDeny" db-relationship-path="fromDeny"/>
 	<obj-relationship name="fromNullify" source="MtDeleteRule" target="MtDeleteNullify" db-relationship-path="fromNullify"/>
+	<obj-relationship name="targets" source="MtMapToMany" target="MtMapToManyTarget" collection-type="java.util.Map"
db-relationship-path="targets"/>
+	<obj-relationship name="mapToMany" source="MtMapToManyTarget" target="MtMapToMany" db-relationship-path="mapToMany"/>
 	<obj-relationship name="children" source="MtReflexive" target="MtReflexive" db-relationship-path="children"/>
 	<obj-relationship name="toParent" source="MtReflexive" target="MtReflexive" db-relationship-path="toParent"/>
 	<obj-relationship name="table2Array" source="MtTable1" target="MtTable2" db-relationship-path="table2Array"/>



Mime
View raw message