package org.thdl.roster.om;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.Collections;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;

   
      
   
/**
 * This class was autogenerated by Torque on:
 *
 * [Wed May 14 19:01:42 EDT 2003]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to PersonPersonType
 */
public abstract class BasePersonPersonType extends BaseObject
{
    /** The Peer class */
    private static final PersonPersonTypePeer peer =
        new PersonPersonTypePeer();

                  
        /**
         * The value for the id field
         */
        private Integer id;
              
        /**
         * The value for the person_type_id field
         */
        private Integer person_type_id;
              
        /**
         * The value for the person_data_id field
         */
        private Integer person_data_id;
              
        /**
         * The value for the relevance field
         */
        private Integer relevance;
      
      
        /**
         * Get the Id
         *
         * @return Integer
         */
        public Integer getId()
        {
            return id;
        }

                                            
        /**
         * Set the value of Id
         *
         * @param v new value
         */
        public void setId(Integer v) 
        {
          


         if (!ObjectUtils.equals(this.id, v))
        {
             this.id = v;
            setModified(true);
        }

                  
                       }


        /**
         * Get the PersonTypeId
         *
         * @return Integer
         */
        public Integer getPersonTypeId()
        {
            return person_type_id;
        }

                                                      
        /**
         * Set the value of PersonTypeId
         *
         * @param v new value
         */
        public void setPersonTypeId(Integer v) throws TorqueException
        {
          


         if (!ObjectUtils.equals(this.person_type_id, v))
        {
             this.person_type_id = v;
            setModified(true);
        }

                                          
                if (aPersonType != null && !ObjectUtils.equals(aPersonType.getId(), v))
                {
            aPersonType = null;
        }
          
                       }


        /**
         * Get the PersonDataId
         *
         * @return Integer
         */
        public Integer getPersonDataId()
        {
            return person_data_id;
        }

                                                      
        /**
         * Set the value of PersonDataId
         *
         * @param v new value
         */
        public void setPersonDataId(Integer v) throws TorqueException
        {
          


         if (!ObjectUtils.equals(this.person_data_id, v))
        {
             this.person_data_id = v;
            setModified(true);
        }

                                          
                if (aPersonData != null && !ObjectUtils.equals(aPersonData.getId(), v))
                {
            aPersonData = null;
        }
          
                       }


        /**
         * Get the Relevance
         *
         * @return Integer
         */
        public Integer getRelevance()
        {
            return relevance;
        }

                                            
        /**
         * Set the value of Relevance
         *
         * @param v new value
         */
        public void setRelevance(Integer v) 
        {
          


         if (!ObjectUtils.equals(this.relevance, v))
        {
             this.relevance = v;
            setModified(true);
        }

                  
                       }


 
     
   
             
   
       private PersonData aPersonData;

    /**
     * Declares an association between this object and a PersonData object
     *
     * @param v PersonData
     * @throws TorqueException
     */
    public void setPersonData(PersonData v) throws TorqueException
    {
           if (v == null)
        {
                         setPersonDataId((Integer)null);
                    }
        else
        {
            setPersonDataId(v.getId());
        }
           aPersonData = v;
    }

                 
    /**
     * Get the associated PersonData object
     *
     * @return the associated PersonData object
     * @throws TorqueException
     */
    public PersonData getPersonData() throws TorqueException
    {
        if (aPersonData == null && (!ObjectUtils.equals(this.person_data_id, null)))
        {
              aPersonData = PersonDataPeer.retrieveByPK(SimpleKey.keyFor(this.person_data_id));
      
            /* 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.
               PersonData obj = PersonDataPeer.retrieveByPK(this.person_data_id);
               obj.addPersonPersonTypes(this);
             */
        }
        return aPersonData;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setPersonDataKey(ObjectKey key) throws TorqueException
    {
    
                                        setPersonDataId(new Integer(((NumberKey) key).intValue()));
                    }
 
   
             
   
       private PersonType aPersonType;

    /**
     * Declares an association between this object and a PersonType object
     *
     * @param v PersonType
     * @throws TorqueException
     */
    public void setPersonType(PersonType v) throws TorqueException
    {
           if (v == null)
        {
                         setPersonTypeId((Integer)null);
                    }
        else
        {
            setPersonTypeId(v.getId());
        }
           aPersonType = v;
    }

                 
    /**
     * Get the associated PersonType object
     *
     * @return the associated PersonType object
     * @throws TorqueException
     */
    public PersonType getPersonType() throws TorqueException
    {
        if (aPersonType == null && (!ObjectUtils.equals(this.person_type_id, null)))
        {
              aPersonType = PersonTypePeer.retrieveByPK(SimpleKey.keyFor(this.person_type_id));
      
            /* 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.
               PersonType obj = PersonTypePeer.retrieveByPK(this.person_type_id);
               obj.addPersonPersonTypes(this);
             */
        }
        return aPersonType;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setPersonTypeKey(ObjectKey key) throws TorqueException
    {
    
                                        setPersonTypeId(new Integer(((NumberKey) key).intValue()));
                    }
    
        
    
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
      if (fieldNames == null)
      {
        fieldNames = new ArrayList();
            fieldNames.add("Id");
            fieldNames.add("PersonTypeId");
            fieldNames.add("PersonDataId");
            fieldNames.add("Relevance");
            fieldNames = Collections.unmodifiableList(fieldNames);
      }
      return fieldNames;
    }

    /**
     * Retrieves a field from the object by name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
            if (name.equals("Id"))
    {
              return getId();
          }
            if (name.equals("PersonTypeId"))
    {
              return getPersonTypeId();
          }
            if (name.equals("PersonDataId"))
    {
              return getPersonDataId();
          }
            if (name.equals("Relevance"))
    {
              return getRelevance();
          }
            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.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
            if (name.equals(PersonPersonTypePeer.ID))
        {
              return getId();
          }
            if (name.equals(PersonPersonTypePeer.PERSON_TYPE_ID))
        {
              return getPersonTypeId();
          }
            if (name.equals(PersonPersonTypePeer.PERSON_DATA_ID))
        {
              return getPersonDataId();
          }
            if (name.equals(PersonPersonTypePeer.RELEVANCE))
        {
              return getRelevance();
          }
            return null;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
            if (pos == 0)
    {
              return getId();
          }
            if (pos == 1)
    {
              return getPersonTypeId();
          }
            if (pos == 2)
    {
              return getPersonDataId();
          }
            if (pos == 3)
    {
              return getRelevance();
          }
                return null;
    }

     


    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
             save(PersonPersonTypePeer.getMapBuilder()
                .getDatabaseMap().getName());
     }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
     *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
         try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }

     }

      /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
      /**
     * 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
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
        if (!alreadyInSave)
      {
        alreadyInSave = true;



  
        // If this object has been modified, then save it to the database.
        if (isModified())
        {
            if (isNew())
            {
                PersonPersonTypePeer.doInsert((PersonPersonType) this, con);
                setNew(false);
            }
            else
            {
                PersonPersonTypePeer.doUpdate((PersonPersonType) this, con);
            }
        }

              alreadyInSave = false;
      }
      }


                
    
    

        /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param  id ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        
    {
                    setId(new Integer(((NumberKey) key).intValue()));
            }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) 
    {
                    setId(new Integer(key));
            }


    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
        return SimpleKey.keyFor(getId());
    }

 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     */
    public PersonPersonType copy() throws TorqueException
    {
        return copyInto(new PersonPersonType());
    }

    protected PersonPersonType copyInto(PersonPersonType copyObj) throws TorqueException
    {
        copyObj.setId(id);
        copyObj.setPersonTypeId(person_type_id);
        copyObj.setPersonDataId(person_data_id);
        copyObj.setRelevance(relevance);

  copyObj.setNew(false);
      copyObj.setNew(true);

                      copyObj.setId((Integer)null);
                                return copyObj;
    }

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public PersonPersonTypePeer getPeer()
    {
        return peer;
    }
}
