📄 peer.vm
字号:
## ## setup joins ## #set ( $className = $table.JavaName ) #set ( $countFK = 0 ) #foreach ($dummyFK in $table.ForeignKeys) #set ( $countFK = $countFK + 1 ) #end #if ($countFK >= 1) #foreach ($fk in $table.ForeignKeys) #set ( $tblFK = $table.Database.getTable($fk.ForeignTableName) ) #if (!$tblFK.isForReferenceOnly()) ## want to cover this case, but the code is not there yet. #if ( !($fk.ForeignTableName.equals($table.Name)) ) #set ( $partJoinName = "" ) #foreach ($columnName in $fk.LocalColumns) #set ( $column = $table.getColumn($columnName) ) #if ($column.isMultipleFK() || $fk.ForeignTableName.equals($table.Name)) #set ( $partJoinName = "$partJoinName$column.JavaName" ) #end #end #set ( $joinTable = $table.Database.getTable($fk.ForeignTableName) ) #set ( $joinClassName = $joinTable.JavaName ) #set ($interfaceName = $joinTable.JavaName) #if ($joinTable.Interface) #set ($interfaceName = $joinTable.Interface) #end #if ($partJoinName == "") #set ( $joinColumnId = $joinClassName ) #set ( $joinInterface = $interfaceName ) #set ( $collThisTable = "${className}s" ) #set ( $collThisTableMs = $className ) #else #set ( $joinColumnId= "${joinClassName}RelatedBy$partJoinName" ) #set ( $joinInterface= "${interfaceName}RelatedBy$partJoinName" ) #set ( $collThisTable="${className}sRelatedBy$partJoinName" ) #set ( $collThisTableMs="${className}RelatedBy$partJoinName" ) #end## ------------------------------------------------------------ /** * selects a collection of $className objects pre-filled with their * $joinClassName objects. * * 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}Peer. * * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ protected static List doSelectJoin${joinColumnId}(Criteria c) throws TorqueException { // Set the correct dbName if it has not been overridden // c.getDbName will return the same object if not set to // another value so == check is okay and faster if (c.getDbName() == Torque.getDefaultDB()) { c.setDbName(DATABASE_NAME); } ${table.JavaName}Peer.addSelectColumns(c); int offset = numColumns + 1; ${joinClassName}Peer.addSelectColumns(c); #set ( $lfMap = $fk.LocalForeignMapping ) #foreach ($columnName in $fk.LocalColumns) #set ( $column = $table.getColumn($columnName) ) #set ( $columnFk = $joinTable.getColumn( $lfMap.get($columnName) ) ) c.addJoin(${table.JavaName}Peer.$column.Name.toUpperCase(), ${joinClassName}Peer.$columnFk.Name.toUpperCase()); #end #foreach ($col in $table.Columns) #set ( $cup=$col.Name.toUpperCase() ) #if($col.isBooleanInt()) // check for conversion from boolean to int if (c.containsKey($cup)) { Object possibleBoolean = c.get($cup); if (possibleBoolean instanceof Boolean) { if (((Boolean) possibleBoolean).booleanValue()) { c.add($cup, 1); } else { c.add($cup, 0); } } } #elseif ($col.isBooleanChar()) // check for conversion from boolean to Y/N if ( c.containsKey($cup) ) { Object possibleBoolean = c.get($cup); if (possibleBoolean instanceof Boolean) { if (((Boolean) possibleBoolean).booleanValue()) { c.add($cup, "Y"); } else { c.add($cup, "N"); } } } #end #end List rows = BasePeer.doSelect(c); List results = new ArrayList(); for (int i = 0; i < rows.size(); i++) { Record row = (Record) rows.get(i); #set ($classDecl = "Class") #if ($table.ChildrenColumn) $classDecl omClass = ${table.JavaName}Peer.getOMClass(row, 1); #else $classDecl omClass = ${table.JavaName}Peer.getOMClass(); #end #set ($classDecl = "") $className obj1 = ($className) ${table.JavaName}Peer .row2Object(row, 1, omClass); #if ($joinTable.ChildrenColumn) $classDecl omClass = ${joinClassName}Peer.getOMClass(row, offset); #else $classDecl omClass = ${joinClassName}Peer.getOMClass(); #end #set ($classDecl = "") $joinClassName obj2 = ($joinClassName)${joinClassName}Peer .row2Object(row, offset, omClass); boolean newObject = true; for (int j = 0; j < results.size(); j++) { $className temp_obj1 = ($className)results.get(j); $joinClassName temp_obj2 = ($joinClassName)temp_obj1.get${joinInterface}(); if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey())) { newObject = false; temp_obj2.add${collThisTableMs}(obj1); break; } } if (newObject) { obj2.init${collThisTable}(); obj2.add${collThisTableMs}(obj1); } results.add(obj1); } return results; } #end #end #end #end ## =========================================================== #if ($countFK > 2) #set ($includeJoinAll = true) #foreach ($fk in $table.ForeignKeys) #set ( $tblFK = $table.Database.getTable($fk.ForeignTableName) ) #if ($tblFK.isForReferenceOnly()) #set ($includeJoinAll = false) #end #end #if ($includeJoinAll) #foreach ($fk in $table.ForeignKeys) #set ( $tblFK = $table.Database.getTable($fk.ForeignTableName) ) #set ( $excludeTable = $table.Database.getTable($fk.ForeignTableName) ) #set ( $excludeClassName = $excludeTable.JavaName ) #set ( $relatedByCol = "" ) #foreach ($columnName in $fk.LocalColumns) #set ( $column = $table.getColumn($columnName) ) #if ($column.isMultipleFK()) #set ($relatedByCol = "$relatedByCol$column.JavaName") #end #end #if ($relatedByCol == "") #set ( $excludeString = $excludeClassName ) #set ( $collThisTable = "${className}s" ) #set ( $collThisTableMs = $className ) #else #set ( $excludeString="${excludeClassName}RelatedBy$relatedByCol" ) #set ( $collThisTable="${className}sRelatedBy$relatedByCol" ) #set ( $collThisTableMs="${className}RelatedBy$relatedByCol" ) #end /** * selects a collection of $className objects pre-filled with * all related objects. * * 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}Peer. * * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ protected static List doSelectJoinAllExcept${excludeString}(Criteria c) throws TorqueException { // Set the correct dbName if it has not been overridden // c.getDbName will return the same object if not set to another value // so == check is okay and faster if (c.getDbName() == Torque.getDefaultDB()) { c.setDbName(DATABASE_NAME); } addSelectColumns(c); int offset2 = numColumns + 1; #set ( $index = 2 ) #foreach ($fk in $table.ForeignKeys) ## want to cover this case, but the code is not there yet. #if ( !($fk.ForeignTableName.equals($table.Name)) ) #set ( $joinTable = $table.Database.getTable($fk.ForeignTableName) ) #set ( $joinClassName = $joinTable.JavaName ) #if (!$joinClassName.equals($excludeClassName)) #set ( $new_index = $index + 1 ) ${joinClassName}Peer.addSelectColumns(c); int offset$new_index = offset$index + ${joinClassName}Peer.numColumns; #set ( $index = $new_index ) #end #end #end #foreach ($col in $table.Columns) #set ( $cup=$col.Name.toUpperCase() ) #if($col.isBooleanInt()) // check for conversion from boolean to int if (c.containsKey($cup)) { Object possibleBoolean = c.get($cup); if (possibleBoolean instanceof Boolean) { if (((Boolean) possibleBoolean).booleanValue()) { c.add($cup, 1); } else { c.add($cup, 0); } } } #elseif ($col.isBooleanChar()) // check for conversion from boolean to Y/N if ( c.containsKey($cup) ) { Object possibleBoolean = c.get($cup); if (possibleBoolean instanceof Boolean) { if (((Boolean) possibleBoolean).booleanValue()) { c.add($cup, "Y"); } else { c.add($cup, "N"); } } } #end #end List rows = BasePeer.doSelect(c); List results = new ArrayList(); for (int i = 0; i < rows.size(); i++) { Record row = (Record)rows.get(i); #set ($classDecl = "Class") #if ($table.ChildrenColumn) $classDecl omClass = ${table.JavaName}Peer.getOMClass(row, 1); #else $classDecl omClass = ${table.JavaName}Peer.getOMClass(); #end #set ($classDecl = "") $className obj1 = ($className)${table.JavaName}Peer .row2Object(row, 1, omClass); #set ( $index = 1 ) #foreach ($fk in $table.ForeignKeys) ## want to cover this case, but the code is not there yet. #if ( !($fk.ForeignTableName.equals($table.Name)) ) #set ( $joinTable = $table.Database.getTable($fk.ForeignTableName) ) #set ( $joinClassName = $joinTable.JavaName ) #set ($interfaceName = $joinTable.JavaName) #if ($joinTable.Interface) #set ($interfaceName = $joinTable.Interface) #end #if (!$joinClassName.equals($excludeClassName)) #set ( $partJoinName = "" ) #foreach ($columnName in $fk.LocalColumns) #set ( $column = $table.getColumn($columnName) ) #if ($column.isMultipleFK()) #set ( $partJoinName = "$partJoinName$column.JavaName" ) #end #end #if ($partJoinName == "") #set ( $joinString = $interfaceName ) #set ( $collThisTable = "${className}s" ) #set ( $collThisTableMs = $className ) #else #set ( $joinString="${interfaceName}RelatedBy$partJoinName" ) #set ( $collThisTable="${className}sRelatedBy$partJoinName" ) #set ( $collThisTableMs="${className}RelatedBy$partJoinName" ) #end #set ( $index = $index + 1 ) #if ($joinTable.ChildrenColumn) $classDecl omClass = ${joinClassName}Peer.getOMClass(row, offset$index); #else $classDecl omClass = ${joinClassName}Peer.getOMClass(); #end #set ($classDecl = "") $joinClassName obj$index = ($joinClassName)${joinClassName}Peer .row2Object( row, offset$index, omClass); #if ($index == 2) boolean #end newObject = true; for (int j = 0; j < results.size(); j++) { $className temp_obj1 = ($className)results.get(j); $joinClassName temp_obj$index = ($joinClassName)temp_obj1.get${joinString}(); if (temp_obj${index}.getPrimaryKey().equals(obj${index}.getPrimaryKey())) { newObject = false; temp_obj${index}.add${collThisTableMs}(obj1); break; } } if (newObject) { obj${index}.init${collThisTable}(); obj${index}.add${collThisTableMs}(obj1); } #end #end #end results.add(obj1); } return results; } #end #end #end #end ## ------------------------------------------------------------ #if (!$table.isAlias()) /** * Returns the TableMap related to this peer. This method is not * needed for general use but a specific application could have a need. * * @throws TorqueException Any exceptions caught during processing will be * rethrown wrapped into a TorqueException. */ protected static TableMap getTableMap() throws TorqueException { return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME); } #end ## ends if (!$table.isAlias())}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -