📄 objectwithmanager.vm
字号:
set${col.JavaName}(new Float(((NumberKey) keys[$i]).floatValue())); #elseif($fktype == "Double") set${col.JavaName}(new Double(((NumberKey) keys[$i]).doubleValue())); #elseif($fktype == "String") set${col.JavaName}(keys[$i].toString()); #elseif($fktype == "Date") set${col.JavaName}(((DateKey)keys[$i]).getDate()); #end #set ( $i = $i + 1 ) #end #else #set ($colName = $fk.LocalColumns.get(0)) #set ($col = $table.getColumn($colName) ) #set ($fktype = $col.JavaNative) #if ($fktype == "short") set${col.JavaName}(((NumberKey) key).shortValue()); #elseif($fktype == "int") set${col.JavaName}(((NumberKey) key).intValue()); #elseif($fktype == "long") set${col.JavaName}(((NumberKey) key).longValue()); #elseif($fktype == "BigDecimal") set${col.JavaName}(((NumberKey) key).getBigDecimal()); #elseif($fktype == "byte") ) set${col.JavaName}(((NumberKey) key).byteValue()); #elseif($fktype == "float") set${col.JavaName}(((NumberKey) key).floatValue()); #elseif($fktype == "double") set${col.JavaName}(((NumberKey) key).doubleValue()); #elseif($fktype == "Short") set${col.JavaName}(new Short(((NumberKey) key).shortValue())); #elseif($fktype == "Integer") set${col.JavaName}(new Integer(((NumberKey) key).intValue())); #elseif($fktype == "Long") set${col.JavaName}(new Long(((NumberKey) key).longValue())); #elseif($fktype == "Byte") ) set${col.JavaName}(new Byte(((NumberKey) key).byteValue())); #elseif($fktype == "Float") set${col.JavaName}(new Float(((NumberKey) key).floatValue())); #elseif($fktype == "Double") set${col.JavaName}(new Double(((NumberKey) key).doubleValue())); #elseif($fktype == "String") set${col.JavaName}(key.toString()); #elseif($fktype == "Date") set${col.JavaName}(((DateKey)key).getDate()); #end #end } #end ## end of foreach loop over foreign keys ## ## setup foreign key associations ## #foreach ($fk in $table.Referrers) #set ( $tblFK = $fk.Table ) #if ( !($tblFK.Name.equals($table.Name)) ) #set ( $className = $tblFK.JavaName ) #set ( $relatedByCol = "" ) #foreach ($columnName in $fk.LocalColumns) #set ( $column = $tblFK.getColumn($columnName) ) #if ($column.isMultipleFK()) #set ($relatedByCol= "$relatedByCol$column.JavaName") #end #end #if ($relatedByCol == "") #set ( $suffix = "" ) #set ( $relCol = "${className}s" ) #set ( $relColMs = $className ) #else #set ( $suffix = "RelatedBy$relatedByCol" ) #set ( $relCol= "${className}sRelatedBy$relatedByCol" ) #set ( $relColMs= "${className}RelatedBy$relatedByCol" ) #end #set ( $collName = "coll$relCol" ) /** * Collection to store aggregation of $collName */ protected List $collName; /** * Temporary storage of $collName to save a possible db hit in * the event objects are add to the collection, but the * complete collection is never requested. */ protected void init${relCol}() { if ($collName == null) { $collName = new ArrayList(); } } #set ($interfaceName = $table.JavaName) #if ($table.Interface) #set ($interfaceName = $table.Interface) #end /** * Method called to associate a $tblFK.JavaName object to this object * through the $className foreign key attribute * * @param $className l */ public void add${relColMs}($className l) throws TorqueException { get${relCol}().add(l); l.set${interfaceName}${suffix}(($table.JavaName)this); } /** * The criteria used to select the current contents of $collName */ private Criteria last${relCol}Criteria = null; /** * If this collection has already been initialized, returns * the collection. Otherwise returns the results of * get${relCol}(new Criteria()) */ public List get${relCol}() throws TorqueException { if ($collName == null) { $collName = get${relCol}(new Criteria(10)); } return $collName; } /** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this $table.JavaName has previously * been saved, it will retrieve related ${relCol} from storage. * If this $table.JavaName is new, it will return * an empty collection or the current collection, the criteria * is ignored on a new object. */ public List get${relCol}(Criteria criteria) throws TorqueException { if ($collName == null) { if (isNew()) { $collName = new ArrayList(); } else { #foreach ($columnName in $fk.ForeignColumns) #set ( $column = $table.getColumn($columnName) ) #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) ) #set ( $colFK = $tblFK.getColumn($colFKName) ) criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() ); #end $collName = ${className}Peer.doSelect(criteria); } } else { // criteria has no effect for a new object if (!isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. #foreach ($columnName in $fk.ForeignColumns) #set ( $column = $table.getColumn($columnName) ) #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) ) #set ( $colFK = $tblFK.getColumn($colFKName) ) criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() ); #end if (!last${relCol}Criteria.equals(criteria)) { $collName = ${className}Peer.doSelect(criteria); } } } last${relCol}Criteria = criteria; return $collName; } /** * If this collection has already been initialized, returns * the collection. Otherwise returns the results of * get${relCol}(new Criteria(),Connection) * This method takes in the Connection also as input so that * referenced objects can also be obtained using a Connection * that is taken as input */ public List get${relCol}(Connection con) throws TorqueException { if ($collName == null) { $collName = get${relCol}(new Criteria(10),con); } return $collName; } /** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this $table.JavaName has previously * been saved, it will retrieve related ${relCol} from storage. * If this $table.JavaName is new, it will return * an empty collection or the current collection, the criteria * is ignored on a new object. * This method takes in the Connection also as input so that * referenced objects can also be obtained using a Connection * that is taken as input */ public List get${relCol}(Criteria criteria,Connection con) throws TorqueException { if ($collName == null) { if (isNew()) { $collName = new ArrayList(); } else { #foreach ($columnName in $fk.ForeignColumns) #set ( $column = $table.getColumn($columnName) ) #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) ) #set ( $colFK = $tblFK.getColumn($colFKName) ) criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() ); #end $collName = ${className}Peer.doSelect(criteria,con); } } else { // criteria has no effect for a new object if (!isNew()) { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. #foreach ($columnName in $fk.ForeignColumns) #set ( $column = $table.getColumn($columnName) ) #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) ) #set ( $colFK = $tblFK.getColumn($colFKName) ) criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() ); #end if (!last${relCol}Criteria.equals(criteria)) { $collName = ${className}Peer.doSelect(criteria,con); } } } last${relCol}Criteria = criteria; return $collName; } #set ( $countFK = 0 ) #foreach ($dummyFK in $tblFK.ForeignKeys) #set ( $countFK = $countFK + 1 ) #end## ------------------------------------------------------------## #if ($countFK >= 1) #set ( $lastTable = "" ) #foreach ($fk2 in $tblFK.ForeignKeys) ## Add join methods if the fk2 table is not this table or ## the fk2 table references this table multiple times. #set ( $doJoinGet = true ) #if ( $fk2.ForeignTableName.equals($table.Name) ) #set ( $doJoinGet = false ) #end #foreach ($columnName in $fk2.LocalColumns) #set ( $column = $tblFK.getColumn($columnName) ) #if ($column.isMultipleFK()) #set ( $doJoinGet = true ) #end #end #set ( $tblFK2 = $table.Database.getTable($fk2.ForeignTableName) ) #if ($tblFK2.isForReferenceOnly()) #set ($doJoinGet = false) #else #set ($doJoinGet = true) #end #set ( $relatedByCol2 = "" ) #foreach ($columnName in $fk2.LocalColumns) #set ( $column = $tblFK.getColumn($columnName) ) #if ($column.isMultipleFK()) #set($relatedByCol2 = "$relatedByCol2$column.JavaName") #end #end #set ( $fkClassName = $tblFK2.JavaName ) ## do not generate code for self-referencing fk's, it would be ## good to do, but it is just not implemented yet. #if ($className == $fkClassName) #set ( $doJoinGet = false ) #end #if ($relatedByCol2 == "") #set ( $relCol2 = $fkClassName ) #else #set ($relCol2 = "${fkClassName}RelatedBy$relatedByCol2") #end #if ( $relatedByCol == "") #else #if ( $relatedByCol.equals($relatedByCol2) ) #set ( $doJoinGet = false ) #end #end #if ($doJoinGet) /** * If this collection has already been initialized with * an identical criteria, it returns the collection. * Otherwise if this $table.JavaName is new, it will return * an empty collection; or if this $table.JavaName has previously * been saved, it will retrieve related ${relCol} from storage. * * This method is protected by default in order to keep the public * api reasonable. You can provide public methods for those you * actually need in ${table.JavaName}. */ protected List get${relCol}Join${relCol2}(Criteria criteria) throws TorqueException { if ($collName == null) { if (isNew()) { $collName = new ArrayList(); } else { #foreach ($columnName in $fk.ForeignColumns) #set ( $column = $table.getColumn($columnName) ) #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) ) #set ( $colFK = $tblFK.getColumn($colFKName) ) criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() ); #end $collName = ${className}Peer.doSelectJoin${relCol2}(criteria); } } else { // the following code is to determine if a new query is // called for. If the criteria is the same as the last // one, just return the collection. boolean newCriteria = true; #foreach ($columnName in $fk.ForeignColumns) #set ( $column = $table.getColumn($columnName) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -