You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by an...@apache.org on 2009/11/24 21:29:56 UTC

svn commit: r883858 [2/2] - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/r...

Added: cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/light-superclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/light-superclass.vm?rev=883858&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/light-superclass.vm (added)
+++ cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/light-superclass.vm Tue Nov 24 20:29:54 2009
@@ -0,0 +1,194 @@
+##   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.
+##
+##Terminology:
+##	Base class - super superclass of entity, ie, org.apache.cayenne.PersistentObject or MyBaseClass
+##  Super class - superclass of entity, ie,  org.apache.cayenne.art.auto._Artist
+##	Sub class - class of entity, ie, org.apache.cayenne.art.Artist
+##
+##  Classes available in template
+##    object (duplicated as 'objEntity') - the ObjEntity class: See org.apache.cayenne.map.ObjectEntity
+##    stringUtils - class for string "helper" functions: See org.apache.cayenne.gen.StringUtils
+##    entityUtils - class for entity "helper" functions: See org.apache.cayenne.gen.EntityUtils
+##    importUtils - class for import statement management: See org.apache.cayenne.gen.ImportUtils
+##    superClassName
+##    superPackageName
+##    subClassName
+##    subPackageName
+##    baseClassName
+##    basePackageName
+##
+##
+${importUtils.setPackage($superPackageName)}##
+${importUtils.addReservedType("${$superPackageName}.${superClassName}")}##
+${importUtils.addType("${basePackageName}.${baseClassName}")}##
+#foreach( $attr in ${object.DeclaredAttributes} )
+$importUtils.addType(${attr.Type})##
+#end
+#foreach( $rel in ${object.DeclaredRelationships} )
+$importUtils.addType(${rel.TargetEntity.ClassName})##
+#if(${rel.CollectionType}) 
+$importUtils.addType(${rel.CollectionType})##
+#end
+#end
+#if( ${entityUtils.hasToOneDeclaredRelationships()} )
+${importUtils.addType('org.apache.cayenne.ValueHolder')}##
+#end
+${importUtils.generate()}
+
+/**
+ * A generated persistent class mapped as "${object.name}" 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 ${superClassName} extends ${baseClassName} {
+
+## Create ivars names
+#foreach( $attr in ${object.DeclaredAttributes} )
+    public static final String ${stringUtils.capitalizedAsConstant($attr.Name)}_PROPERTY = "${attr.Name}";
+#end
+#foreach( $rel in ${object.DeclaredRelationships} )
+    public static final String ${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY = "${rel.Name}";
+#end
+
+## Create ivars
+#foreach( $attr in ${object.DeclaredAttributes} )
+    protected $importUtils.formatJavaType(${attr.Type}) ${attr.Name};
+#end
+#foreach( $rel in ${object.DeclaredRelationships} )
+#if( $rel.ToMany )
+#if ( ${rel.CollectionType} == "java.util.Map")
+    protected $importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)), $importUtils.formatJavaType($rel.TargetEntity.ClassName)> ${rel.Name};
+#else
+    protected $importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClassName)> ${rel.Name};
+#end
+#else
+    protected ValueHolder ${rel.Name};
+#end
+#end
+
+## Create attribute set/get methods
+#foreach( $attr in ${object.DeclaredAttributes} )
+#if ( $importUtils.isBoolean(${attr.Type}) )
+    public boolean is${stringUtils.capitalized($attr.Name)}() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "${attr.Name}", false);
+        }
+
+        return ${attr.Name};
+    }
+#else 
+    public $importUtils.formatJavaType(${attr.Type}) get${stringUtils.capitalized($attr.Name)}() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "${attr.Name}", false);
+        }
+
+        return ${attr.Name};
+    }
+#end
+#if ("true" != "${object.isReadOnly()}")
+    public void set${stringUtils.capitalized($attr.Name)}($importUtils.formatJavaType(${attr.Type}) $stringUtils.formatVariableName(${attr.Name})) {
+        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 )
+#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)}() {
+#else
+    public $importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClassName)> get${stringUtils.capitalized($rel.Name)}() {
+#end
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "${rel.Name}", true);
+        }
+
+        return ${rel.Name};
+    }
+#if ( ! $rel.ReadOnly )
+#if ( ${rel.CollectionType} == "java.util.Map")
+	public void addTo${stringUtils.capitalized($rel.Name)}($importUtils.formatJavaType(${rel.TargetEntity.ClassName}) 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.ClassName}) 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.ClassName}) object) {
+        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.ClassName}) object) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "${rel.Name}", true);
+        }
+
+        this.${rel.Name}.remove(object);
+    }
+#end
+#end
+#else
+    public $importUtils.formatJavaType(${rel.TargetEntity.ClassName}) get${stringUtils.capitalized($rel.Name)}() {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "${rel.Name}", true);
+        }
+
+        return ($importUtils.formatJavaType(${rel.TargetEntity.ClassName})) ${rel.Name}.getValue();
+    }
+#if ( !${object.isReadOnly()} && !$rel.ReadOnly )
+    public void set${stringUtils.capitalized($rel.Name)}(${importUtils.formatJavaType($rel.TargetEntity.ClassName)} $stringUtils.formatVariableName(${rel.Name})) {
+        if(objectContext != null) {
+            objectContext.prepareForAccess(this, "${rel.Name}", true);
+        }
+
+        this.${stringUtils.formatVariableName($rel.Name)}.setValue(${stringUtils.formatVariableName($rel.Name)});
+    }
+#end
+#end
+
+#end
+##callback methods
+#foreach( $cbname in ${entityUtils.callbackNames})
+    protected abstract void ${cbname}();
+
+#end
+}