PageRenderTime 153ms CodeModel.GetById 2ms app.highlight 140ms RepoModel.GetById 1ms 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

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

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

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