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


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

1.4
date	2001.03.30.23.59.25;	author edk;	state Exp;
branches;
next	1.3;

1.3
date	2001.03.07.01.17.59;	author lucas;	state Exp;
branches
	1.3.6.1;
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	;

1.3.6.1
date	2001.04.17.22.36.28;	author edk;	state Exp;
branches;
next	;


desc
@@


1.5
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};

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

// Village classes
import com.workingdogs.village.*;

// Turbine classes
import org.apache.turbine.om.*;
import org.apache.turbine.om.peer.*;
import org.apache.turbine.util.*;
import org.apache.turbine.util.db.*;
import org.apache.turbine.util.db.map.*;
import org.apache.turbine.util.db.pool.DBConnection;


// Local classes
import ${package}.map.*;

#if ($db.BasePeer)
    #set ($extendsBasePeer = "extends $db.BasePeer" )
#else
    #set ($extendsBasePeer = "extends BasePeer")
#end

/**
  * This class was autogenerated by Torque on:
  *
  * [$now]
  *
  */
public abstract class $basePrefix${table.JavaName}Peer $extendsBasePeer
{
    /** the mapbuilder for this class */
    private static final ${table.JavaName}MapBuilder mapBuilder = 
        (${table.JavaName}MapBuilder)getMapBuilder(${table.JavaName}MapBuilder.CLASS_NAME);

    /** the table name for this class */
    public static final String TABLE_NAME = mapBuilder.getTable();

#foreach ($col in $table.Columns)
    #set ( $tfc=$table.JavaName )
    #set ( $cfc=$col.JavaName )
    #set ( $cup=$col.Name.toUpperCase() )
    /** the column name for the $cup field */
    public static final String $cup = mapBuilder.get${tfc}_${cfc}();
#end

    /** number of columns for this peer */
    public static final int numColumns =  $table.NumColumns;

    /** A class that can be returned by this peer. */
    protected static final String CLASSNAME_DEFAULT = 
        "${package}.$table.JavaName";

    /** A class that can be returned by this peer. */
    protected static final Class CLASS_DEFAULT = initClass();

    /** Initialization method for static CLASS_DEFAULT attribute */
    private static Class initClass()
    {
        Class c = null;
        try
        { 
            c = Class.forName(CLASSNAME_DEFAULT);
        }
        catch (Exception e)
        {
            Log.error("A FATAL ERROR has occurred which should not" +
                "have happened under any circumstance.  Please notify" +
                "Turbine and give as many details as possible including the " +
                "error stacktrace.", e);
        }
        return c;
    }

#if ($table.ChildrenColumn) 
    #set ($col = $table.ChildrenColumn)
    #set ( $tfc=$table.JavaName )
    #set ( $cfc=$col.JavaName )
    #set ( $cup=$col.Name.toUpperCase() )

    #if ($col.isEnumeratedClasses())
        ## NOTE: this hack requires a class type definition column to
        ## be a primitive type or a String. Should not be a bad assumption
        #if ($col.isPrimitive())
            #set ($quote = "")
        #else
            #set ($quote = '"')
        #end

        #foreach ($child in $col.Children)
    /** A key representing a particular subclass */
    public static final $col.JavaNative CLASSKEY_$child.Key.toUpperCase() = 
        $quote$child.Key$quote;

    /** A class that can be returned by this peer. */
    public static final String CLASSNAME_$child.Key.toUpperCase() = 
        "${package}.$child.ClassName";

    /** A class that can be returned by this peer. */
    public static final Class CLASS_$child.Key.toUpperCase() = 
        init${child.Key.toUpperCase()}Class();

    /** Initialization method for static CLASS_$child.Key.toUpperCase() attribute */
    private static Class init${child.Key.toUpperCase()}Class()
    {
        Class c = null;
        try
        { 
            c = Class.forName(CLASSNAME_$child.Key.toUpperCase());
        }
        catch (Exception e)
        {
            Log.error("A FATAL ERROR has occurred which should not" +
                "have happened under any circumstance.  Please notify " +
                "Turbine and give as many details as possible including the " +
                "error stacktrace.", e);
        }
        return c;
    }

        #end
    #end
#end

    /** Method to do inserts */
    public static ObjectKey doInsert( Criteria criteria ) throws Exception
    {
        criteria.setDbName(mapBuilder.getDatabaseMap().getName());
     #foreach ($col in $table.Columns)
         #set ( $cup=$col.Name.toUpperCase() )
         #if($col.isBooleanInt())
        // check for conversion from boolean to int
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, 1);
                }
                else
                {   
                    criteria.add($cup, 0);
                }
            }                     
         }
         #elseif ($col.isBooleanChar())
        // check for conversion from boolean to Y/N
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, "Y");
                }
                else
                {   
                    criteria.add($cup, "N");
                }
            }                     
         }
         #end
     #end
        return BasePeer.doInsert( criteria );
    }

    /** 
     * Method to do inserts.  This method is to be used during a transaction,
     * otherwise use the doInsert(Criteria) method.  It will take care of 
     * the connection details internally. 
     */
    public static ObjectKey doInsert( Criteria criteria, DBConnection dbCon ) 
        throws Exception
    {
        criteria.setDbName(mapBuilder.getDatabaseMap().getName());
     #foreach ($col in $table.Columns)
         #set ( $cup=$col.Name.toUpperCase() )
         #if($col.isBooleanInt())
        // check for conversion from boolean to int
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, 1);
                }
                else
                {   
                    criteria.add($cup, 0);
                }
            }                     
         }
         #elseif ($col.isBooleanChar())
        // check for conversion from boolean to Y/N
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, "Y");
                }
                else
                {   
                    criteria.add($cup, "N");
                }
            }                     
         }
         #end
     #end
        return BasePeer.doInsert( criteria, dbCon );
    }

    /** Add all the columns needed to create a new object */
    public static void addSelectColumns (Criteria criteria) throws Exception
    {
    #foreach ($col in $table.Columns)
        #set ( $cup=$col.Name.toUpperCase() )
        criteria.addSelectColumn( $cup );
    #end
    }


    /** 
     * Create a new object of type cls from a resultset row starting
     * from a specified offset.  This is done so that you can select
     * other rows than just those needed for this object.  You may
     * for example want to create two objects from the same row.
     */
    public static $table.JavaName row2Object (Record row, 
                                              int offset, 
                                              Class cls ) 
        throws Exception
    {
        $table.JavaName obj = ($table.JavaName)cls.newInstance();
        #set ( $n=0 )
        #foreach ($col in $table.Columns)
            #if ($col.isBooleanChar())
            obj.set${col.JavaName}
                (Y.equals(row.getValue(offset+$n).$col.VillageMethod));
            #elseif ($col.isBooleanInt())
            obj.set${col.JavaName}
                (1 == row.getValue(offset+$n).$col.VillageMethod);
            #else
                #if ($col.isPrimaryKey() || $col.isForeignKey() )
            obj.set${col.JavaName}(
                new ${col.JavaNative}(row.getValue(offset+$n).$col.VillageMethod));
                #else
            obj.set${col.JavaName}(row.getValue(offset+$n).$col.VillageMethod);
                #end
            #end
                #set ( $n = $n + 1 )
        #end
        #if ($addSaveMethod)
            obj.setModified(false);
        #end
        obj.setNew(false);

        return obj;
    }

    /** Method to do selects */
    public static Vector doSelect( Criteria criteria ) throws Exception
    {
        return populateObjects( doSelectVillageRecords(criteria) ); 
    }


    /** Method to do selects within a transaction */
    public static Vector doSelect( Criteria criteria, 
                                   DBConnection dbCon ) 
        throws Exception
    {
        return populateObjects( doSelectVillageRecords(criteria, dbCon) ); 
    }

    /** 
     * Grabs the raw Village records to be formed into objects.
     * This method handles connections internally.  The Record objects
     * returned by this method should be considered readonly.  Do not
     * alter the data and call save(), your results may vary, but are
     * certainly likely to result in hard to track MT bugs.
     */
    public static Vector doSelectVillageRecords( Criteria criteria ) 
        throws Exception
    {
        criteria.setDbName(mapBuilder.getDatabaseMap().getName());
        if (criteria.getSelectColumns().size() == 0)
        {
            addSelectColumns ( criteria );
        }

     #foreach ($col in $table.Columns)
         #set ( $cup=$col.Name.toUpperCase() )
         #if($col.isBooleanInt())
        // check for conversion from boolean to int
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, 1);
                }
                else
                {   
                    criteria.add($cup, 0);
                }
            }                     
         }
         #elseif ($col.isBooleanChar())
        // check for conversion from boolean to Y/N
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, "Y");
                }
                else
                {   
                    criteria.add($cup, "N");
                }
            }                     
         }
         #end
     #end

        // BasePeer returns a Vector of Value (Village) arrays.  The array
        // order follows the order columns were placed in the Select clause.
        return BasePeer.doSelect(criteria);
    }


    /** 
     * Grabs the raw Village records to be formed into objects.
     * This method should be used for transactions 
     */
    public static Vector doSelectVillageRecords( Criteria criteria, 
                                                 DBConnection dbCon ) 
        throws Exception
    {
        addSelectColumns ( criteria );

     #foreach ($col in $table.Columns)
         #set ( $cup=$col.Name.toUpperCase() )
         #if($col.isBooleanInt())
        // check for conversion from boolean to int
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, 1);
                }
                else
                {   
                    criteria.add($cup, 0);
                }
            }                     
         }
         #elseif ($col.isBooleanChar())
        // check for conversion from boolean to Y/N
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, "Y");
                }
                else
                {   
                    criteria.add($cup, "N");
                }
            }                     
         }
         #end
     #end

        // BasePeer returns a Vector of Value (Village) arrays.  The array
        // order follows the order columns were placed in the Select clause.
        return BasePeer.doSelect(criteria, dbCon);
    }

    /** 
     * The returned vector will contain objects of the default type or
     * objects that inherit from the default.
     */
    public static Vector populateObjects(Vector records) 
        throws Exception
    {
        Vector results = new Vector(records.size());

        // populate the object(s)
        for ( int i=0; i<records.size(); i++ )
        {
            Record row = (Record)records.elementAt(i);
#if ($table.ChildrenColumn)
            results.add(${table.JavaName}Peer.row2Object(row, 1,
                ${table.JavaName}Peer.getOMClass(row, 1)));
#else
            results.add(${table.JavaName}Peer
                .row2Object( row,1, CLASS_DEFAULT ));
#end
        }
        return results;
    }

#if ($table.ChildrenColumn)
    #set ($col = $table.ChildrenColumn)
    /** 
     * The returned vector will contain objects of the default type or
     * objects that inherit from the default.
     */
    public static Class getOMClass(Record record, int offset) 
        throws Exception
    {
    #if ($col.isEnumeratedClasses())
            Class omClass = null;
            $col.JavaNative classKey = 
                record.getValue(offset-1 + $col.Position)
                .$col.VillageMethod;
        #set ($if = "if")
        #foreach ($child in $col.Children)
            #if ($col.isPrimitive())
            $if (classKey == CLASSKEY_$child.Key.toUpperCase())
            #else
            $if (CLASSKEY_${child.Key.toUpperCase()}.equals(classKey))
            #end
            {
                omClass = CLASS_$child.Key.toUpperCase();
            }
            #set ($if = "else if")
        #end
            else
            {
                omClass = CLASS_DEFAULT;
            }
            return omClass;
    #else
            return Class.forName( 
                record.getValue(offset-1 + $col.Position).asString());
    #end
    }
#end



    /**
     * Method to do updates. 
     *
     * @@param Criteria object containing data that is used to create the UPDATE statement.
     */
    public static void doUpdate(Criteria criteria) throws Exception
    {
        criteria.setDbName(mapBuilder.getDatabaseMap().getName());
        Criteria selectCriteria = new
            Criteria(mapBuilder.getDatabaseMap().getName(), 2);
     #foreach ($col in $table.Columns)
         #set ( $cup=$col.Name.toUpperCase() )
         #if($col.isBooleanInt())
        // check for conversion from boolean to int
        if ( criteria.containsKey($cup) ) 
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, 1);
                }
                else
                {   
                    criteria.add($cup, 0);
                }
            }                     
         }
         #elseif ($col.isBooleanChar())
        // check for conversion from boolean to Y/N
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, "Y");
                }
                else
                {   
                    criteria.add($cup, "N");
                }
            }                     
        }
         #end
         #if($col.isPrimaryKey())
         selectCriteria.put( $cup, criteria.remove($cup) );
         #end
     #end
         BasePeer.doUpdate( selectCriteria, criteria );
    }

    /** 
     * Method to do updates.  This method is to be used during a transaction,
     * otherwise use the doUpdate(Criteria) method.  It will take care of 
     * the connection details internally. 
     *
     * @@param Criteria object containing data that is used to create the UPDATE statement.
     */
    public static void doUpdate(Criteria criteria, DBConnection dbCon) throws Exception
    {
        criteria.setDbName(mapBuilder.getDatabaseMap().getName());
        Criteria selectCriteria = new
            Criteria(mapBuilder.getDatabaseMap().getName(), 2);
     #foreach ($col in $table.Columns)
         #set ( $cup=$col.Name.toUpperCase() )
         #if($col.isBooleanInt())
        // check for conversion from boolean to int
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, 1);
                }
                else
                {   
                    criteria.add($cup, 0);
                }
            }                     
         }
         #elseif ($col.isBooleanChar())
        // check for conversion from boolean to int
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, "Y");
                }
                else
                {   
                    criteria.add($cup, "N");
                }
            }                     
         }
         #end
         #if($col.isPrimaryKey())
         selectCriteria.put( $cup, criteria.remove($cup) );
         #end
     #end
         BasePeer.doUpdate( selectCriteria, criteria, dbCon );
     }

    /** 
     * Method to do deletes.
     *
     * @@param Criteria object containing data that is used DELETE from database.
     */
     public static void doDelete(Criteria criteria) throws Exception
     {
         criteria.setDbName(mapBuilder.getDatabaseMap().getName());
     #foreach ($col in $table.Columns)
         #set ( $cup=$col.Name.toUpperCase() )
         #if($col.isBooleanInt())
        // check for conversion from boolean to int
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, 1);
                }
                else
                {   
                    criteria.add($cup, 0);
                }
            }                     
         }
         #elseif ($col.isBooleanChar())
        // check for conversion from boolean to Y/N
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, "Y");
                }
                else
                {   
                    criteria.add($cup, "N");
                }
            }                     
         }
         #end
     #end
         BasePeer.doDelete ( criteria );
     }

    /** 
     * Method to do deletes.  This method is to be used during a transaction,
     * otherwise use the doDelete(Criteria) method.  It will take care of 
     * the connection details internally. 
     *
     * @@param Criteria object containing data that is used DELETE from database.
     */
     public static void doDelete(Criteria criteria, DBConnection dbCon) throws Exception
     {
         criteria.setDbName(mapBuilder.getDatabaseMap().getName());
     #foreach ($col in $table.Columns)
         #set ( $cup=$col.Name.toUpperCase() )
         #if($col.isBooleanInt())
        // check for conversion from boolean to int
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, 1);
                }
                else
                {   
                    criteria.add($cup, 0);
                }
            }                     
         }
         #elseif ($col.isBooleanChar())
        // check for conversion from boolean to Y/N
        if ( criteria.containsKey($cup) )
        {
            Object possibleBoolean = criteria.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    criteria.add($cup, "Y");
                }
                else
                {   
                    criteria.add($cup, "N");
                }
            }                     
         }
         #end
     #end
         BasePeer.doDelete ( criteria, dbCon );
     }

    /** Method to do inserts */
    public static void doInsert( $table.JavaName obj ) throws Exception
    {
        #if ($table.IdMethod.equals("none"))
        doInsert(buildCriteria(obj));
        #else
        obj.setPrimaryKey(doInsert(buildCriteria(obj)));
        #end
        obj.setNew(false);
    }

    /**
     * @@param obj the data object to update in the database.
     */
    public static void doUpdate($table.JavaName obj) throws Exception
    {
        doUpdate(buildCriteria(obj));
    }
    /**
     * @@param obj the data object to delete in the database.
     */
    public static void doDelete($table.JavaName obj) throws Exception
    {
        doDelete(buildCriteria(obj));
    }

    /** 
     * Method to do inserts.  This method is to be used during a transaction,
     * otherwise use the doInsert($table.JavaName) method.  It will take 
     * care of the connection details internally. 
     *
     * @@param obj the data object to insert into the database.
     */
    public static void doInsert( $table.JavaName obj, DBConnection dbCon) throws Exception
    {
        #if ($table.IdMethod.equals("none"))
        doInsert(buildCriteria(obj), dbCon);
        #else
        obj.setPrimaryKey(doInsert(buildCriteria(obj), dbCon));
        #end
        obj.setNew(false);
    }

    /**
     * Method to do update.  This method is to be used during a transaction,
     * otherwise use the doUpdate($table.JavaName) method.  It will take 
     * care of the connection details internally. 
     *
     * @@param obj the data object to update in the database.
     */
    public static void doUpdate($table.JavaName obj, DBConnection dbCon) throws Exception
    {
        doUpdate(buildCriteria(obj), dbCon);
    }
    /**
     * Method to delete.  This method is to be used during a transaction,
     * otherwise use the doDelete($table.JavaName) method.  It will take 
     * care of the connection details internally. 
     *
     * @@param obj the data object to delete in the database.
     */
    public static void doDelete($table.JavaName obj, DBConnection dbCon) throws Exception
    {
        doDelete(buildCriteria(obj), dbCon);
    }

    /** Build a Criteria object from the data object for this peer */
    public static Criteria buildCriteria( $table.JavaName obj )
    {
        Criteria criteria = new Criteria();
        #foreach ($col in $table.Columns)
            #set ( $cfc=$col.JavaName )
            #set ( $cup=$col.Name.toUpperCase() )
            #if ($col.isPrimaryKey() && !$table.IdMethod.equals("none"))
        if ( !obj.isNew() )
    	    #end
            criteria.add( $cup, obj.get${cfc}() );
        #end
        return criteria;
    }

    /** 
     * Retrieve a single object by pk
     *
     * @@param ObjectKey pk
     */
    public static $table.JavaName retrieveByPK( ObjectKey pk )
        throws Exception
    {
        Criteria criteria = new Criteria();
#if ($table.PrimaryKeys.size() == 1)
            criteria.add( $table.PrimaryKeys.get(0).Name.toUpperCase(), pk );
#else
        SimpleKey[] keys = (SimpleKey[])pk.getValue();
    #set ( $i = 0 )
    #foreach ($col in $table.PrimaryKeys)
        #set ( $cup=$col.Name.toUpperCase() )
            criteria.add( $cup, keys[$i] );
        #set ( $i = $i + 1 )
    #end
#end
        Vector v = doSelect(criteria);
        if ( v.size() != 1)
        {
            throw new Exception("Failed to select one and only one row.");
        }
        else
        {
            return ($table.JavaName)v.firstElement();
        }
    }


#if ($table.PrimaryKeys.size() > 1)
#set ( $comma = false )
    /** 
     * retrieve object using using pk values.
     *
#foreach ($col in $table.PrimaryKeys)
    #set ( $clo=$col.Name.toLowerCase() )
    #set ( $cjtype= $col.JavaNative )
     * @@param $cjtype $clo
#end
     */
    public static $table.JavaName retrieveByPK(
#foreach ($col in $table.PrimaryKeys)
    #set ( $clo=$col.Name.toLowerCase() )
    #set ( $cjtype = $col.JavaNative )
    #if ($comma),#end $cjtype $clo
        #set ( $comma = true )
#end
        ) throws Exception
    {
        Criteria criteria = new Criteria(5);
#foreach ($col in $table.PrimaryKeys)
    #set ( $cup=$col.Name.toUpperCase() )
    #set ( $clo=$col.Name.toLowerCase() )
        criteria.add( $cup, $clo );
#end
        Vector v = doSelect(criteria);
        if ( v.size() != 1)
        {
            throw new Exception("Failed to select one and only one row.");
        }
        else
        {
            return ($table.JavaName) v.firstElement();
        }
    }
#end


#if ($complexOM)

 ## 
 ## setup joins
 ##
 #set ( $className = $table.JavaName ) 
 #set ( $countFK = 0 )  
 #foreach ($dummyFK in $table.ForeignKeys)
      #set ( $countFK = $countFK + 1 )
 #end

 #if ($countFK >= 1)
 #foreach ($fk in $table.ForeignKeys)
   ## want to cover this case, but the code is not there yet.
   #if ( !($fk.ForeignTableName.equals($table.Name)) )

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

     #set ( $joinTable = $table.Database.getTable($fk.ForeignTableName) )
     #set ( $joinClassName = $joinTable.JavaName )

     #if ($partJoinName == "")
        #set ( $joinColumnId = $joinClassName )
        #set ( $collThisTable = $strings.concat([$className, "s"]) )
     #else
        #set ( $joinColumnId=$strings.concat([$joinClassName,"RelatedBy",$partJoinName]) )
        #set ( $collThisTable=$strings.concat([$className,"sRelatedBy",$partJoinName]) )
     #end


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

   /**
    * selects a collection of $className objects pre-filled with their
    * $joinClassName objects.
    */
    public static Vector doSelectJoin${joinColumnId}(Criteria c)
        throws Exception
    {
         c.setDbName(mapBuilder.getDatabaseMap().getName());

        addSelectColumns(c);
        int offset = numColumns + 1;
        ${joinClassName}Peer.addSelectColumns(c);

     #foreach ($col in $table.Columns)
         #set ( $cup=$col.Name.toUpperCase() )
         #if($col.isBooleanInt())
        // check for conversion from boolean to int
        if ( c.containsKey($cup) )
        {
            Object possibleBoolean = c.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    c.add($cup, 1);
                }
                else
                {   
                    c.add($cup, 0);
                }
            }                     
         }
         #elseif ($col.isBooleanChar())
        // check for conversion from boolean to Y/N
        if ( c.containsKey($cup) )
        {
            Object possibleBoolean = c.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    c.add($cup, "Y");
                }
                else
                {   
                    c.add($cup, "N");
                }
            }                     
         }
         #end
     #end
        
        Vector rows = BasePeer.doSelect(c);
        Vector results = new Vector();

        for (int i=0; i<rows.size(); i++)
        {
            Record row = (Record)rows.elementAt(i);

#set ($classDecl = "Class")
#if ($table.ChildrenColumn)
    #set ($col = $table.ChildrenColumn)
            $classDecl omClass = ${table.JavaName}Peer.getOMClass(row, 1);
            #set ($classDecl = "")
            $className obj1 = ${table.JavaName}Peer
                .row2Object( row, 1, omClass);
#else
            $className obj1 = ${table.JavaName}Peer
                .row2Object( row,1, CLASS_DEFAULT );
#end


#if ($joinTable.ChildrenColumn)
    #set ($col = $joinTable.ChildrenColumn)
            $classDecl omClass = ${joinClassName}Peer.getOMClass(row, offset);
    #set ($classDecl = "")
   
            $joinClassName obj2 = ${joinClassName}Peer
                .row2Object(row, offset, omClass);
#else
            $joinClassName obj2 = ${joinClassName}Peer
                .row2Object(row, offset, 
                    ${joinClassName}Peer.CLASS_DEFAULT);
#end
            
            boolean newObject = true;
            for (int j=0; j<results.size(); j++)
            {
                $className temp_obj1 = ($className)results.elementAt(j);
                $joinClassName temp_obj2 = temp_obj1.get${joinColumnId}();
                if ( temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey() ) )
                {
                    newObject = false;
                    temp_obj2.add${collThisTable}(obj1);
                    break;
                }
            }
            if (newObject)
            {
                obj2.init${collThisTable}();
                obj2.add${collThisTable}(obj1);
            }
            results.add(obj1);

        }

        return results;
    }
  #end
 #end 
 #end 

## ===========================================================

  #if ($countFK > 2)

  #foreach ($fk in $table.ForeignKeys)

     #set ( $excludeTable = $table.Database.getTable($fk.ForeignTableName) )
     #set ( $excludeClassName = $excludeTable.JavaName )

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

     #if ($relatedByCol == "")
        #set ( $excludeString = $excludeClassName )
        #set ( $collThisTable = $strings.concat([$className, "s"]) )
     #else
        #set ( $excludeString=$strings.concat([$excludeClassName,"RelatedBy",$relatedByCol]) )
        #set ( $collThisTable=$strings.concat([$className,"sRelatedBy",$relatedByCol]) )
     #end



   /**
    * selects a collection of $className objects pre-filled with 
    * all related objects.
    */
    public static Vector doSelectJoinAllExcept${excludeString}(Criteria c) 
        throws Exception
    {
         c.setDbName(mapBuilder.getDatabaseMap().getName());

        addSelectColumns(c);
        int offset2 = numColumns + 1;
    #set ( $index = 2 )
    #foreach ($fk in $table.ForeignKeys)
      ## want to cover this case, but the code is not there yet.
      #if ( !($fk.ForeignTableName.equals($table.Name)) )
        #set ( $joinTable = $table.Database.getTable($fk.ForeignTableName) )
        #set ( $joinClassName = $joinTable.JavaName )

        #if ( $joinClassName.equals($excludeClassName) )
        #else
            #set ( $new_index = $index + 1 )
        ${joinClassName}Peer.addSelectColumns(c);
        int offset$new_index = offset$index + ${joinClassName}Peer.numColumns;
            #set ( $index = $new_index )
        #end
      #end
    #end
     #foreach ($col in $table.Columns)
         #set ( $cup=$col.Name.toUpperCase() )
         #if($col.isBooleanInt())
        // check for conversion from boolean to int
        if ( c.containsKey($cup) )
        {
            Object possibleBoolean = c.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    c.add($cup, 1);
                }
                else
                {   
                    c.add($cup, 0);
                }
            }                     
         }
         #elseif ($col.isBooleanChar())
        // check for conversion from boolean to Y/N
        if ( c.containsKey($cup) )
        {
            Object possibleBoolean = c.get($cup);
            if ( possibleBoolean instanceof Boolean )
            {
                if ( ((Boolean)possibleBoolean).booleanValue() )
                {
                    c.add($cup, "Y");
                }
                else
                {   
                    c.add($cup, "N");
                }
            }                     
         }
         #end
     #end

        Vector rows = BasePeer.doSelect(c);
        Vector results = new Vector();

        for (int i=0; i<rows.size(); i++)
        {
            Record row = (Record)rows.elementAt(i);


  #set ($classDecl = "Class")
  #if ($table.ChildrenColumn)
    #set ($col = $table.ChildrenColumn)
            $classDecl omClass = ${table.JavaName}Peer.getOMClass(row, 1);
            #set ($classDecl = "")
            $className obj1 = ${table.JavaName}Peer
                .row2Object( row, 1, omClass);
  #else
            $className obj1 = ${table.JavaName}Peer
                .row2Object( row,1, CLASS_DEFAULT );
  #end

    #set ( $index = 1 )
    #foreach ($fk in $table.ForeignKeys)
      ## want to cover this case, but the code is not there yet.
      #if ( !($fk.ForeignTableName.equals($table.Name)) )
        #set ( $joinTable = $table.Database.getTable($fk.ForeignTableName) )
        #set ( $joinClassName = $joinTable.JavaName )

        #if ( $joinClassName.equals($excludeClassName) )
        #else
            #set ( $partJoinName = "" )
            #foreach ($columnName in $fk.LocalColumns)
                #set ( $column = $table.getColumn($columnName) )
                #if ($column.isMultipleFK())
                    #set ( $partJoinName=$strings.concat([$partJoinName,$column.JavaName]) )
                #end
            #end

            #if ($partJoinName == "")
                #set ( $joinString = $joinClassName )
                #set ( $collThisTable = $strings.concat([$className, "s"]) )
            #else
                #set ( $joinString=$strings.concat([$joinClassName,"RelatedBy",$partJoinName]) )
                #set ( $collThisTable=$strings.concat([$className,"sRelatedBy",$partJoinName]) )
            #end

            #set ( $index = $index + 1 )


#if ($joinTable.ChildrenColumn)
    #set ($col = $joinTable.ChildrenColumn)
            $classDecl omClass = ${joinClassName}Peer.getOMClass(row, offset$index);
            #set ($classDecl = "")
            $joinClassName obj$index = ${joinClassName}Peer
                .row2Object( row, offset$index, omClass);
#else
            $joinClassName obj$index = ${joinClassName}Peer
                .row2Object(row, offset$index, 
                    ${joinClassName}Peer.CLASS_DEFAULT);
#end
            
            #if ($index == 2) boolean #end newObject = true;
            for (int j=0; j<results.size(); j++)    
            {
                $className temp_obj1 = ($className)results.elementAt(j);
                $joinClassName temp_obj$index = temp_obj1.get${joinString}();
                if ( temp_obj${index}.getPrimaryKey().equals(obj${index}.getPrimaryKey() ) )
                {
                    newObject = false;
                    temp_obj${index}.add${collThisTable}(obj1);
                    break;
                }
            }
            if (newObject)
            {
                obj${index}.init${collThisTable}();
                obj${index}.add${collThisTable}(obj1);
            }
      #end
    #end
  #end
            results.add(obj1);

        }

        return results;
    }
 #end
 #end  

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

#*
## #if ($table.ForeignKeys.length > 1)
#foreach ($col in $table.Columns)
  #if ($col.isForeignKey())
    #set ( $tmp = $col.RelatedTableName )
    #set ( $tblFK = $table.Database.getTable($tmp) )
    #set ( $colFK = $tblFK.getColumn($col.RelatedColumnName) ) 
    #set ( $clo=$col.Name.toLowerCase() )
    #set ( $cjtype=$col.JavaNative )

    /** 
     * Retrieve objects by fk
     *
     * @@param $cjtype $clo
     */
//    public static Vector retrieveBy${col.JavaName}($cjtype $clo)
//    {
        
  #end
#end
## #end
*#

#end

}

@


1.4
log
@commit some changes from turbine, by John McNally : prefix calls to
row2Object with the (non-Base) peer name so that peers can override
row2Object with a more efficient implementation.

i left out some changes related to renaming variables : defaultPackage ->
targetPackage and complexOM -> complexObjectModel
@
text
@@


1.3
log
@Updating for latest Torque
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d422 1
a422 1
            results.add(row2Object(row, 1,
d425 2
a426 1
            results.add(row2Object( row,1, CLASS_DEFAULT ));
d938 2
a939 1
            $className obj1 = row2Object( row, 1, omClass);
d941 2
a942 1
            $className obj1 = row2Object( row,1, CLASS_DEFAULT );
d1092 2
a1093 1
            $className obj1 = row2Object( row, 1, omClass);
d1095 2
a1096 1
            $className obj1 = row2Object( row,1, CLASS_DEFAULT );
@


1.3.6.1
log
@change so that it's possible to use a more efficient row2Object when you
select a list of mailing lists: now we avoid calling methods which would
cause unnecessary RMI connections when viewing a list of mailing lists.
@
text
@d422 1
a422 1
            results.add(${table.JavaName}Peer.row2Object(row, 1,
d425 1
a425 2
            results.add(${table.JavaName}Peer
                .row2Object( row,1, CLASS_DEFAULT ));
d937 1
a937 2
            $className obj1 = ${table.JavaName}Peer
                .row2Object( row, 1, omClass);
d939 1
a939 2
            $className obj1 = ${table.JavaName}Peer
                .row2Object( row,1, CLASS_DEFAULT );
d1089 1
a1089 2
            $className obj1 = ${table.JavaName}Peer
                .row2Object( row, 1, omClass);
d1091 1
a1091 2
            $className obj1 = ${table.JavaName}Peer
                .row2Object( row,1, CLASS_DEFAULT );
@


1.2
log
@Latest turbine templates
@
text
@d7 1
a7 1
package ${package}.base;
a26 2
import ${package}.peer.*;
import ${package}.*;
d29 1
a29 1
    #set ($extendsBasePeer = "extends $db.BaseClass" )
d40 1
a40 1
public abstract class ${table.BaseJavaName}Peer $extendsBasePeer
@


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
@d297 4
a300 1
     * This method handles connections internally 
d855 1
a855 1
            #set ( $partJoinName=$tstrings.concat([$partJoinName,$column.JavaName]) )
d857 1
a857 1
            #set ( $partJoinName=$tstrings.concat([$partJoinName,$column.JavaName]) )
d866 1
a866 1
        #set ( $collThisTable = $tstrings.concat([$className, "s"]) )
d868 2
a869 2
        #set ( $joinColumnId=$tstrings.concat([$joinClassName,"RelatedBy",$partJoinName]) )
        #set ( $collThisTable=$tstrings.concat([$className,"sRelatedBy",$partJoinName]) )
d998 1
a998 1
            #set ($relatedByCol=$tstrings.concat([$relatedByCol,$column.JavaName]))
d1004 1
a1004 1
        #set ( $collThisTable = $tstrings.concat([$className, "s"]) )
d1006 2
a1007 2
        #set ( $excludeString=$tstrings.concat([$excludeClassName,"RelatedBy",$relatedByCol]) )
        #set ( $collThisTable=$tstrings.concat([$className,"sRelatedBy",$relatedByCol]) )
d1109 1
a1109 1
                    #set ( $partJoinName=$tstrings.concat([$partJoinName,$column.JavaName]) )
d1115 1
a1115 1
                #set ( $collThisTable = $tstrings.concat([$className, "s"]) )
d1117 2
a1118 2
                #set ( $joinString=$tstrings.concat([$joinClassName,"RelatedBy",$partJoinName]) )
                #set ( $collThisTable=$tstrings.concat([$className,"sRelatedBy",$partJoinName]) )
@

