package test.peer;



import com.workingdogs.village.*;
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 java.util.*;
import test.map.*;
import test.*;

/** This class was autogenerated by XMLSchemaToObjectModel on: Sun Aug 27 15:53:54 EDT 2000 */
public class IdTablePeer extends BasePeer
{
    /** the mapbuilder for this class */
    private static final IdTableMapBuilder mapBuilder = (IdTableMapBuilder)getMapBuilder(IdTableMapBuilder.CLASS_NAME);

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

    /** the column name for the ID_TABLE_ID id field */
    public static final String ID_TABLE_ID = mapBuilder.getIdTable_IdTableId();
    /** the column name for the QUANTITY id field */
    public static final String QUANTITY = mapBuilder.getIdTable_Quantity();
    /** the column name for the NEXT_ID id field */
    public static final String NEXT_ID = mapBuilder.getIdTable_NextId();
    /** the column name for the TABLE_NAME id field */
    public static final String TABLE_NAME = mapBuilder.getIdTable_TableName();

    /** Method to do inserts */ 
    public static Object doInsert( Criteria criteria ) throws Exception
    {
        return BasePeer.doInsert( criteria );
    }

    /** Method to do selects */ 
    public static Vector doSelect( Criteria criteria ) throws Exception
    {
        criteria.addSelectColumn( ID_TABLE_ID );
        criteria.addSelectColumn( QUANTITY );
        criteria.addSelectColumn( NEXT_ID );
        criteria.addSelectColumn( TABLE_NAME );

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

        // populate the object(s)
        for ( int i=0; i<rows.size(); i++ )
        {
           IdTable obj = new IdTable();
            Record row = (Record)rows.elementAt(i);
            obj.setIdTableId( row.getValue(1).asInt() );
            obj.setQuantity( row.getValue(2).asInt() );
            obj.setNextId( row.getValue(3).asInt() );
            obj.setTableName( row.getValue(4).asString() );
            results.addElement( obj );
         }
         return results;
    }

    /**
     * @param Criteria object containing data that is used to create the UPDATE statement.
     */
     public static void doUpdate(Criteria criteria) throws Exception
     {
         Criteria selectCriteria = new Criteria(2);
         selectCriteria.put( ID_TABLE_ID, criteria.remove(ID_TABLE_ID) );
         BasePeer.doUpdate( selectCriteria, criteria );
     }

    /**
     * @param Criteria object containing data that is used DELETE from database.
     */
     public static void doDelete(Criteria criteria) throws Exception
     {
         BasePeer.doDelete ( criteria );
     }

    /** Method to do inserts */
    public static Object doInsert( IdTable obj ) throws Exception
    {
        return IdTablePeer.doInsert(buildCriteria(obj));
    }

    /** Build a Criteria object from the data object for this peer */
    public static Criteria buildCriteria( IdTable obj )
    {
        Criteria criteria = new Criteria();
        if( obj.getIdTableId() > 0 )
            criteria.add( IdTablePeer.ID_TABLE_ID, obj.getIdTableId() );
        criteria.add( IdTablePeer.QUANTITY, obj.getQuantity() );
        criteria.add( IdTablePeer.NEXT_ID, obj.getNextId() );
        criteria.add( IdTablePeer.TABLE_NAME, obj.getTableName() );
        return criteria;
    }


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

}
