PageRenderTime 64ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/portlets/agenda/agenda/misc/torque-gen-3.1/templates/om/Object.vm

https://bitbucket.org/bureauvirtuel/bureauvirtuel
Unknown | 1596 lines | 1494 code | 102 blank | 0 comment | 0 complexity | 052ea61882938ca7ffb25f6931c67f40 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. package ${package};
  2. #if ($table.BaseClass == "")
  3. #set ($extendsBaseClass = "" )
  4. #else
  5. #set ($extendsBaseClass = "extends $table.BaseClass" )
  6. #end
  7. import java.math.BigDecimal;
  8. import java.sql.Connection;
  9. import java.util.ArrayList;
  10. import java.util.Date;
  11. import java.util.Collections;
  12. import java.util.List;
  13. import java.text.ParseException;
  14. import java.text.SimpleDateFormat;
  15. #if ($addSaveMethod)
  16. import org.apache.commons.lang.ObjectUtils;
  17. #end
  18. #if ($addIntakeRetrievable)
  19. import $retrievableInterface;
  20. #end
  21. #if (!$complexObjectModel)
  22. import org.apache.torque.Torque;
  23. #end
  24. import org.apache.commons.lang.time.DateFormatUtils;
  25. import org.apache.commons.lang.time.FastDateFormat;
  26. import org.apache.torque.TorqueException;
  27. import org.apache.torque.om.BaseObject;
  28. import org.apache.torque.om.ComboKey;
  29. import org.apache.torque.om.DateKey;
  30. import org.apache.torque.om.NumberKey;
  31. import org.apache.torque.om.ObjectKey;
  32. import org.apache.torque.om.SimpleKey;
  33. import org.apache.torque.om.StringKey;
  34. import org.apache.torque.om.Persistent;
  35. import org.apache.torque.util.Criteria;
  36. import org.apache.torque.util.Transaction;
  37. import org.w3c.dom.Document;
  38. import org.w3c.dom.Element;
  39. #foreach ($fk in $table.ForeignKeys)
  40. #set ( $tblFK = $table.Database.getTable($fk.ForeignTableName) )
  41. #set ( $className = $tblFK.JavaName )
  42. #if ($tblFK.Interface)
  43. #set ($className = $tblFK.Interface)
  44. #end
  45. #if ($tblFK.Package != $package)
  46. import ${tblFK.Package}.${className};
  47. import ${tblFK.Package}.${tblFK.JavaName}Peer;
  48. #end
  49. #end
  50. /**
  51. #if ($addTimeStamp)
  52. * This class was autogenerated by Torque on:
  53. *
  54. * [$now]
  55. *
  56. #end
  57. * You should not use this class directly. It should not even be
  58. * extended all references should be to $table.JavaName
  59. */
  60. public abstract class $basePrefix$table.JavaName $extendsBaseClass
  61. #if ($addIntakeRetrievable)
  62. implements $retrievableInterface
  63. #end
  64. {
  65. /** The Peer class */
  66. private static final ${table.JavaName}Peer peer =
  67. new ${table.JavaName}Peer();
  68. #if (!$table.isAlias())
  69. ## member variables
  70. #foreach ($col in $table.Columns)
  71. #set ( $cjtype = $col.JavaNative )
  72. #set ( $clo=$col.UncapitalisedJavaName )
  73. #set ($defVal = "")
  74. #if ($col.DefaultValue && !$col.DefaultValue.equalsIgnoreCase("NULL") )
  75. #set ( $quote = '' )
  76. #if ( $cjtype == "String" )
  77. #set ( $quote = '"' )
  78. #end
  79. #set ( $defaultValue = $col.DefaultValue )
  80. #if ( $cjtype == "boolean" || $cjtype == "Boolean" )
  81. #if ( $defaultValue == "1" || $defaultValue == "Y" )
  82. #set ( $defaultValue = "true" )
  83. #elseif ( $defaultValue == "0" || $defaultValue == "N" )
  84. #set ( $defaultValue = "false" )
  85. #end
  86. #end
  87. #if ($cjtype == "BigDecimal")
  88. #set ($defVal = "= new BigDecimal($defaultValue)")
  89. #elseif ($cjtype == "NumberKey")
  90. #set ( $quote = '"' )
  91. #set ($defVal = "= new NumberKey($quote$defaultValue$quote)")
  92. #elseif ($cjtype == "StringKey")
  93. #set ( $quote = '"' )
  94. #set ($defVal = "= new StringKey($quote$defaultValue$quote)")
  95. #else
  96. #if (!$col.isPrimitive() && $cjtype != "String")
  97. #set ( $defaultValue = "new ${cjtype}($defaultValue)" )
  98. #end
  99. #set ($defVal = " = $quote$defaultValue$quote")
  100. #end
  101. #end
  102. /** The value for the $clo field */
  103. private $cjtype $clo$defVal;
  104. #end
  105. ## getter and setter methods
  106. #foreach ($col in $table.Columns)
  107. #set ( $cfc=$col.JavaName )
  108. #set ( $clo=$col.UncapitalisedJavaName )
  109. #set ( $cjtype = $col.JavaNative )
  110. /**
  111. * Get the $cfc
  112. *
  113. * @return $cjtype
  114. */
  115. public $cjtype get${cfc}()
  116. {
  117. return $clo;
  118. }
  119. #set ( $throwsClause = "" )
  120. #if ($complexObjectModel)
  121. #if ($col.isForeignKey())
  122. #set ( $throwsClause = "throws TorqueException" )
  123. #end
  124. #if ( $col.Referrers.size() > 0 )
  125. #if ($throwsClause == "")
  126. #set ( $throwsClause = "throws TorqueException" )
  127. #end
  128. #end
  129. #end
  130. /**
  131. * Set the value of $cfc
  132. *
  133. * @param v new value
  134. */
  135. public void set${cfc}($cjtype v) $throwsClause
  136. {
  137. #if (($cjtype == "NumberKey") || ($cjtype == "StringKey") || ($cjtype == "DateKey"))
  138. if (v != null && v.getValue() == null)
  139. {
  140. // If this is an Objectkey than this set method is
  141. // probably storing the id of this object or some
  142. // associated object. If the objectKey value is null
  143. // then we convert the parameter to null so that this
  144. // property is consistently null to indicate that no
  145. // object is associated or defined.
  146. v = null;
  147. }
  148. #end
  149. #if ($addSaveMethod)
  150. #if ($col.isPrimitive())
  151. if (this.$clo != v)
  152. #else
  153. if (!ObjectUtils.equals(this.$clo, v))
  154. #end
  155. {
  156. this.$clo = v;
  157. setModified(true);
  158. }
  159. #else
  160. this.$clo = v;
  161. #end
  162. #if ($complexObjectModel)
  163. #if ($col.isForeignKey())
  164. #set ( $tblFK = $table.Database.getTable($col.RelatedTableName) )
  165. #set ( $colFK = $tblFK.getColumn($col.RelatedColumnName) )
  166. #if ($col.isMultipleFK() || $col.RelatedTableName.equals($table.Name))
  167. #set ( $relCol = "" )
  168. #foreach ($columnName in $col.foreignKey.LocalColumns)
  169. #set ( $column = $table.getColumn($columnName) )
  170. #set ( $relCol = "$relCol$column.JavaName" )
  171. #end
  172. #if ($relCol != "")
  173. #set ( $relCol = "RelatedBy$relCol" )
  174. #end
  175. #set ( $varName = "a${tblFK.JavaName}$relCol" )
  176. #else
  177. #set ( $varName = "a$tblFK.JavaName" )
  178. #end
  179. #if($colFK.Primitive)
  180. if ($varName != null && !(${varName}.get${colFK.JavaName}() == v))
  181. #else
  182. if ($varName != null && !ObjectUtils.equals(${varName}.get${colFK.JavaName}(), v))
  183. #end
  184. {
  185. $varName = null;
  186. }
  187. #end
  188. #foreach ($fk in $col.Referrers)
  189. #set ( $fkColName = $fk.ForeignLocalMapping.get($col.Name) )
  190. #set ( $tblFK = $fk.Table )
  191. #if ( !($tblFK.Name.equals($table.Name)) )
  192. #set ( $colFK = $tblFK.getColumn($fkColName) )
  193. #if ($colFK.isMultipleFK())
  194. #set ( $collName = "coll${tblFK.JavaName}sRelatedBy$colFK.JavaName" )
  195. #else
  196. #set ( $collName = "coll${tblFK.JavaName}s" )
  197. #end
  198. // update associated $tblFK.JavaName
  199. if ($collName != null)
  200. {
  201. for (int i = 0; i < ${collName}.size(); i++)
  202. {
  203. ((${tblFK.JavaName}) ${collName}.get(i))
  204. .set${colFK.JavaName}(v);
  205. }
  206. }
  207. #end
  208. #end
  209. #end
  210. }
  211. #end
  212. #end
  213. ##association code
  214. #if ($complexObjectModel)
  215. #set($pVars = []) ## Array of object set method names for later reference.
  216. #set($aVars = []) ## Array of object field names for later reference.
  217. #foreach ($fk in $table.ForeignKeys)
  218. #set ( $tblFK = $table.Database.getTable($fk.ForeignTableName) )
  219. #set ( $className = $tblFK.JavaName )
  220. #set ( $relCol = "" )
  221. #foreach ($columnName in $fk.LocalColumns)
  222. #set ( $column = $table.getColumn($columnName) )
  223. #if ($column.isMultipleFK() || $fk.ForeignTableName.equals($table.Name))
  224. #set ( $relCol = "$relCol$column.JavaName" )
  225. #end
  226. #end
  227. #if ($relCol != "")
  228. #set ( $relCol = "RelatedBy$relCol" )
  229. #end
  230. #set ( $pVarName = "$className$relCol" )
  231. #set ( $varName = "a$pVarName" )
  232. #set ( $retVal = $pVars.add($pVarName) )
  233. #set ( $retVal = $aVars.add($varName) )
  234. private $className $varName;
  235. /**
  236. * Declares an association between this object and a $className object
  237. *
  238. * @param v $className
  239. * @throws TorqueException
  240. */
  241. public void set${pVarName}($className v) throws TorqueException
  242. {
  243. #foreach ($columnName in $fk.LocalColumns)
  244. #set ( $column = $table.getColumn($columnName) )
  245. #set ( $colFKName = $fk.LocalForeignMapping.get($columnName) )
  246. #set ( $colFK = $tblFK.getColumn($colFKName) )
  247. if (v == null)
  248. {
  249. #if($colFK.Primitive)
  250. #set ($coldefval = "0")
  251. #set ($coldefval = $column.DefaultValue)
  252. set${column.JavaName}(($column.JavaNative) $coldefval);
  253. #else
  254. set${column.JavaName}(($column.JavaNative) null);
  255. #end
  256. }
  257. else
  258. {
  259. set${column.JavaName}(v.get${colFK.JavaName}());
  260. }
  261. #end
  262. $varName = v;
  263. }
  264. #set ( $and = "" )
  265. #set ( $comma = "" )
  266. #set ( $conditional = "" )
  267. #set ( $arglist = "" )
  268. #set ( $argsize = 0 )
  269. #foreach ($columnName in $fk.LocalColumns)
  270. #set ( $column = $table.getColumn($columnName) )
  271. #set ( $cjtype = $column.JavaNative )
  272. #set ( $clo=$column.UncapitalisedJavaName )
  273. #if ($cjtype == "short" || $cjtype == "int" || $cjtype == "long" || $cjtype == "byte" || $cjtype == "float" || $cjtype == "double")
  274. #set ( $conditional = "$conditional${and}this.${clo} > 0" )
  275. #else
  276. #set ( $conditional = "$conditional${and}!ObjectUtils.equals(this.${clo}, null)" )
  277. #end
  278. #set ( $arglist = "$arglist${comma}this.$clo" )
  279. #set ( $and = " && " )
  280. #set ( $comma = ", " )
  281. #set ( $argsize = $argsize + 1 )
  282. #end
  283. #set ( $pCollName = "${table.JavaName}s$relCol" )
  284. /**
  285. * Get the associated $className object
  286. *
  287. * @return the associated $className object
  288. * @throws TorqueException
  289. */
  290. public $className get${pVarName}() throws TorqueException
  291. {
  292. if ($varName == null && ($conditional))
  293. {
  294. #if ($tblFK.isAlias())
  295. #if ($argsize > 1)
  296. $varName = ${className}Peer.retrieve${className}ByPK($arglist);
  297. #else
  298. $varName = ${className}Peer.retrieve${className}ByPK(SimpleKey.keyFor($arglist));
  299. #end
  300. #else
  301. #if ($argsize > 1)
  302. $varName = ${className}Peer.retrieveByPK($arglist);
  303. #else
  304. $varName = ${className}Peer.retrieveByPK(SimpleKey.keyFor($arglist));
  305. #end
  306. #end
  307. /* The following can be used instead of the line above to
  308. guarantee the related object contains a reference
  309. to this object, but this level of coupling
  310. may be undesirable in many circumstances.
  311. As it can lead to a db query with many results that may
  312. never be used.
  313. $className obj = ${className}Peer.retrieveByPK($arglist);
  314. obj.add${pCollName}(this);
  315. */
  316. }
  317. return $varName;
  318. }
  319. /**
  320. * Provides convenient way to set a relationship based on a
  321. * ObjectKey. e.g.
  322. * <code>bar.setFooKey(foo.getPrimaryKey())</code>
  323. *
  324. #if ($fk.LocalColumns.size() > 1)
  325. * Note: It is important that the xml schema used to create this class
  326. * maintains consistency in the order of related columns between
  327. * $table.Name and ${tblFK.Name}.
  328. * If for some reason this is impossible, this method should be
  329. * overridden in <code>$table.JavaName</code>.
  330. #end
  331. */
  332. public void set${pVarName}Key(ObjectKey key) throws TorqueException
  333. {
  334. #if ($fk.LocalColumns.size() > 1)
  335. SimpleKey[] keys = (SimpleKey[]) key.getValue();
  336. #set ($i = 0)
  337. #foreach ($colName in $fk.LocalColumns)
  338. #set ($col = $table.getColumn($colName) )
  339. #set ($fktype = $col.JavaNative)
  340. #if ($fktype == "short")
  341. set${col.JavaName}(((NumberKey) keys[$i]).shortValue());
  342. #elseif($fktype == "int")
  343. set${col.JavaName}(((NumberKey) keys[$i]).intValue());
  344. #elseif($fktype == "long")
  345. set${col.JavaName}(((NumberKey) keys[$i]).longValue());
  346. #elseif($fktype == "BigDecimal")
  347. set${col.JavaName}(((NumberKey) keys[$i]).getBigDecimal());
  348. #elseif($fktype == "byte") )
  349. set${col.JavaName}(((NumberKey) keys[$i]).byteValue());
  350. #elseif($fktype == "float")
  351. set${col.JavaName}(((NumberKey) keys[$i]).floatValue());
  352. #elseif($fktype == "double")
  353. set${col.JavaName}(((NumberKey) keys[$i]).doubleValue());
  354. #elseif($fktype == "Short")
  355. set${col.JavaName}(new Short(((NumberKey) keys[$i]).shortValue()));
  356. #elseif($fktype == "Integer")
  357. set${col.JavaName}(new Integer(((NumberKey) keys[$i]).intValue()));
  358. #elseif($fktype == "Long")
  359. set${col.JavaName}(new Long(((NumberKey) keys[$i]).longValue()));
  360. #elseif($fktype == "Byte") )
  361. set${col.JavaName}(new Byte(((NumberKey) keys[$i]).byteValue()));
  362. #elseif($fktype == "Float")
  363. set${col.JavaName}(new Float(((NumberKey) keys[$i]).floatValue()));
  364. #elseif($fktype == "Double")
  365. set${col.JavaName}(new Double(((NumberKey) keys[$i]).doubleValue()));
  366. #elseif($fktype == "String")
  367. set${col.JavaName}(keys[$i].toString());
  368. #elseif($fktype == "Date")
  369. set${col.JavaName}(((DateKey)keys[$i]).getDate());
  370. #end
  371. #set ( $i = $i + 1 )
  372. #end
  373. #else
  374. #set ($colName = $fk.LocalColumns.get(0))
  375. #set ($col = $table.getColumn($colName) )
  376. #set ($fktype = $col.JavaNative)
  377. #if ($fktype == "short")
  378. set${col.JavaName}(((NumberKey) key).shortValue());
  379. #elseif($fktype == "int")
  380. set${col.JavaName}(((NumberKey) key).intValue());
  381. #elseif($fktype == "long")
  382. set${col.JavaName}(((NumberKey) key).longValue());
  383. #elseif($fktype == "BigDecimal")
  384. set${col.JavaName}(((NumberKey) key).getBigDecimal());
  385. #elseif($fktype == "byte") )
  386. set${col.JavaName}(((NumberKey) key).byteValue());
  387. #elseif($fktype == "float")
  388. set${col.JavaName}(((NumberKey) key).floatValue());
  389. #elseif($fktype == "double")
  390. set${col.JavaName}(((NumberKey) key).doubleValue());
  391. #elseif($fktype == "Short")
  392. set${col.JavaName}(new Short(((NumberKey) key).shortValue()));
  393. #elseif($fktype == "Integer")
  394. set${col.JavaName}(new Integer(((NumberKey) key).intValue()));
  395. #elseif($fktype == "Long")
  396. set${col.JavaName}(new Long(((NumberKey) key).longValue()));
  397. #elseif($fktype == "Byte") )
  398. set${col.JavaName}(new Byte(((NumberKey) key).byteValue()));
  399. #elseif($fktype == "Float")
  400. set${col.JavaName}(new Float(((NumberKey) key).floatValue()));
  401. #elseif($fktype == "Double")
  402. set${col.JavaName}(new Double(((NumberKey) key).doubleValue()));
  403. #elseif($fktype == "String")
  404. set${col.JavaName}(key.toString());
  405. #elseif($fktype == "Date")
  406. set${col.JavaName}(((DateKey)key).getDate());
  407. #end
  408. #end
  409. }
  410. #end ## end of foreach loop over foreign keys
  411. ##
  412. ## setup foreign key associations
  413. ##
  414. #foreach ($fk in $table.Referrers)
  415. #set ( $tblFK = $fk.Table )
  416. #if ( !($tblFK.Name.equals($table.Name)) )
  417. #set ( $className = $tblFK.JavaName )
  418. #set ( $relatedByCol = "" )
  419. #foreach ($columnName in $fk.LocalColumns)
  420. #set ( $column = $tblFK.getColumn($columnName) )
  421. #if ($column.isMultipleFK())
  422. #set ($relatedByCol= "$relatedByCol$column.JavaName")
  423. #end
  424. #end
  425. #if ($relatedByCol == "")
  426. #set ( $suffix = "" )
  427. #set ( $relCol = "${className}s" )
  428. #set ( $relColMs = $className )
  429. #else
  430. #set ( $suffix = "RelatedBy$relatedByCol" )
  431. #set ( $relCol= "${className}sRelatedBy$relatedByCol" )
  432. #set ( $relColMs= "${className}RelatedBy$relatedByCol" )
  433. #end
  434. #set ( $collName = "coll$relCol" )
  435. /**
  436. * Collection to store aggregation of $collName
  437. */
  438. protected List $collName;
  439. /**
  440. * Temporary storage of $collName to save a possible db hit in
  441. * the event objects are add to the collection, but the
  442. * complete collection is never requested.
  443. */
  444. protected void init${relCol}()
  445. {
  446. if ($collName == null)
  447. {
  448. $collName = new ArrayList();
  449. }
  450. }
  451. /**
  452. * Method called to associate a $tblFK.JavaName object to this object
  453. * through the $className foreign key attribute
  454. *
  455. * @param l $className
  456. * @throws TorqueException
  457. */
  458. public void add${relColMs}($className l) throws TorqueException
  459. {
  460. get${relCol}().add(l);
  461. l.set${table.JavaName}${suffix}(($table.JavaName) this);
  462. }
  463. /**
  464. * The criteria used to select the current contents of $collName
  465. */
  466. private Criteria last${relCol}Criteria = null;
  467. /**
  468. * If this collection has already been initialized, returns
  469. * the collection. Otherwise returns the results of
  470. * get${relCol}(new Criteria())
  471. *
  472. * @throws TorqueException
  473. */
  474. public List get${relCol}() throws TorqueException
  475. {
  476. if ($collName == null)
  477. {
  478. $collName = get${relCol}(new Criteria(10));
  479. }
  480. return $collName;
  481. }
  482. /**
  483. * If this collection has already been initialized with
  484. * an identical criteria, it returns the collection.
  485. * Otherwise if this $table.JavaName has previously
  486. * been saved, it will retrieve related ${relCol} from storage.
  487. * If this $table.JavaName is new, it will return
  488. * an empty collection or the current collection, the criteria
  489. * is ignored on a new object.
  490. *
  491. * @throws TorqueException
  492. */
  493. public List get${relCol}(Criteria criteria) throws TorqueException
  494. {
  495. if ($collName == null)
  496. {
  497. if (isNew())
  498. {
  499. $collName = new ArrayList();
  500. }
  501. else
  502. {
  503. #foreach ($columnName in $fk.ForeignColumns)
  504. #set ( $column = $table.getColumn($columnName) )
  505. #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
  506. #set ( $colFK = $tblFK.getColumn($colFKName) )
  507. criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() );
  508. #end
  509. $collName = ${className}Peer.doSelect(criteria);
  510. }
  511. }
  512. else
  513. {
  514. // criteria has no effect for a new object
  515. if (!isNew())
  516. {
  517. // the following code is to determine if a new query is
  518. // called for. If the criteria is the same as the last
  519. // one, just return the collection.
  520. #foreach ($columnName in $fk.ForeignColumns)
  521. #set ( $column = $table.getColumn($columnName) )
  522. #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
  523. #set ( $colFK = $tblFK.getColumn($colFKName) )
  524. criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}());
  525. #end
  526. if (!last${relCol}Criteria.equals(criteria))
  527. {
  528. $collName = ${className}Peer.doSelect(criteria);
  529. }
  530. }
  531. }
  532. last${relCol}Criteria = criteria;
  533. return $collName;
  534. }
  535. /**
  536. * If this collection has already been initialized, returns
  537. * the collection. Otherwise returns the results of
  538. * get${relCol}(new Criteria(),Connection)
  539. * This method takes in the Connection also as input so that
  540. * referenced objects can also be obtained using a Connection
  541. * that is taken as input
  542. */
  543. public List get${relCol}(Connection con) throws TorqueException
  544. {
  545. if ($collName == null)
  546. {
  547. $collName = get${relCol}(new Criteria(10), con);
  548. }
  549. return $collName;
  550. }
  551. /**
  552. * If this collection has already been initialized with
  553. * an identical criteria, it returns the collection.
  554. * Otherwise if this $table.JavaName has previously
  555. * been saved, it will retrieve related ${relCol} from storage.
  556. * If this $table.JavaName is new, it will return
  557. * an empty collection or the current collection, the criteria
  558. * is ignored on a new object.
  559. * This method takes in the Connection also as input so that
  560. * referenced objects can also be obtained using a Connection
  561. * that is taken as input
  562. */
  563. public List get${relCol}(Criteria criteria, Connection con)
  564. throws TorqueException
  565. {
  566. if ($collName == null)
  567. {
  568. if (isNew())
  569. {
  570. $collName = new ArrayList();
  571. }
  572. else
  573. {
  574. #foreach ($columnName in $fk.ForeignColumns)
  575. #set ( $column = $table.getColumn($columnName) )
  576. #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
  577. #set ( $colFK = $tblFK.getColumn($colFKName) )
  578. criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}());
  579. #end
  580. $collName = ${className}Peer.doSelect(criteria, con);
  581. }
  582. }
  583. else
  584. {
  585. // criteria has no effect for a new object
  586. if (!isNew())
  587. {
  588. // the following code is to determine if a new query is
  589. // called for. If the criteria is the same as the last
  590. // one, just return the collection.
  591. #foreach ($columnName in $fk.ForeignColumns)
  592. #set ( $column = $table.getColumn($columnName) )
  593. #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
  594. #set ( $colFK = $tblFK.getColumn($colFKName) )
  595. criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}());
  596. #end
  597. if (!last${relCol}Criteria.equals(criteria))
  598. {
  599. $collName = ${className}Peer.doSelect(criteria, con);
  600. }
  601. }
  602. }
  603. last${relCol}Criteria = criteria;
  604. return $collName;
  605. }
  606. #set ( $countFK = 0 )
  607. #foreach ($dummyFK in $tblFK.ForeignKeys)
  608. #set ( $countFK = $countFK + 1 )
  609. #end
  610. ## ------------------------------------------------------------
  611. ##
  612. #if ($countFK >= 1)
  613. #set ( $lastTable = "" )
  614. #foreach ($fk2 in $tblFK.ForeignKeys)
  615. ## Add join methods if the fk2 table is not this table or
  616. ## the fk2 table references this table multiple times.
  617. #set ( $doJoinGet = true )
  618. #if ( $fk2.ForeignTableName.equals($table.Name) )
  619. #set ( $doJoinGet = false )
  620. #end
  621. #foreach ($columnName in $fk2.LocalColumns)
  622. #set ( $column = $tblFK.getColumn($columnName) )
  623. #if ($column.isMultipleFK())
  624. #set ( $doJoinGet = true )
  625. #end
  626. #end
  627. #set ( $tblFK2 = $table.Database.getTable($fk2.ForeignTableName) )
  628. #if ($tblFK2.isForReferenceOnly())
  629. #set ($doJoinGet = false)
  630. #else
  631. #set ($doJoinGet = true)
  632. #end
  633. #set ( $relatedByCol2 = "" )
  634. #foreach ($columnName in $fk2.LocalColumns)
  635. #set ( $column = $tblFK.getColumn($columnName) )
  636. #if ($column.isMultipleFK())
  637. #set($relatedByCol2 = "$relatedByCol2$column.JavaName")
  638. #end
  639. #end
  640. #set ( $fkClassName = $tblFK2.JavaName )
  641. ## do not generate code for self-referencing fk's, it would be
  642. ## good to do, but it is just not implemented yet.
  643. #if ($className == $fkClassName)
  644. #set ( $doJoinGet = false )
  645. #end
  646. #if ($relatedByCol2 == "")
  647. #set ( $relCol2 = $fkClassName )
  648. #else
  649. #set ($relCol2 = "${fkClassName}RelatedBy$relatedByCol2")
  650. #end
  651. #if ( $relatedByCol == "")
  652. #else
  653. #if ( $relatedByCol.equals($relatedByCol2) )
  654. #set ( $doJoinGet = false )
  655. #end
  656. #end
  657. #if ($doJoinGet)
  658. /**
  659. * If this collection has already been initialized with
  660. * an identical criteria, it returns the collection.
  661. * Otherwise if this $table.JavaName is new, it will return
  662. * an empty collection; or if this $table.JavaName has previously
  663. * been saved, it will retrieve related ${relCol} from storage.
  664. *
  665. * This method is protected by default in order to keep the public
  666. * api reasonable. You can provide public methods for those you
  667. * actually need in ${table.JavaName}.
  668. */
  669. protected List get${relCol}Join${relCol2}(Criteria criteria)
  670. throws TorqueException
  671. {
  672. if ($collName == null)
  673. {
  674. if (isNew())
  675. {
  676. $collName = new ArrayList();
  677. }
  678. else
  679. {
  680. #foreach ($columnName in $fk.ForeignColumns)
  681. #set ( $column = $table.getColumn($columnName) )
  682. #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
  683. #set ( $colFK = $tblFK.getColumn($colFKName) )
  684. criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}());
  685. #end
  686. $collName = ${className}Peer.doSelectJoin${relCol2}(criteria);
  687. }
  688. }
  689. else
  690. {
  691. // the following code is to determine if a new query is
  692. // called for. If the criteria is the same as the last
  693. // one, just return the collection.
  694. boolean newCriteria = true;
  695. #foreach ($columnName in $fk.ForeignColumns)
  696. #set ( $column = $table.getColumn($columnName) )
  697. #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
  698. #set ( $colFK = $tblFK.getColumn($colFKName) )
  699. criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}());
  700. #end
  701. if (!last${relCol}Criteria.equals(criteria))
  702. {
  703. $collName = ${className}Peer.doSelectJoin${relCol2}(criteria);
  704. }
  705. }
  706. last${relCol}Criteria = criteria;
  707. return $collName;
  708. }
  709. #end
  710. #end
  711. #end
  712. #end
  713. ## ===========================================================
  714. #*
  715. #if ($countFK > 2)
  716. /**
  717. * If this collection has already been initialized with
  718. * an identical criteria, it returns the collection.
  719. * Otherwise if this $table.JavaName is new, it will return
  720. * an empty collection; or if this $table.JavaName has previously
  721. * been saved, it will retrieve related ${relCol} from storage.
  722. *
  723. * This method is protected by default in order to keep the public
  724. * api reasonable. You can provide public methods for those you
  725. * actually need in ${table.JavaName}.
  726. */
  727. protected List get${relCol}JoinAllExcept${table.JavaName}(Criteria criteria)
  728. throws TorqueException
  729. {
  730. if ($collName == null)
  731. {
  732. if (isNew())
  733. {
  734. $collName = new ArrayList();
  735. }
  736. else
  737. {
  738. #foreach ($columnName in $fk.ForeignColumns)
  739. #set ( $column = $table.getColumn($columnName) )
  740. #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
  741. #set ( $colFK = $tblFK.getColumn($colFKName) )
  742. criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}());
  743. #end
  744. $collName = ${className}Peer.doSelectJoinAllExcept${table.JavaName}${suffix}(criteria);
  745. }
  746. }
  747. else
  748. {
  749. // the following code is to determine if a new query is
  750. // called for. If the criteria is the same as the last
  751. // one, just return the collection.
  752. boolean newCriteria = true;
  753. #foreach ($columnName in $fk.ForeignColumns)
  754. #set ( $column = $table.getColumn($columnName) )
  755. #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
  756. #set ( $colFK = $tblFK.getColumn($colFKName) )
  757. criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}());
  758. #end
  759. if (!last${relCol}Criteria.equals(criteria))
  760. {
  761. $collName = ${className}Peer.doSelectJoinAllExcept${table.JavaName}${suffix}(criteria);
  762. }
  763. }
  764. last${relCol}Criteria = criteria;
  765. return $collName;
  766. }
  767. #end
  768. *#
  769. ## ------------------------------------------------------------
  770. #end ## ends foreach over table.Referrers
  771. #end ##ends the if(complexObjectModel)
  772. ##
  773. ## getByName code
  774. ##
  775. #if (!$table.isAlias() && $addGetByNameMethod)
  776. private static List fieldNames = null;
  777. /**
  778. * Generate a list of field names.
  779. *
  780. * @return a list of field names
  781. */
  782. public static synchronized List getFieldNames()
  783. {
  784. if (fieldNames == null)
  785. {
  786. fieldNames = new ArrayList();
  787. #foreach ($col in $table.Columns)
  788. fieldNames.add("${col.JavaName}");
  789. #end
  790. fieldNames = Collections.unmodifiableList(fieldNames);
  791. }
  792. return fieldNames;
  793. }
  794. /**
  795. * Retrieves a field from the object by name passed in as a String.
  796. *
  797. * @param name field name
  798. * @return value
  799. */
  800. public Object getByName(String name)
  801. {
  802. #foreach ($col in $table.Columns)
  803. #set ( $cfc = $col.JavaName )
  804. #set ( $cjtype = $col.JavaNative )
  805. if (name.equals("${col.JavaName}"))
  806. {
  807. #if ($cjtype == "int")
  808. return new Integer(get${cfc}());
  809. #elseif ($cjtype == "long")
  810. return new Long(get${cfc}());
  811. #elseif ($cjtype == "float")
  812. return new Float(get${cfc}());
  813. #elseif ($cjtype == "double")
  814. return new Double(get${cfc}());
  815. #elseif ($cjtype == "boolean")
  816. return new Boolean(get${cfc}());
  817. #elseif ($cjtype == "short")
  818. return new Short(get${cfc}());
  819. #elseif ($cjtype == "byte")
  820. return new Byte(get${cfc}());
  821. #elseif ($cjtype == "char")
  822. return new Character(get${cfc}());
  823. #else
  824. return get${cfc}();
  825. #end
  826. }
  827. #end
  828. return null;
  829. }
  830. /**
  831. * Retrieves a field from the object by name passed in
  832. * as a String. The String must be one of the static
  833. * Strings defined in this Class' Peer.
  834. *
  835. * @param name peer name
  836. * @return value
  837. */
  838. public Object getByPeerName(String name)
  839. {
  840. #foreach ($col in $table.Columns)
  841. #set ( $cfc = $col.JavaName )
  842. #set ( $cup=$col.Name.toUpperCase() )
  843. #set ( $cjtype = $col.JavaNative )
  844. if (name.equals(${table.JavaName}Peer.$cup))
  845. {
  846. #if ($cjtype == "int")
  847. return new Integer(get${cfc}());
  848. #elseif ($cjtype == "long")
  849. return new Long(get${cfc}());
  850. #elseif ($cjtype == "float")
  851. return new Float(get${cfc}());
  852. #elseif ($cjtype == "double")
  853. return new Double(get${cfc}());
  854. #elseif ($cjtype == "boolean")
  855. return new Boolean(get${cfc}());
  856. #elseif ($cjtype == "short")
  857. return new Short(get${cfc}());
  858. #elseif ($cjtype == "byte")
  859. return new Byte(get${cfc}());
  860. #elseif ($cjtype == "char")
  861. return new Character(get${cfc}());
  862. #else
  863. return get${cfc}();
  864. #end
  865. }
  866. #end
  867. return null;
  868. }
  869. /**
  870. * Retrieves a field from the object by Position as specified
  871. * in the xml schema. Zero-based.
  872. *
  873. * @param pos position in xml schema
  874. * @return value
  875. */
  876. public Object getByPosition(int pos)
  877. {
  878. #set ($i = 0)
  879. #foreach ($col in $table.Columns)
  880. #set ( $cfc = $col.JavaName )
  881. #set ( $cjtype = $col.JavaNative )
  882. if (pos == $i)
  883. {
  884. #if ($cjtype == "int")
  885. return new Integer(get${cfc}());
  886. #elseif ($cjtype == "long")
  887. return new Long(get${cfc}());
  888. #elseif ($cjtype == "float")
  889. return new Float(get${cfc}());
  890. #elseif ($cjtype == "double")
  891. return new Double(get${cfc}());
  892. #elseif ($cjtype == "boolean")
  893. return new Boolean(get${cfc}());
  894. #elseif ($cjtype == "short")
  895. return new Short(get${cfc}());
  896. #elseif ($cjtype == "byte")
  897. return new Byte(get${cfc}());
  898. #elseif ($cjtype == "char")
  899. return new Character(get${cfc}());
  900. #else
  901. return get${cfc}();
  902. #end
  903. }
  904. #set ($i = $i + 1)
  905. #end
  906. return null;
  907. }
  908. #end ## ends the if(addGetByNameMethod)
  909. #if (!$table.isAlias() && $addSaveMethod)
  910. /**
  911. * Stores the object in the database. If the object is new,
  912. * it inserts it; otherwise an update is performed.
  913. *
  914. * @throws $saveException
  915. */
  916. public void save() throws $saveException
  917. {
  918. #if ($complexObjectModel)
  919. save(${table.JavaName}Peer.getMapBuilder()
  920. .getDatabaseMap().getName());
  921. #else
  922. if (isModified())
  923. {
  924. if (isNew())
  925. {
  926. ${table.JavaName}Peer.doInsert(($table.JavaName) this);
  927. setNew(false);
  928. }
  929. else
  930. {
  931. ${table.JavaName}Peer.doUpdate(($table.JavaName) this);
  932. }
  933. }
  934. #end
  935. }
  936. /**
  937. * Stores the object in the database. If the object is new,
  938. * it inserts it; otherwise an update is performed.
  939. #if ($complexObjectModel)
  940. * Note: this code is here because the method body is
  941. * auto-generated conditionally and therefore needs to be
  942. * in this file instead of in the super class, BaseObject.
  943. #end
  944. *
  945. * @param dbName
  946. * @throws TorqueException
  947. */
  948. public void save(String dbName) throws TorqueException
  949. {
  950. Connection con = null;
  951. #if ($complexObjectModel)
  952. try
  953. {
  954. con = Transaction.begin(dbName);
  955. save(con);
  956. Transaction.commit(con);
  957. }
  958. catch(TorqueException e)
  959. {
  960. Transaction.safeRollback(con);
  961. throw e;
  962. }
  963. #else
  964. if (isModified())
  965. {
  966. try
  967. {
  968. con = Torque.getConnection(dbName);
  969. if (isNew())
  970. {
  971. ${table.JavaName}Peer
  972. .doInsert(($table.JavaName) this, con);
  973. setNew(false);
  974. }
  975. else
  976. {
  977. ${table.JavaName}Peer
  978. .doUpdate(($table.JavaName) this, con);
  979. }
  980. }
  981. finally
  982. {
  983. Torque.closeConnection(con);
  984. }
  985. }
  986. #end
  987. }
  988. #if ($complexObjectModel)
  989. /** flag to prevent endless save loop, if this object is referenced
  990. by another object which falls in this transaction. */
  991. private boolean alreadyInSave = false;
  992. #end
  993. /**
  994. * Stores the object in the database. If the object is new,
  995. * it inserts it; otherwise an update is performed. This method
  996. * is meant to be used as part of a transaction, otherwise use
  997. * the save() method and the connection details will be handled
  998. * internally
  999. *
  1000. * @param con
  1001. * @throws TorqueException
  1002. */
  1003. public void save(Connection con) throws TorqueException
  1004. {
  1005. #if ($complexObjectModel)
  1006. if (!alreadyInSave)
  1007. {
  1008. alreadyInSave = true;
  1009. #* FIXME! the following code can cause an infinite loop, needs more thought
  1010. shows the infinite loop: System.out.println("Entering save for " + this);
  1011. #if ($pVars.size() != 0)
  1012. // We call the save method on the following object(s) if they
  1013. // were passed to this object by their coresponding set
  1014. // method. This object relates to these object(s) by a
  1015. // foreign key reference. If the object(s) being saved were
  1016. // new to the database, an insert was performed, then they may
  1017. // have a new PrimaryKey. We call the coresponding set method
  1018. // for the given object(s) to set this object's Id reference
  1019. // to this new Primary key so that it will be saved.
  1020. #foreach ($aVarName in $aVars)
  1021. #set($i = $velocityCount - 1)
  1022. if ($aVarName != null)
  1023. {
  1024. ${aVarName}.save(con);
  1025. set$pVars.get($i)($aVarName);
  1026. }
  1027. #end
  1028. #end
  1029. *#
  1030. #end
  1031. // If this object has been modified, then save it to the database.
  1032. if (isModified())
  1033. {
  1034. if (isNew())
  1035. {
  1036. ${table.JavaName}Peer.doInsert(($table.JavaName) this, con);
  1037. setNew(false);
  1038. }
  1039. else
  1040. {
  1041. ${table.JavaName}Peer.doUpdate(($table.JavaName) this, con);
  1042. }
  1043. }
  1044. #if ($complexObjectModel)
  1045. #foreach ($fk in $table.Referrers)
  1046. #set ( $tblFK = $fk.Table )
  1047. #if ( !($tblFK.Name.equals($table.Name)) )
  1048. #set ( $className = $tblFK.JavaName )
  1049. #set ( $relCol = "" )
  1050. #foreach ($columnName in $fk.LocalColumns)
  1051. #set ( $column = $tblFK.getColumn($columnName) )
  1052. #if ($column.isMultipleFK())
  1053. #set ( $relCol = "$relCol$column.JavaName" )
  1054. #end
  1055. #end
  1056. #if ($relCol == "")
  1057. #set ( $relCol = "${className}s" )
  1058. #else
  1059. #set ( $relCol = "${className}sRelatedBy$relCol" )
  1060. #end
  1061. #set ( $collName = "coll$relCol" )
  1062. if ($collName != null)
  1063. {
  1064. for (int i = 0; i < ${collName}.size(); i++)
  1065. {
  1066. ((${className}) ${collName}.get(i)).save(con);
  1067. }
  1068. }
  1069. #end
  1070. #end
  1071. #end
  1072. #if ($complexObjectModel)
  1073. alreadyInSave = false;
  1074. }
  1075. #end
  1076. }
  1077. #end
  1078. ## PrimaryKey methods
  1079. #if (!$table.isAlias())
  1080. #set ( $throwsClause = "" )
  1081. #set ( $argList = "" )
  1082. #set ( $argList2 = "" )
  1083. #set ( $comma = "" )
  1084. #foreach ($col in $table.PrimaryKey)
  1085. #if ($complexObjectModel)
  1086. #if ( $col.isForeignKey() || ($col.Referrers.size() > 0) )
  1087. #set ( $throwsClause = "throws TorqueException" )
  1088. #end
  1089. #end
  1090. #set ( $clo=$col.UncapitalisedJavaName )
  1091. #set ( $cjtype = $col.JavaNative )
  1092. #set ($argList = "${argList}$comma $cjtype $clo")
  1093. #set ($argList2 = "${argList2}$comma String $clo")
  1094. #set ( $comma = "," )
  1095. #end
  1096. #if ($table.PrimaryKey.size() == 1)
  1097. #set ($col = $table.PrimaryKey.get(0) )
  1098. #set ( $clo=$col.UncapitalisedJavaName )
  1099. #set ( $cjtype= $col.JavaNative )
  1100. /**
  1101. * Set the PrimaryKey using ObjectKey.
  1102. *
  1103. * @param $clo ObjectKey
  1104. */
  1105. public void setPrimaryKey(ObjectKey key)
  1106. $throwsClause
  1107. {
  1108. #if ($cjtype == "short")
  1109. set${col.JavaName}(((NumberKey) key).shortValue());
  1110. #elseif($cjtype == "int")
  1111. set${col.JavaName}(((NumberKey) key).intValue());
  1112. #elseif($cjtype == "long")
  1113. set${col.JavaName}(((NumberKey) key).longValue());
  1114. #elseif($cjtype == "BigDecimal")
  1115. set${col.JavaName}(((NumberKey) key).getBigDecimal());
  1116. #elseif($cjtype == "byte") )
  1117. set${col.JavaName}(((NumberKey) key).byteValue());
  1118. #elseif($cjtype == "float")
  1119. set${col.JavaName}(((NumberKey) key).floatValue());
  1120. #elseif($cjtype == "double")
  1121. set${col.JavaName}(((NumberKey) key).doubleValue());
  1122. #elseif($cjtype == "Short")
  1123. set${col.JavaName}(new Short(((NumberKey) key).shortValue()));
  1124. #elseif($cjtype == "Integer")
  1125. set${col.JavaName}(new Integer(((NumberKey) key).intValue()));
  1126. #elseif($cjtype == "Long")
  1127. set${col.JavaName}(new Long(((NumberKey) key).longValue()));
  1128. #elseif($cjtype == "Byte") )
  1129. set${col.JavaName}(new Byte(((NumberKey) key).byteValue()));
  1130. #elseif($cjtype == "Float")
  1131. set${col.JavaName}(new Float(((NumberKey) key).floatValue()));
  1132. #elseif($cjtype == "Double")
  1133. set${col.JavaName}(new Double(((NumberKey) key).doubleValue()));
  1134. #elseif($cjtype == "String")
  1135. set${col.JavaName}(key.toString());
  1136. #elseif($cjtype == "Date")
  1137. set${col.JavaName}(((DateKey)key).getDate());
  1138. #else
  1139. set${col.JavaName}(($cjtype)key);
  1140. #end
  1141. }
  1142. /**
  1143. * Set the PrimaryKey using a String.
  1144. *
  1145. * @param key
  1146. */
  1147. public void setPrimaryKey(String key) $throwsClause
  1148. {
  1149. #if ($cjtype == "short")
  1150. set${col.JavaName}(Short.parseShort(key));
  1151. #elseif($cjtype == "int")
  1152. set${col.JavaName}(Integer.parseInt(key));
  1153. #elseif($cjtype == "long")
  1154. set${col.JavaName}(Long.parseLong(key));
  1155. #elseif($cjtype == "BigDecimal")
  1156. set${col.JavaName}(new BigDecimal(key));
  1157. #elseif($cjtype == "byte") )
  1158. set${col.JavaName}(Byte.parseByte(key));
  1159. #elseif($cjtype == "float")
  1160. set${col.JavaName}(Float.parseFloat(key));
  1161. #elseif($cjtype == "double")
  1162. set${col.JavaName}(Double.parseDouble(key));
  1163. #elseif($cjtype == "Short")
  1164. set${col.JavaName}(new Short(key));
  1165. #elseif($cjtype == "Integer")
  1166. set${col.JavaName}(new Integer(key));
  1167. #elseif($cjtype == "Long")
  1168. set${col.JavaName}(new Long(key));
  1169. #elseif($cjtype == "Byte") )
  1170. set${col.JavaName}(new Byte(key));
  1171. #elseif($cjtype == "Float")
  1172. set${col.JavaName}(new Float(key));
  1173. #elseif($cjtype == "Double")
  1174. set${col.JavaName}(new Double(key));
  1175. #elseif($cjtype == "String")
  1176. set${col.JavaName}(key);
  1177. #elseif($cjtype == "Date")
  1178. set${col.JavaName}(new Date(key));
  1179. #else
  1180. set${col.JavaName}(new ${cjtype}(key));
  1181. #end
  1182. }
  1183. #elseif ($table.PrimaryKey.size() > 1)
  1184. private final SimpleKey[] pks = new SimpleKey[$table.PrimaryKey.size()];
  1185. private final ComboKey comboPK = new ComboKey(pks);
  1186. /**
  1187. * Set the PrimaryKey with an ObjectKey
  1188. *
  1189. * @param key
  1190. */
  1191. public void setPrimaryKey(ObjectKey key) throws TorqueException
  1192. {
  1193. SimpleKey[] keys = (SimpleKey[]) key.getValue();
  1194. SimpleKey tmpKey = null;
  1195. #set ($i = 0)
  1196. #foreach ($pk in $table.PrimaryKey)
  1197. #set ($pktype = $pk.JavaNative)
  1198. #if ($pktype == "short")
  1199. set${pk.JavaName}(((NumberKey)keys[$i]).shortValue());
  1200. #elseif($pktype == "int")
  1201. set${pk.JavaName}(((NumberKey)keys[$i]).intValue());
  1202. #elseif($pktype == "long")
  1203. set${pk.JavaName}(((NumberKey)keys[$i]).longValue());
  1204. #elseif($pktype == "BigDecimal")
  1205. set${pk.JavaName}(((NumberKey)keys[$i]).getBigDecimal());
  1206. #elseif($pktype == "byte") )
  1207. set${pk.JavaName}(((NumberKey)keys[$i]).byteValue());
  1208. #elseif($pktype == "float")
  1209. set${pk.JavaName}(((NumberKey)keys[$i]).floatValue());
  1210. #elseif($pktype == "double")
  1211. set${pk.JavaName}(((NumberKey)keys[$i]).doubleValue());
  1212. #elseif($pktype == "Short")
  1213. set${pk.JavaName}(new Short(((NumberKey)keys[$i]).shortValue()));
  1214. #elseif($pktype == "Integer")
  1215. set${pk.JavaName}(new Integer(((NumberKey)keys[$i]).intValue()));
  1216. #elseif($pktype == "Long")
  1217. set${pk.JavaName}(new Long(((NumberKey)keys[$i]).longValue()));
  1218. #elseif($pktype == "Byte") )
  1219. set${pk.JavaName}(new Byte(((NumberKey)keys[$i]).byteValue()));
  1220. #elseif($pktype == "Float")
  1221. set${pk.JavaName}(new Float(((NumberKey)keys[$i]).floatValue()));
  1222. #elseif($pktype == "Double")
  1223. set${pk.JavaName}(new Double(((NumberKey)keys[$i]).doubleValue()));
  1224. #elseif($pktype == "String")
  1225. set${pk.JavaName}(keys[$i].toString());
  1226. #elseif($pktype == "Date")
  1227. set${pk.JavaName}(((DateKey)keys[$i]).getDate());
  1228. #end
  1229. #set ( $i = $i + 1 )
  1230. #end
  1231. }
  1232. /**
  1233. * Set the PrimaryKey using SimpleKeys.
  1234. *
  1235. #foreach ($col in $table.PrimaryKey)
  1236. #set ( $clo=$col.UncapitalisedJavaName )
  1237. #set ( $cjtype= $col.JavaNative )
  1238. * @param $cjtype $clo
  1239. #end
  1240. */
  1241. public void setPrimaryKey($argList)
  1242. $throwsClause
  1243. {
  1244. #foreach ($col in $table.PrimaryKey)
  1245. set${col.JavaName}($col.UncapitalisedJavaName);
  1246. #end
  1247. }
  1248. /**
  1249. * Set the PrimaryKey using a String.
  1250. */
  1251. public void setPrimaryKey(String key) throws TorqueException
  1252. {
  1253. setPrimaryKey(new ComboKey(key));
  1254. }
  1255. #end
  1256. /**
  1257. * returns an id that differentiates this object from others
  1258. * of its class.
  1259. */
  1260. public ObjectKey getPrimaryKey()
  1261. {
  1262. #if ($table.PrimaryKey.size() == 1)
  1263. return SimpleKey.keyFor(get${table.PrimaryKey.get(0).JavaName}());
  1264. #elseif ($table.PrimaryKey.size() > 1)
  1265. #set ($i = 0)
  1266. #foreach ($pk in $table.PrimaryKey)
  1267. pks[$i] = SimpleKey.keyFor(get${pk.JavaName}());
  1268. #set ($i = $i +1)
  1269. #end
  1270. return comboPK;
  1271. #else
  1272. return null;
  1273. #end
  1274. }
  1275. #end ##ends if(!$table.isAlias())
  1276. #if ($addIntakeRetrievable)
  1277. /**
  1278. * get an id that differentiates this object from others
  1279. * of its class.
  1280. */
  1281. public String getQueryKey()
  1282. {
  1283. if (getPrimaryKey() == null)
  1284. {
  1285. return "";
  1286. }
  1287. else
  1288. {
  1289. return getPrimaryKey().toString();
  1290. }
  1291. }
  1292. /**
  1293. * set an id that differentiates this object from others
  1294. * of its class.
  1295. */
  1296. public void setQueryKey(String key)
  1297. throws TorqueException
  1298. {
  1299. setPrimaryKey(key);
  1300. }
  1301. #end
  1302. #if (!$table.isAlias())
  1303. /**
  1304. * Makes a copy of this object.
  1305. * It creates a new object filling in the simple attributes.
  1306. #if ($complexObjectModel)
  1307. * It then fills all the association collections and sets the
  1308. * related objects to isNew=true.
  1309. #end
  1310. */
  1311. #if ($table.isAbstract())
  1312. public abstract $table.JavaName copy() throws TorqueException;
  1313. #else
  1314. public $table.JavaName copy() throws TorqueException
  1315. {
  1316. return copyInto(new ${table.JavaName}());
  1317. }
  1318. #end
  1319. protected $table.JavaName copyInto($table.JavaName copyObj) throws TorqueException
  1320. {
  1321. #foreach ($col in $table.Columns)
  1322. copyObj.set${col.JavaName}($col.UncapitalisedJavaName);
  1323. #end
  1324. #foreach ($col in $table.Columns)
  1325. #if ($col.isPrimaryKey())
  1326. #if($col.Primitive)
  1327. #set ($coldefval = "0")
  1328. #set ($coldefval = $col.DefaultValue)
  1329. copyObj.set${col.JavaName}(($col.JavaNative) $coldefval);
  1330. #else
  1331. #set ( $pkid = "null" )
  1332. #set ( $cjtype = $col.JavaNative )
  1333. copyObj.set${col.JavaName}((${cjtype}) ${pkid});
  1334. #end
  1335. #end
  1336. #end
  1337. #if ($complexObjectModel)
  1338. #set ( $list = "List " )
  1339. #foreach ($fk in $table.Referrers)
  1340. #set ( $tblFK = $fk.Table )
  1341. #if ( !($tblFK.Name.equals($table.Name)) )
  1342. #set ( $className = $tblFK.JavaName )
  1343. #set ( $relCol = "" )
  1344. #foreach ($columnName in $fk.LocalColumns)
  1345. #set ( $column = $tblFK.getColumn($columnName) )
  1346. #if ($column.isMultipleFK())
  1347. #set ( $relCol = "$relCol$column.JavaName" )
  1348. #end
  1349. #end
  1350. #if ($relCol == "")
  1351. #set ( $pCollName = "${className}s" )
  1352. #set ( $pCollNameNoS = "${className}" )
  1353. #else
  1354. #set ( $pCollName = "${className}sRelatedBy$relCol" )
  1355. #set ( $pCollNameNoS = "${className}RelatedBy$relCol" )
  1356. #end
  1357. ${list}v = get${pCollName}();
  1358. for (int i = 0; i < v.size(); i++)
  1359. {
  1360. $className obj = ($className) v.get(i);
  1361. copyObj.add$pCollNameNoS(obj.copy());
  1362. }
  1363. #set ( $list = "" )
  1364. #end
  1365. #end
  1366. #end
  1367. return copyObj;
  1368. }
  1369. #end
  1370. #if (!$table.isAlias())
  1371. /**
  1372. * returns a peer instance associated with this om. Since Peer classes
  1373. * are not to have any instance attributes, this method returns the
  1374. * same instance for all member of this class. The method could therefore
  1375. * be static, but this would prevent one from overriding the behavior.
  1376. */
  1377. public ${table.JavaName}Peer getPeer()
  1378. {
  1379. return peer;
  1380. }
  1381. #end
  1382. public String toString()
  1383. {
  1384. StringBuffer str = new StringBuffer();
  1385. str.append("$table.JavaName:\n");
  1386. #foreach ($col in $table.Columns)
  1387. str.append("$col.JavaName = ")
  1388. .append(get${col.JavaName}())
  1389. .append("\n");
  1390. #end
  1391. return(str.toString());
  1392. }
  1393. /**
  1394. * Default DOM object conversion
  1395. */
  1396. public Element toXmlElement(Document d) {
  1397. return toXmlElement(d, "$table.JavaName");
  1398. }
  1399. /**
  1400. * Convert object to a DOM element
  1401. */
  1402. public Element toXmlElement(Document d, String n) {
  1403. Element e = d.createElement(n);
  1404. #foreach ($col in $table.Columns)
  1405. #set ( $clo=$col.UncapitalisedJavaName )
  1406. #if (!$col.isPrimitive())
  1407. if (${col.UncapitalisedJavaName} != null) {
  1408. #end
  1409. ## #if ($col.TorqueType == "LONGVARCHAR" || $col.TorqueType == "BINARY" || $col.TorqueType == "VARBINARY" || $col.TorqueType == "BLOB" || $col.TorqueType == "CLOB")
  1410. ## Element elem${col.JavaName} = doc.createElement("${col.JavaName}");
  1411. ## elem${col.JavaName}.appendChild(doc.createTextNode($clo));
  1412. ## elem.appendChild(elem${col.JavaName});
  1413. #if ($col.TorqueType == "DATE")
  1414. e.setAttribute("$clo", DateFormatUtils.ISO_DATE_FORMAT.format($clo));
  1415. #elseif ($col.TorqueType == "TIME")
  1416. e.setAttribute("$clo", DateFormatUtils.ISO_TIME_NO_T_FORMAT.format($clo));
  1417. #elseif ($col.TorqueType == "TIMESTAMP")
  1418. e.setAttribute("$clo", DateFormatUtils.ISO_DATETIME_FORMAT.format($clo));
  1419. #else
  1420. e.setAttribute("$clo", String.valueOf($clo));
  1421. #end
  1422. #if (!$col.isPrimitive())
  1423. }
  1424. #end
  1425. #end
  1426. return e;
  1427. }
  1428. /**
  1429. * DOM element deserializer
  1430. */
  1431. public voi

Large files files are truncated, but you can click here to view the full file