cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmen...@apache.org
Subject svn commit: r603268 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main: java/org/apache/cayenne/gen/EntityUtils.java resources/dotemplates/v1_2/client-superclass.vm resources/dotemplates/v1_2/superclass.vm
Date Tue, 11 Dec 2007 15:20:48 GMT
Author: kmenard
Date: Tue Dec 11 07:20:48 2007
New Revision: 603268

URL: http://svn.apache.org/viewvc?rev=603268&view=rev
Log:
Fixed CAY-936: Update Velocity templates for generics.

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/client-superclass.vm
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/superclass.vm

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java?rev=603268&r1=603267&r2=603268&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java
Tue Dec 11 07:20:48 2007
@@ -19,10 +19,8 @@
 
 package org.apache.cayenne.gen;
 
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.map.MappingNamespace;
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.map.Relationship;
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.map.*;
 
 /**
  * Attributes and Methods for working with ObjEntities.
@@ -260,5 +258,34 @@
         }
 
         return false;
+    }
+
+    /**
+     * Returns the map key type for a collection relationship of type java.util.Map.
+     *
+     * @param relationship The relationship to look up type information for.
+     *
+     * @return The type of the attribute keyed on.
+     */
+    public String getMapKeyType(final ObjRelationship relationship) {
+
+        // If the map key is null, then we're doing look-ups by actual object key.
+        if (relationship.getMapKey() == null) {
+
+            // If it's a multi-column key, then the return type is always ObjectId.
+            DbEntity dbEntity = objEntity.getDbEntity();
+            if ((dbEntity != null) && (dbEntity.getPrimaryKeys().size() > 1))
{
+                return ObjectId.class.getName();
+            }
+
+            // If it's a single column key or no key exists at all, then we really don't
know what the key type is,
+            // so default to Object.
+            return Object.class.getName();
+        }
+
+        // If the map key is a non-default attribute, then fetch the attributue and return
its type.
+        final ObjAttribute attribute = (ObjAttribute) objEntity.getAttribute(relationship.getMapKey());
+
+        return attribute.getType();
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/client-superclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/client-superclass.vm?rev=603268&r1=603267&r2=603268&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/client-superclass.vm
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/client-superclass.vm
Tue Dec 11 07:20:48 2007
@@ -30,7 +30,7 @@
 ##    subClassName
 ##    subPackageName
 ##    baseClassName
-##    basePackageName 
+##    basePackageName
 ##
 ##
 ${importUtils.setPackage($superPackageName)}##
@@ -69,7 +69,11 @@
 #end
 #foreach( $rel in ${object.DeclaredRelationships} )
 #if( $rel.ToMany )
-    protected $importUtils.formatJavaType($rel.CollectionType) ${rel.Name};
+#if ( ${rel.CollectionType} == "java.util.Map")
+    protected $importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)),
$importUtils.formatJavaType($rel.TargetEntity.ClientClassName)> ${rel.Name};
+#else
+    protected $importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClientClassName)>
${rel.Name};
+#end
 #else
     protected ValueHolder ${rel.Name};
 #end
@@ -81,7 +85,7 @@
         if(objectContext != null) {
             objectContext.prepareForAccess(this, "${attr.Name}", false);
         }
-        
+
         return ${attr.Name};
     }
 #if ("true" != "${object.isReadOnly()}")
@@ -89,29 +93,33 @@
         if(objectContext != null) {
             objectContext.prepareForAccess(this, "${attr.Name}", false);
         }
-        
+
         Object oldValue = this.${stringUtils.formatVariableName($attr.Name)};
         this.${stringUtils.formatVariableName($attr.Name)} = ${stringUtils.formatVariableName($attr.Name)};
-        
+
         // notify objectContext about simple property change
         if(objectContext != null) {
             objectContext.propertyChanged(this, "${attr.Name}", oldValue, ${stringUtils.formatVariableName($attr.Name)});
         }
     }
 #end
-    
-    
+
+
 #end
 ##
 ##
 ## Create list add/remove/get methods
 #foreach( $rel in ${object.DeclaredRelationships} )
 #if( $rel.ToMany )
-    public $importUtils.formatJavaType($rel.CollectionType) get${stringUtils.capitalized($rel.Name)}()
{
+#if ( ${rel.CollectionType} == "java.util.Map")
+    public $importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)),
$importUtils.formatJavaType($rel.TargetEntity.ClientClassName)> get${stringUtils.capitalized($rel.Name)}()
{
+#else
+    public $importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClientClassName)>
get${stringUtils.capitalized($rel.Name)}() {
+#end
         if(objectContext != null) {
             objectContext.prepareForAccess(this, "${rel.Name}", true);
         }
-        
+
         return ${rel.Name};
     }
 #if ( ! $rel.ReadOnly )
@@ -120,14 +128,14 @@
         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
@@ -135,14 +143,14 @@
         if(objectContext != null) {
             objectContext.prepareForAccess(this, "${rel.Name}", true);
         }
-        
+
         this.${rel.Name}.add(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(object);
     }
 #end
@@ -152,7 +160,7 @@
         if(objectContext != null) {
             objectContext.prepareForAccess(this, "${rel.Name}", true);
         }
-        
+
         return ($importUtils.formatJavaType(${rel.TargetEntity.ClientClassName})) ${rel.Name}.getValue();
     }
 #if ( !${object.isReadOnly()} && !$rel.ReadOnly )
@@ -160,11 +168,11 @@
         if(objectContext != null) {
             objectContext.prepareForAccess(this, "${rel.Name}", true);
         }
-        
+
         this.${stringUtils.formatVariableName($rel.Name)}.setValue(${stringUtils.formatVariableName($rel.Name)});
     }
 #end
 #end
-    
+
 #end
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/superclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/superclass.vm?rev=603268&r1=603267&r2=603268&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/superclass.vm
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/superclass.vm
Tue Dec 11 07:20:48 2007
@@ -30,7 +30,7 @@
 ##    subClassName
 ##    subPackageName
 ##    baseClassName
-##    basePackageName 
+##    basePackageName
 ##
 ${importUtils.setPackage($superPackageName)}##
 ${importUtils.addReservedType("${superPackageName}.${superClassName}")}##
@@ -44,11 +44,11 @@
 #end
 ${importUtils.generate()}
 
-/** 
+/**
  * Class ${superClassName} 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. 
+ * 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 ${superClassName} extends ${baseClassName} {
 
@@ -81,7 +81,7 @@
 #elseif ( $importUtils.isNonBooleanPrimitive(${attr.Type}) )
     public $classGen.formatJavaType(${attr.Type}) get${stringUtils.capitalized($attr.Name)}()
{
         Object value = readProperty("${attr.Name}");
-        return (value != null) ? ($importUtils.formatJavaTypeAsNonBooleanPrimitive(${attr.Type}))
value : 0; 
+        return (value != null) ? ($importUtils.formatJavaTypeAsNonBooleanPrimitive(${attr.Type}))
value : 0;
     }
 #else
     public $importUtils.formatJavaType(${attr.Type}) get${stringUtils.capitalized($attr.Name)}()
{
@@ -102,10 +102,16 @@
         removeToManyTarget("${rel.name}", obj, true);
     }
 #end
-    public $importUtils.formatJavaType($rel.CollectionType) get${stringUtils.capitalized($rel.Name)}()
{
-        return ($importUtils.formatJavaType($rel.CollectionType))readProperty("${rel.name}");
+#if ( ${rel.CollectionType} == "java.util.Map")
+    public $importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)),
$importUtils.formatJavaType($rel.TargetEntity.ClassName)> get${stringUtils.capitalized($rel.Name)}()
{
+        return ($importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)),
$importUtils.formatJavaType($rel.TargetEntity.ClassName)>)readProperty("${rel.name}");
     }
 #else
+    public $importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClassName)>
get${stringUtils.capitalized($rel.Name)}() {
+        return ($importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClassName)>)readProperty("${rel.name}");
+    }
+#end
+#else
 #if ( !${object.isReadOnly()} && !$rel.ReadOnly )
     public void set${stringUtils.capitalized($rel.Name)}($importUtils.formatJavaType(${rel.TargetEntity.ClassName})
$stringUtils.formatVariableName(${rel.name})) {
         setToOneTarget("${rel.name}", $stringUtils.formatVariableName(${rel.name}), true);
@@ -114,9 +120,9 @@
 
     public $importUtils.formatJavaType(${rel.TargetEntity.ClassName}) get${stringUtils.capitalized($rel.Name)}()
{
         return ($importUtils.formatJavaType(${rel.TargetEntity.ClassName}))readProperty("${rel.name}");
-    } 
+    }
 #end
-    
-    
+
+
 #end
 }



Mime
View raw message