templates.v4_1.datamap-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
##
## https://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.GenericPersistentObject 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
## stringUtils - class for string "helper" functions: See org.apache.cayenne.gen.StringUtils
## dataMapUtils - class for query "helper" functions: See org.apache.cayenne.gen.DataMapUtils
## importUtils - class for import statement management: See org.apache.cayenne.gen.ImportUtils
## superClassName
## superPackageName
## subClassName
## subPackageName
## baseClassName
## basePackageName
##
${importUtils.setPackage($superPackageName)}##
#if(${superPackageName})${importUtils.addReservedType("${superPackageName}.${superClassName}")}#end##
#if(${basePackageName})${importUtils.addType("${basePackageName}.${baseClassName}")}#end##
${importUtils.addType('org.apache.cayenne.ObjectContext')}##
#if( ${object.hasSelectQueries()} )
${importUtils.addType('java.util.List')}##
${importUtils.addType('org.apache.cayenne.query.MappedSelect')}##
#foreach( $selectQuery in ${object.SelectQueries})
${importUtils.addType(${selectQuery.Root.ClassName})}##
#if(${dataMapUtils.isValidParameterNames($selectQuery)})
#foreach( $parameter in ${dataMapUtils.getParameterNames(${selectQuery})})
${importUtils.addType(${dataMapUtils.getParameterType(${selectQuery}, ${parameter})})}##
#end##
#end##
#end##
#end##
#if($object.hasExecQueries())##
${importUtils.addType('java.util.Map')}##
${importUtils.addType('org.apache.cayenne.QueryResult')}##
${importUtils.addType('org.apache.cayenne.query.MappedExec')}##
#end##
${importUtils.generate()}
/**
* This class 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 class ${superClassName} {
#if( ${object.hasQueryNames()})
#foreach( $qname in ${object.queryNames})
public static final String ${stringUtils.capitalizedAsConstant($qname)}_QUERYNAME = "$qname";
#end
#end
#foreach( $selectQuery in ${object.SelectQueries})
#if(${dataMapUtils.isValidParameterNames($selectQuery)})
#set($rootClass = ${stringUtils.stripPackageName($selectQuery.Root.ClassName)})
public List<$rootClass> perform${dataMapUtils.getQueryMethodName(${selectQuery})}(ObjectContext context#foreach( $parameter in ${dataMapUtils.getParameterNames(${selectQuery})}), ${stringUtils.stripPackageName(${dataMapUtils.getParameterType(${selectQuery}, ${parameter})})} ${parameter}#end) {
MappedSelect<${rootClass}> query = MappedSelect.query(${stringUtils.capitalizedAsConstant(${selectQuery.Name})}_QUERYNAME, ${rootClass}.class);
#foreach( $parameter in ${dataMapUtils.getParameterNames(${selectQuery})})
query.param("${parameter}", ${parameter});
#end
return query.select(context);
}
#end
#end
#foreach( $execQuery in ${object.ExecQueries})
public QueryResult> perform${dataMapUtils.getQueryMethodName(${execQuery})}(ObjectContext context, Map parameters) {
MappedExec query = MappedExec.query(${stringUtils.capitalizedAsConstant(${execQuery.Name})}_QUERYNAME).params(parameters);
return query.execute(context);
}
#end
}