![JAR search and dependency download from the Maven repository](/logo.png)
templates.v1_2.superclass.vm Maven / Gradle / Ivy
## 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.CayenneDataObject 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}")}##
#if((${object.DeclaredAttributes} && !${object.DeclaredAttributes.isEmpty()}) || (${object.DeclaredRelationships} && !${object.DeclaredRelationships.isEmpty()}))
${importUtils.addType('org.apache.cayenne.exp.Property')}##
#end
#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
${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.
*/
public abstract class ${superClassName} extends ${baseClassName} {
private static final long serialVersionUID = 1L;
## Create property names
#if( $createPropertyNames )
#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
#end
#if( $object.DbEntity )
#foreach( $idAttr in ${object.DbEntity.PrimaryKeys} )
public static final String ${stringUtils.capitalizedAsConstant($idAttr.Name)}_PK_COLUMN = "${idAttr.Name}";
#end
#end
## Create Properties
#foreach( $attr in ${object.DeclaredAttributes} )
#set ( $type = "$importUtils.formatJavaType(${attr.Type}, false)")
public static final Property<$type> ${stringUtils.capitalizedAsConstant($attr.Name)} = Property.create("${attr.Name}", ${stringUtils.stripGeneric($type)}.class);
#end
#foreach( $rel in ${object.DeclaredRelationships} )
#if( $rel.ToMany )
#if ( ${rel.CollectionType} == "java.util.Map")
#set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)), $importUtils.formatJavaType($rel.TargetEntity.ClassName)>" )
public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)} = Property.create("${rel.Name}", ${stringUtils.stripGeneric($type)}.class);
#else
#set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClassName)>" )
public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)} = Property.create("${rel.Name}", ${stringUtils.stripGeneric($type)}.class);
#end
#else
#set( $type = "$importUtils.formatJavaType(${rel.TargetEntity.ClassName})" )
public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)} = Property.create("${rel.Name}", ${stringUtils.stripGeneric($type)}.class);
#end
#end
## Create attribute set/get methods
#foreach( $attr in ${object.DeclaredAttributes} )
#if ("true" != "${object.isReadOnly()}")
public void set${stringUtils.capitalized($attr.Name)}($importUtils.formatJavaType(${attr.Type}) $stringUtils.formatVariableName(${attr.Name})) {
writeProperty("${attr.Name}", $stringUtils.formatVariableName(${attr.Name}));
}
#end
#if ( $importUtils.isBoolean(${attr.Type}) )
public boolean is${stringUtils.capitalized($attr.Name)}() {
Boolean value = (Boolean)readProperty("${attr.Name}");
return (value != null) ? value.booleanValue() : false;
}
#elseif ( $importUtils.isNonBooleanPrimitive(${attr.Type}) )
public ${importUtils.formatJavaType($attr.Type)} get${stringUtils.capitalized($attr.Name)}() {
Object value = readProperty("${attr.Name}");
return (value != null) ? ($importUtils.formatJavaTypeAsNonBooleanPrimitive(${attr.Type})) value : 0;
}
#else
public $importUtils.formatJavaType(${attr.Type}) get${stringUtils.capitalized($attr.Name)}() {
return ($importUtils.formatJavaType(${attr.Type}))readProperty("${attr.Name}");
}
#end
#end
##
## Create list add/remove/get methods
#foreach( $rel in ${object.DeclaredRelationships} )
#if( $rel.ToMany )
#if ( ! $rel.ReadOnly )
public void addTo${stringUtils.capitalized($rel.Name)}($importUtils.formatJavaType(${rel.TargetEntity.ClassName}) obj) {
addToManyTarget("${rel.Name}", obj, true);
}
public void removeFrom${stringUtils.capitalized($rel.Name)}($importUtils.formatJavaType(${rel.TargetEntity.ClassName}) obj) {
removeToManyTarget("${rel.Name}", obj, true);
}
#end
@SuppressWarnings("unchecked")
#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);
}
#end
public $importUtils.formatJavaType(${rel.TargetEntity.ClassName}) get${stringUtils.capitalized($rel.Name)}() {
return ($importUtils.formatJavaType(${rel.TargetEntity.ClassName}))readProperty("${rel.Name}");
}
#end
#end
##
##callback methods
#foreach($cbname in ${entityUtils.callbackNames})
protected abstract void ${cbname}();
#end
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy