head	1.6;
access;
symbols
	TIGRIS_1_1_0RC2:1.5
	TIGRIS_1_1_0RC1:1.5
	TIGRIS_1_1:1.5.0.4
	TIGRIS_1_0_8:1.5
	TIGRIS_1_0_8RC3:1.5
	TIGRIS_1_0_8RC2:1.5
	TIGRIS_1_0_8RC1:1.5
	TIGRIS_1_0_7:1.5
	TIGRIS_1_0_7RC3:1.5
	TIGRIS_1_0_7RC2:1.5
	TIGRIS_1_0_7RC1:1.5
	TIGRIS_1_0_6:1.5
	TIGRIS_1_0_6RC5:1.5
	TIGRIS_1_0_6RC4:1.5
	TIGRIS_1_0_6RC3:1.5
	TIGRIS_1_0_6RC2:1.5
	TIGRIS_1_0_6RC1:1.5
	TIGRIS_1_0_5:1.5
	TIGRIS_1_0_5RC6:1.5
	TIGRIS_1_0_5RC5:1.5
	TIGRIS_1_0_5RC4:1.5
	TIGRIS_1_0_5RC3:1.5
	TIGRIS_1_0_5RC2:1.5
	TIGRIS_1_0_5RC1:1.5
	TIGRIS_1_0_4:1.5
	TIGRIS_1_0_3:1.5
	TIGRIS_1_0_2:1.5
	TIGRIS_1_0_1:1.5
	TIGRIS_1_0:1.5.0.6
	TIGRIS_1_0_0:1.5
	TIGRIS_1_0_0_RC1:1.5.0.2;
locks; strict;
comment	@# @;


1.6
date	2001.08.11.09.08.13;	author dlr;	state dead;
branches;
next	1.5;

1.5
date	2001.03.27.02.35.57;	author jmcnally;	state Exp;
branches;
next	1.4;

1.4
date	2001.03.20.03.40.43;	author lucas;	state Exp;
branches;
next	1.3;

1.3
date	2001.03.07.01.17.59;	author lucas;	state Exp;
branches;
next	1.2;

1.2
date	2001.02.28.00.48.58;	author lucas;	state Exp;
branches;
next	1.1;

1.1
date	2001.02.27.01.45.46;	author lucas;	state Exp;
branches;
next	;


desc
@@


1.6
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@#set ($db = $table.Database)
#if ($db.Package)
    #set ($package = $db.Package)
#else
    #set ($package = $defaultPackage)
#end
package ${package};

#if ($db.BaseClass)
    #if ($db.BaseClass == "")
        #set ($extendsBaseClass = "" )
    #else
        #set ($extendsBaseClass = "extends $db.BaseClass" )
    #end
#else
    #set ($extendsBaseClass = "extends BaseObject")
#end

// JDK classes
import java.util.*;
import java.math.*;

// Turbine classes
import org.apache.turbine.om.*;
import org.apache.turbine.om.peer.BasePeer;
import org.apache.turbine.util.db.Criteria;
#if ($addSaveMethod)
import org.apache.turbine.util.ObjectUtils;
#end
import org.apache.turbine.util.StringUtils;
import org.apache.turbine.util.ParameterParser;
import org.apache.turbine.util.Log;
import org.apache.turbine.util.db.pool.DBConnection;

/** 
 * This class was autogenerated by Torque on:
 *
 * [$now]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to $table.JavaName 
 */
public abstract class $basePrefix$table.JavaName $extendsBaseClass
{
#foreach ($col in $table.Columns)
    #set ( $cjtype = $col.JavaNative )
    #set ( $clo=$col.Name.toLowerCase() )
    #set ($defVal = "")
    #if ($col.DefaultValue && !$col.DefaultValue.equalsIgnoreCase("NULL") )
        #set ( $quote = '' )
        #if ( $cjtype == "String" ) 
            #set ( $quote = '"' )
        #end
        #set ($defVal = "=$quote$col.DefaultValue$quote")
    #end
    /** the value for the $clo field */
    private $cjtype $clo$defVal;
#end


#foreach ($col in $table.Columns)
    #set ( $cfc=$col.JavaName )
    #set ( $clo=$col.Name.toLowerCase() )
    #set ( $cjtype = $col.JavaNative )
    /**
     * Get the $cfc
     * @@return $cjtype
     */
     public $cjtype get${cfc}()
     {
          return $clo;
     }

#set ( $throwsClause = "" )
#if ($complexOM)
    #if ($col.isForeignKey())
        #set ( $throwsClause = "throws Exception" )
    #end    
    #if ( $col.Referrers.size() > 0 )
        #if ($throwsClause == "")
            #set ( $throwsClause = "throws Exception" )
        #end
    #end
#end

    /**
     * Set the value of $cfc
     */
     public void set${cfc}($cjtype v ) $throwsClause
     {
#if ($complexOM)
  #if ($col.isForeignKey())
    #set ( $tmp = $col.RelatedTableName )
    #set ( $tblFK = $table.Database.getTable($tmp) )
    #set ( $colFK = $tblFK.getColumn($col.RelatedColumnName) )
    #if ($col.isMultipleFK())
        #set ( $varName = $strings.concat(["a", $tblFK.JavaName, "RelatedBy", $col.JavaName]) )
    #elseif ($tmp.equals($table.Name))
        #set ( $varName = $strings.concat(["a", $tblFK.JavaName, "RelatedBy", $col.JavaName]) )
    #else
        #set ( $varName = $strings.concat(["a", $tblFK.JavaName]) )
    #end
    $varName = null;
  #end

  #foreach ($fk in $col.Referrers)
     #set ( $fkColName = $fk.ForeignLocalMapping.get($col.Name) )
     #set ( $tblFK = $fk.Table )
     #if ( !($tblFK.Name.equals($table.Name)) )

        #set ( $colFK = $tblFK.getColumn($fkColName) )

        #if ($colFK.isMultipleFK())
            #set ( $collName = $strings.concat(["coll", $tblFK.JavaName, "sRelatedBy", $colFK.JavaName]) )
        #else
            #set ( $collName = $strings.concat(["coll", $tblFK.JavaName, "s"]) )
        #end

          // update associated $tblFK.JavaName
          if ($collName != null )
          {
              for (int i=0; i<${collName}.size(); i++)
              {
                  ((${tblFK.JavaName})${collName}.get(i))
                      .set${colFK.JavaName}(v);
              }
          }
     #end
  #end 
#end

#if ($addSaveMethod)

 #if ( ($cjtype == "int") || ($cjtype == "long") || ($cjtype == "boolean") 
    || ($cjtype == "short") || ($cjtype == "float") || ($cjtype == "double")
    || ($cjtype == "char") || ($cjtype == "byte") )
        if (this.$clo != v)
        {
 #else
        if ( !ObjectUtils.equals(this.$clo, v) )
        {
 #end
          #if ( ($cjtype == "NumberKey") 
               || ($cjtype == "StringKey")
               || ($cjtype == "DateKey") )
            if (this.$clo == null)
            {
                $cjtype copyKey = new $cjtype(v);
                this.$clo = copyKey;
            }
            else
            {
                this.${clo}.setValue(v);
            }
          #else  
            this.$clo = v;
          #end
            setModified(true);
        }
#else
          this.$clo = v;
#end
     }

##if ($complexOM)
  #if ($col.isPrimaryKey() || $col.isForeignKey())
   /**
    * Set the value of $cfc as a string.
    */
    public void set${cfc}(String v ) $throwsClause
    {
         set${cfc}(new ${cjtype}(v));
    }
  #end
##end

#end

 ##association code

#if ($complexOM)
 #foreach ($fk in $table.ForeignKeys)

   #set ( $tmp = $fk.ForeignTableName )
   #set ( $tblFK = $table.Database.getTable($tmp) )
   #set ( $className = $tblFK.JavaName )

   #set ( $relCol = "" )
   #foreach ($columnName in $fk.LocalColumns)
    #set ( $column = $table.getColumn($columnName) )
    #if ($column.isMultipleFK())
        #set ( $relCol = $strings.concat([$relCol, $column.JavaName]) )
    #elseif ($tmp.equals($table.Name))
        #set ( $relCol = $strings.concat([$relCol, $column.JavaName]) )
    #end
   #end

   #if ($relCol != "")
       #set ( $relCol = $strings.concat(["RelatedBy", $relCol]) )
   #end

   #set ( $pVarName = $strings.concat([$className, $relCol]) )
   #set ( $varName = $strings.concat(["a", $pVarName]) )

    /**
     * Declares an association between this object and a $className object
     *
     * @@param $className v
     */
    private $className $varName;
    public void set${pVarName}($className v) throws Exception
    {
   #foreach ($columnName in $fk.LocalColumns)
    #set ( $column = $table.getColumn($columnName) )
    #set ( $colFKName = $fk.LocalForeignMapping.get($columnName) )
    #set ( $colFK = $tblFK.getColumn($colFKName) )
        set${column.JavaName}(v.get${colFK.JavaName}());
   #end
        $varName = v;
    }

   #set ( $and = "" )
   #set ( $comma = "" )
   #set ( $conditional = "" )
   #set ( $arglist = "" )
   #foreach ($columnName in $fk.LocalColumns)
    #set ( $column = $table.getColumn($columnName) )
    #set ( $cjtype = $column.JavaNative )
    #set ( $clo=$column.Name.toLowerCase() )
    #if ($cjtype == "int")
        #set ( $conditional = $strings.concat([$conditional, $and, "this.", $clo, ">0"]) )
    #elseif ($cjtype == "long")
        #set ( $conditional = $strings.concat([$conditional, $and, "this.", $clo, ">0"]) )
    #elseif ($cjtype == "short")
        #set ( $conditional = $strings.concat([$conditional, $and, "this.", $clo, ">0"]) )
    #else
        #set ( $conditional = $strings.concat([$conditional, $and, "!ObjectUtils.equals(this.", $clo, ", null)"]) )
    #end
    #set ( $arglist = $strings.concat([$arglist, $comma, "this.", $clo]) )
    #set ( $and = " && " )
    #set ( $comma = ", " )
   #end
   #set ( $pCollName = $strings.concat([$table.JavaName, "s", $relCol]) )
    
    public $className get${pVarName}() throws Exception
    {
        if ( $varName==null && ($conditional) )
        {
            $varName = ${className}Peer.retrieveByPK($arglist);
            // The following can be used instead of the line above to
            // guarantee the related object contains a reference
            // to this object, but this level of coupling 
            // may be undesirable in many circumstances.
            // As it can lead to a db query with many results that may
            // never be used.  
            // $className obj = ${className}Peer.retrieveByPK($arglist);
            // obj.add${pCollName}(this);
        }
        return $varName;
    }


    /**
     * Provides convenient way to set a relationship based on a 
     * ObjectKey.  e.g. 
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
#if ($fk.LocalColumns.size() > 1)
     * Note: It is important that the xml schema used to create this class
     * maintains consistency in the order of related columns between
     * $table.Name and ${tblFK.Name}.  
     * If for some reason this is impossible, this method should be 
     * overridden in <code>$table.JavaName</code>.
#end
     */
    public void set${pVarName}Key(ObjectKey key) throws Exception
    {
    #if ($fk.LocalColumns.size() > 1)
        SimpleKey[] keys = (SimpleKey[])key.getValue();
        #set ($i = 0)
        #foreach ($colName in $fk.LocalColumns)
            #set ($col = $table.getColumn($colName) )
            set${col.JavaName}(($col.JavaNative)keys[$i]);
            #set ( $i = $i + 1 )
        #end
    #else
        #set ($colName = $fk.LocalColumns.get(0))
        #set ($col = $table.getColumn($colName) )
        set${col.JavaName}(($col.JavaNative)key);        
    #end
    }

 #end   ## end of foreach loop over foreign keys

 ## 
 ## setup foreign key associations
 ## 
 #foreach ($fk in $table.Referrers)
  #set ( $tblFK = $fk.Table )
  #if ( !($tblFK.Name.equals($table.Name)) )
   #set ( $className = $tblFK.JavaName )
   #set ( $relatedByCol = "" )
   #foreach ($columnName in $fk.LocalColumns)
    #set ( $column = $tblFK.getColumn($columnName) )
    #if ($column.isMultipleFK())
        #set ($relatedByCol=$strings.concat([$relatedByCol,$column.JavaName]))
    #end
   #end

   #if ($relatedByCol == "")
    #set ( $suffix = "" )
    #set ( $relCol = $strings.concat([$className, "s"]) )
   #else
    #set ( $suffix = $strings.concat(["RelatedBy", $relatedByCol]) )
    #set ( $relCol=$strings.concat([$className,"sRelatedBy",$relatedByCol]))
   #end
   #set ( $collName = $strings.concat(["coll", $relCol]) )

    /**
     * Collection to store aggregation of $collName
     */
    private Vector $collName;
    /**
     * Temporary storage of $collName to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
//    private Vector temp$collName;

    public void init${relCol}()
    {
        if ($collName == null)
            $collName = new Vector();
    }

    /**
     * Method called to associate a $tblFK.JavaName object to this object
     * through the $className foreign key attribute
     *
     * @@param $className l
     */
    public void add${relCol}($className l) throws Exception
    {
        /*
        if ($collName == null)
        {
            if (temp$collName == null)
            {
                temp$collName = new Vector();
            }
            temp${collName}.add(l);
        }
        else
        {
            ${collName}.add(l);
        }
        */
        get${relCol}().add(l);
        l.set${table.JavaName}${suffix}(($table.JavaName)this);
    }

    /**
     * The criteria used to select the current contents of $collName
     */
    private Criteria last${relCol}Criteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of 
     * get${relCol}(new Criteria())
     */
    public Vector get${relCol}() throws Exception
    {
        if ($collName == null)
        {
            $collName = get${relCol}(new Criteria(10));
        }
        return $collName;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection. 
     * Otherwise if this $table.JavaName is new, it will return
     * an empty collection; or if this $table.JavaName has previously
     * been saved, it will retrieve related ${relCol} from storage.
     */
    public Vector get${relCol}(Criteria criteria) throws Exception
    {
        if ($collName == null)
        {
            if ( isNew() ) 
            {
               $collName = new Vector();       
            } 
            else
            {
   #foreach ($columnName in $fk.ForeignColumns)
       #set ( $column = $table.getColumn($columnName) )
       #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
       #set ( $colFK = $tblFK.getColumn($colFKName) )
                criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() );               
   #end
                $collName = ${className}Peer.doSelect(criteria);
            }
/*
            if (temp$collName != null)
            {
                for (int i=0; i<temp${collName}.size(); i++)
                {
                    ${collName}.add(temp${collName}.get(i));
                }
                temp$collName = null;
            }
*/
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
   #foreach ($columnName in $fk.ForeignColumns)
       #set ( $column = $table.getColumn($columnName) )
       #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
       #set ( $colFK = $tblFK.getColumn($colFKName) )
                criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() );               
   #end
            if ( !last${relCol}Criteria.equals(criteria)  )
            {
                $collName = ${className}Peer.doSelect(criteria);  
            }
        }
        last${relCol}Criteria = criteria; 

        return $collName;
    }
 #set ( $countFK = 0 )
 #foreach ($dummyFK in $tblFK.ForeignKeys)
    #set ( $countFK = $countFK + 1 )
 #end

## ------------------------------------------------------------
## 

  #if ($countFK >= 1)
   #set ( $lastTable = "" ) 
   #foreach ($fk2 in $tblFK.ForeignKeys)
   
   ## Add join methods if the fk2 table is not this table or
   ## the fk2 table references this table multiple times.

   #set ( $doJoinGet = true )
   #if ( $fk2.ForeignTableName.equals($table.Name) )
        #set ( $doJoinGet = false )
   #end

   #foreach ($columnName in $fk2.LocalColumns)
    #set ( $column = $tblFK.getColumn($columnName) )
    #if ($column.isMultipleFK())
        #set ( $doJoinGet = true )
    #end
   #end

    #set ( $tblFK2 = $table.Database.getTable($fk2.ForeignTableName) )
    #set ( $relatedByCol2 = "" )
    #foreach ($columnName in $fk2.LocalColumns)
        #set ( $column = $tblFK.getColumn($columnName) )
        #if ($column.isMultipleFK())
            #set($relatedByCol2=$strings.concat([$relatedByCol2,$column.JavaName]))
        #end
    #end 

    #set ( $fkClassName = $tblFK2.JavaName )
    ## do not generate code for self-referencing fk's, it would be
    ## good to do, but it is just not implemented yet.
    #if ($className == $fkClassName)
        #set ( $doJoinGet = false )
    #end        

    #if ($relatedByCol2 == "")
        #set ( $relCol2 = $fkClassName )
    #else
        #set ($relCol2=$strings.concat([$fkClassName,"RelatedBy",$relatedByCol2]))
    #end

    #if ( $relatedByCol == "") 
    #else   
        #if ( $relatedByCol.equals($relatedByCol2) ) 
           #set ( $doJoinGet = false )
        #end
    #end

   #if ($doJoinGet)

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection. 
     * Otherwise if this $table.JavaName is new, it will return
     * an empty collection; or if this $table.JavaName has previously
     * been saved, it will retrieve related ${relCol} from storage.
     */
    public Vector get${relCol}Join${relCol2}(Criteria criteria) 
        throws Exception
    {
        if ($collName == null)
        {
            if ( isNew() ) 
            {
               $collName = new Vector();       
            } 
            else
            {
   #foreach ($columnName in $fk.ForeignColumns)
       #set ( $column = $table.getColumn($columnName) )
       #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
       #set ( $colFK = $tblFK.getColumn($colFKName) )
                criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() );               
   #end
                $collName = ${className}Peer.doSelectJoin${relCol2}(criteria);
            }
            
            #* /*
            if (temp$collName != null)
            {
                for (int i=0; i<temp${collName}.size(); i++)
                {
                    ${collName}.add(temp${collName}.get(i));
                }
                temp$collName = null;
            } 
               */ *#
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
   #foreach ($columnName in $fk.ForeignColumns)
       #set ( $column = $table.getColumn($columnName) )
       #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
       #set ( $colFK = $tblFK.getColumn($colFKName) )
                criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() );               
   #end
            if ( !last${relCol}Criteria.equals(criteria)  )
            {
                $collName = ${className}Peer.doSelectJoin${relCol2}(criteria);
            }
        }
        last${relCol}Criteria = criteria; 

        return $collName;
    }
  #end #end #end #end

## ===========================================================
#*
  #if ($countFK > 2)

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection. 
     * Otherwise if this $table.JavaName is new, it will return
     * an empty collection; or if this $table.JavaName has previously
     * been saved, it will retrieve related ${relCol} from storage.
     */
    public Vector get${relCol}JoinAllExcept${table.JavaName}(Criteria criteria) 
        throws Exception
    {
        if ($collName == null)
        {
            if ( isNew() ) 
            {
               $collName = new Vector();       
            } 
            else
            {
   #foreach ($columnName in $fk.ForeignColumns)
       #set ( $column = $table.getColumn($columnName) )
       #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
       #set ( $colFK = $tblFK.getColumn($colFKName) )
                criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() );               
   #end
                $collName = ${className}Peer.doSelectJoinAllExcept${table.JavaName}${suffix}(criteria);
            }
/*
            if (temp$collName != null)
            {
                for (int i=0; i<temp${collName}.size(); i++)
                {
                    ${collName}.add(temp${collName}.get(i));
                }
                temp$collName = null;
            }
*/
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
   #foreach ($columnName in $fk.ForeignColumns)
       #set ( $column = $table.getColumn($columnName) )
       #set ( $colFKName = $fk.ForeignLocalMapping.get($columnName) )
       #set ( $colFK = $tblFK.getColumn($colFKName) )
                criteria.add(${className}Peer.${colFK.Name.toUpperCase()}, get${column.JavaName}() );               
   #end
            if ( !last${relCol}Criteria.equals(criteria)  )
            {
                $collName = ${className}Peer.doSelectJoinAllExcept${table.JavaName}${suffix}(criteria);
            }
        }
        last${relCol}Criteria = criteria; 

        return $collName;
    }

  #end
  
*#
## ------------------------------------------------------------


 #end    ## ends foreach over table.Referrers

#end    ##ends the if(complexOM)

##
## getByName code
##
#if ($addGetByNameMethod)
    private static Vector fieldNames_ = null;

    /**
     * Generate a list of field names.
     */
    public static synchronized List getFieldNames()
    {
      if (fieldNames_ == null)
      {
        fieldNames_ = new Vector();
    #foreach ($col in $table.Columns)
        fieldNames_.add("${col.JavaName}");
    #end
      }
      return fieldNames_;
    }

    /**
     * Retrieves a field from the object by name passed in
     * as a String.
     */
    public Object getByName(String name)
    {
    #foreach ($col in $table.Columns)
      #set ( $cfc = $col.JavaName )
      #set ( $cjtype = $col.JavaNative )
        if (name.equals("${col.JavaName}"))
	{
	  #if ($cjtype == "int")
	    return new Integer(get${cfc}());
	  #elseif ($cjtype == "long")
	    return new Long(get${cfc}());
	  #elseif ($cjtype == "float")
	    return new Float(get${cfc}());
	  #elseif ($cjtype == "double")
	    return new Double(get${cfc}());
	  #elseif ($cjtype == "boolean")
	    return new Boolean(get${cfc}());
	  #elseif ($cjtype == "short")
	    return new Short(get${cfc}());
	  #elseif ($cjtype == "byte")
	    return new Byte(get${cfc}());
	  #elseif ($cjtype == "char")
	    return new Character(get${cfc}());
	  #else
	    return get${cfc}();
	  #end
	}
    #end
        return null; 
    }
    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     */
    public Object getByPeerName(String name)
    {
    #foreach ($col in $table.Columns)
      #set ( $cfc = $col.JavaName )
      #set ( $cup=$col.Name.toUpperCase() )
      #set ( $cjtype = $col.JavaNative )
        if (name.equals(${table.JavaName}Peer.$cup ))
	    {
	  #if ($cjtype == "int")
	    return new Integer(get${cfc}());
	  #elseif ($cjtype == "long")
	    return new Long(get${cfc}());
	  #elseif ($cjtype == "float")
	    return new Float(get${cfc}());
	  #elseif ($cjtype == "double")
	    return new Double(get${cfc}());
	  #elseif ($cjtype == "boolean")
	    return new Boolean(get${cfc}());
	  #elseif ($cjtype == "short")
	    return new Short(get${cfc}());
	  #elseif ($cjtype == "byte")
	    return new Byte(get${cfc}());
	  #elseif ($cjtype == "char")
	    return new Character(get${cfc}());
	  #else
	    return get${cfc}();
	  #end
	}
    #end
        return null; 
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     */
    public Object getByPosition(int pos)
    {
    #set ($i = 0)
    #foreach ($col in $table.Columns)
      #set ( $cfc = $col.JavaName )
      #set ( $cjtype = $col.JavaNative )
    if ( pos == $i )
	{
	  #if ($cjtype == "int")
	    return new Integer(get${cfc}());
	  #elseif ($cjtype == "long")
	    return new Long(get${cfc}());
	  #elseif ($cjtype == "float")
	    return new Float(get${cfc}());
	  #elseif ($cjtype == "double")
	    return new Double(get${cfc}());
	  #elseif ($cjtype == "boolean")
	    return new Boolean(get${cfc}());
	  #elseif ($cjtype == "short")
	    return new Short(get${cfc}());
	  #elseif ($cjtype == "byte")
	    return new Byte(get${cfc}());
	  #elseif ($cjtype == "char")
	    return new Character(get${cfc}());
	  #else
	    return get${cfc}();
	  #end
	}
    #set ($i = $i + 1)
    #end
        return null; 
    }

#end     ## ends the if(addGetByNameMethod)
	

#if ($addSaveMethod)
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     */
    public void save() throws Exception
    {
 #if ($complexOM)
        DBConnection dbCon = null;
        try
        {
            dbCon = BasePeer.beginTransaction(
                ${table.JavaName}Peer.getMapBuilder()
                .getDatabaseMap().getName());
            save(dbCon);
        }
        catch(Exception e)
        {
            BasePeer.rollBackTransaction(dbCon);
            throw e;
        }
        BasePeer.commitTransaction(dbCon);

 #else

        if (isModified())
        {
            if (isNew())
            {
                ${table.JavaName}Peer.doInsert(($table.JavaName)this);
                setNew(false);
            }
            else
            {
                ${table.JavaName}Peer.doUpdate(($table.JavaName)this);
            }
        }
      
 #end
    }

  #if ($complexOM)
    // flag to prevent endless save loop, if this object is referenced
    // by another object which falls in this transaction.
    private boolean alreadyInSave = false;
  #end
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     */
    public void save(DBConnection dbCon) throws Exception
    {
  #if ($complexOM)
      if (!alreadyInSave)
      {
        alreadyInSave = true;
  #end      
        if (isModified())
        {
            if (isNew())
            {
                ${table.JavaName}Peer.doInsert(($table.JavaName)this, dbCon);
            }
            else
            {
                ${table.JavaName}Peer.doUpdate(($table.JavaName)this, dbCon);
                setNew(false);
            }
        }

 #if ($complexOM)
  #foreach ($fk in $table.Referrers)
     #set ( $tblFK = $fk.Table )
     #if ( !($tblFK.Name.equals($table.Name)) )
        #set ( $className = $tblFK.JavaName )
        #set ( $relCol = "" )
        #foreach ($columnName in $fk.LocalColumns)
            #set ( $column = $tblFK.getColumn($columnName) )
            #if ($column.isMultipleFK())
                #set ( $relCol = $strings.concat([$relCol, $column.JavaName]) )
            #end
        #end

        #if ($relCol == "")
            #set ( $relCol = $strings.concat([$className, "s"]) )
        #else
            #set ( $relCol = $strings.concat([$className, "sRelatedBy", $relCol]) )
        #end
        #set ( $collName = $strings.concat(["coll", $relCol]) )

          if ($collName != null )
          {
              for (int i=0; i<${collName}.size(); i++)
              {
                  ((${className})${collName}.get(i)).save(dbCon);
              }
          }
     #end
  #end      
 #end
  #if ($complexOM)
        alreadyInSave = false;
      }
  #end      
    }
#end

#set ( $throwsClause = "" )
#set ( $argList = "" )
#set ( $argList2 = "" )
#set ( $comma = "" )
#foreach ($col in $table.PrimaryKeys)
    #if ($complexOM)
        #if ( $col.isForeignKey() || ($col.Referrers.size() > 0) )
            #set ( $throwsClause = "throws Exception" )
        #end
    #end

    #set ( $clo=$col.Name.toLowerCase() )
    #set ( $cjtype = $col.JavaNative )
    #set ($argList = "${argList}$comma $cjtype $clo")
    #set ($argList2 = "${argList2}$comma String $clo")

    #set ( $comma = "," )            
#end    

#if ($table.PrimaryKeys.size() == 1)

    #set ($col = $table.PrimaryKeys.get(0) )
    #set ( $clo=$col.Name.toLowerCase() )
    #set ( $cjtype= $col.JavaNative )
    /** 
     * Set the PrimaryKey using ObjectKey.
     *
     * @@param ObjectKey $clo
     */
    public void setPrimaryKey(ObjectKey $clo) 
        $throwsClause {
         set${col.JavaName}(($cjtype)$clo);
    }

    /** 
     * Set the PrimaryKey using a String.
     */
    public void setPrimaryKey(String key) $throwsClause
    {
        set${col.JavaName}(new ${cjtype}(key) );
    }

#elseif ($table.PrimaryKeys.size() > 1)

    private final SimpleKey[] pks = new SimpleKey[$table.PrimaryKeys.size()];
    private final ComboKey comboPK = new ComboKey(pks);
    /** 
     * Set the PrimaryKey with an ObjectKey
     */
    public void setPrimaryKey(ObjectKey key) throws Exception
    {
        SimpleKey[] keys = (SimpleKey[])key.getValue();
    #set ($i = 0)
    #foreach ($pk in $table.PrimaryKeys)
            set${pk.JavaName}(($pk.JavaNative)keys[$i]);
        #set ( $i = $i + 1 )
    #end
    }

    /** 
     * Set the PrimaryKey using SimpleKeys.
     *
#foreach ($col in $table.PrimaryKeys)
    #set ( $clo=$col.Name.toLowerCase() )
    #set ( $cjtype= $col.JavaNative )
     * @@param $cjtype $clo
#end
     */
    public void setPrimaryKey($argList) 
        $throwsClause {
#foreach ($col in $table.PrimaryKeys)
         set${col.JavaName}($col.Name.toLowerCase());
#end
    }

    /** 
     * Set the PrimaryKey with Strings.
     *
#foreach ($col in $table.PrimaryKeys)
    #set ( $clo=$col.Name.toLowerCase() )
     * @@param String $clo
#end
     */
    public void setPrimaryKey($argList2) 
        $throwsClause {
#foreach ($col in $table.PrimaryKeys)
         set${col.JavaName}(new ${col.JavaNative}($col.Name.toLowerCase()));
#end
    }

    /** 
     * Set the PrimaryKey using a String.
     */
    public void setPrimaryKey(String key) throws Exception
    {
        int prevPos = 0;

     #set ($int = "int ")
     #foreach ($col in $table.PrimaryKeys)
        ${int}colonPos = key.indexOf(':', prevPos);
        set${col.JavaName}( new ${col.JavaNative}(key.substring(prevPos, colonPos)) );
        prevPos = colonPos + 1;
        #set ($int = "")
     #end
    }

#end


    /** 
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey() 
    {
#if ($table.PrimaryKeys.size() == 1)
        return get${table.PrimaryKeys.get(0).JavaName}();
#else
    #set ($i = 0)
    #foreach ($pk in $table.PrimaryKeys)
        pks[$i] = get${pk.JavaName}();
        #set ($i = $i +1)
    #end
        return comboPK;
#end
    }

    /**
     * Makes a copy of this object.  
     * It creates a new object filling in the simple attributes.
#if ($complexOM)
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
#end
     */
#if ($table.ChildrenColumn) 
    public $table.JavaName copyInto($table.JavaName copyObj) throws Exception
    {
#else
    public $table.JavaName copy() throws Exception
    {
        $table.JavaName copyObj = new ${table.JavaName}();
#end
#foreach ($col in $table.Columns)
        copyObj.set${col.JavaName}($col.Name.toLowerCase());
#end 

#set ( $list = "List " )
#foreach ($fk in $table.Referrers)
    #set ( $tblFK = $fk.Table )
    #if ( !($tblFK.Name.equals($table.Name)) )
        #set ( $className = $tblFK.JavaName )
        #set ( $relCol = "" )
        #foreach ($columnName in $fk.LocalColumns)
            #set ( $column = $tblFK.getColumn($columnName) )
            #if ($column.isMultipleFK())
                #set ( $relCol = $strings.concat([$relCol, $column.JavaName]) )
            #end
        #end

        #if ($relCol == "")
            #set ( $pCollName = $strings.concat([$className, "s"]) )
        #else
            #set ( $pCollName = $strings.concat([$className, "sRelatedBy", $relCol]) )
        #end

         ${list}v = copyObj.get${pCollName}();
         for (int i=0; i<v.size(); i++)
         {
             ((Persistent)v.get(i)).setNew(true);
         }
        #set ( $list = "" )
    #end
#end 

#foreach ($col in $table.Columns)
    #if ($col.isPrimaryKey())
        #set ( $pkid = "null" )
        #set ( $cjtype = $col.JavaNative )
        copyObj.set${col.JavaName}((${cjtype})${pkid});
    #end
#end 
        return copyObj;
    }
}
@


1.5
log
@id/primary_key was being modified through calls to setSomeId. fix is to
copy the key so that it is not the actual key referenced by the object
that owns it.

PR: 3321
Obtained from:
Submitted by:	jmcnally
Reviewed by:
@
text
@@


1.4
log
@updated for new torque
@
text
@d148 2
a149 1
                this.$clo = v;
@


1.3
log
@Updating for latest Torque
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d1053 2
a1054 2
    return copyObj;
    }             
a1055 1

@


1.2
log
@Latest turbine templates
@
text
@d7 1
a7 1
package ${package}.base;
a34 3
import ${package}.*;
import ${package}.peer.*;

d43 1
a43 1
public abstract class $table.BaseJavaName $extendsBaseClass
d1040 1
a1040 1
             ((BaseObject)v.get(i)).setNew(true);
@


1.1
log
@Added the ability for torque to be called from within the Helm build procedure.  The only major restructure is that the helm-schema.xml file will now live in the sql/schema directory instead of sql/org/tigris/helm.
@
text
@d51 8
d60 1
a60 1
    private $cjtype $clo;
d100 1
a100 1
        #set ( $varName = $tstrings.concat(["a", $tblFK.JavaName, "RelatedBy", $col.JavaName]) )
d102 1
a102 1
        #set ( $varName = $tstrings.concat(["a", $tblFK.JavaName, "RelatedBy", $col.JavaName]) )
d104 1
a104 1
        #set ( $varName = $tstrings.concat(["a", $tblFK.JavaName]) )
d117 1
a117 1
            #set ( $collName = $tstrings.concat(["coll", $tblFK.JavaName, "sRelatedBy", $colFK.JavaName]) )
d119 1
a119 1
            #set ( $collName = $tstrings.concat(["coll", $tblFK.JavaName, "s"]) )
d194 1
a194 1
        #set ( $relCol = $tstrings.concat([$relCol, $column.JavaName]) )
d196 1
a196 1
        #set ( $relCol = $tstrings.concat([$relCol, $column.JavaName]) )
d201 1
a201 1
       #set ( $relCol = $tstrings.concat(["RelatedBy", $relCol]) )
d204 2
a205 2
   #set ( $pVarName = $tstrings.concat([$className, $relCol]) )
   #set ( $varName = $tstrings.concat(["a", $pVarName]) )
d233 1
a233 1
        #set ( $conditional = $tstrings.concat([$conditional, $and, "this.", $clo, ">0"]) )
d235 1
a235 1
        #set ( $conditional = $tstrings.concat([$conditional, $and, "this.", $clo, ">0"]) )
d237 1
a237 1
        #set ( $conditional = $tstrings.concat([$conditional, $and, "this.", $clo, ">0"]) )
d239 1
a239 1
        #set ( $conditional = $tstrings.concat([$conditional, $and, "!ObjectUtils.equals(this.", $clo, ", null)"]) )
d241 1
a241 1
    #set ( $arglist = $tstrings.concat([$arglist, $comma, "this.", $clo]) )
d245 1
a245 1
   #set ( $pCollName = $tstrings.concat([$table.JavaName, "s", $relCol]) )
d308 1
a308 1
        #set ($relatedByCol=$tstrings.concat([$relatedByCol,$column.JavaName]))
d314 1
a314 1
    #set ( $relCol = $tstrings.concat([$className, "s"]) )
d316 2
a317 2
    #set ( $suffix = $tstrings.concat(["RelatedBy", $relatedByCol]) )
    #set ( $relCol=$tstrings.concat([$className,"sRelatedBy",$relatedByCol]))
d319 1
a319 1
   #set ( $collName = $tstrings.concat(["coll", $relCol]) )
d472 1
a472 1
            #set($relatedByCol2=$tstrings.concat([$relatedByCol2,$column.JavaName]))
d486 1
a486 1
        #set ($relCol2=$tstrings.concat([$fkClassName,"RelatedBy",$relatedByCol2]))
d698 1
a698 1
        if (name == ${table.JavaName}Peer.$cup )
d846 1
a846 1
                #set ( $relCol = $tstrings.concat([$relCol, $column.JavaName]) )
d851 1
a851 1
            #set ( $relCol = $tstrings.concat([$className, "s"]) )
d853 1
a853 1
            #set ( $relCol = $tstrings.concat([$className, "sRelatedBy", $relCol]) )
d855 1
a855 1
        #set ( $collName = $tstrings.concat(["coll", $relCol]) )
d1030 1
a1030 1
                #set ( $relCol = $tstrings.concat([$relCol, $column.JavaName]) )
d1035 1
a1035 1
            #set ( $pCollName = $tstrings.concat([$className, "s"]) )
d1037 1
a1037 1
            #set ( $pCollName = $tstrings.concat([$className, "sRelatedBy", $relCol]) )
@

