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 ResearchInterestCulturalArea
 */
public abstract class BaseResearchInterestCulturalArea extends BaseObject
{
    /** The Peer class */
    private static final ResearchInterestCulturalAreaPeer peer =
        new ResearchInterestCulturalAreaPeer();

                  
        /**
         * The value for the id field
         */
        private Integer id;
              
        /**
         * The value for the cultural_area_id field
         */
        private Integer cultural_area_id;
              
        /**
         * The value for the research_interest_id field
         */
        private Integer research_interest_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 CulturalAreaId
         *
         * @return Integer
         */
        public Integer getCulturalAreaId()
        {
            return cultural_area_id;
        }

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


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

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


        /**
         * Get the ResearchInterestId
         *
         * @return Integer
         */
        public Integer getResearchInterestId()
        {
            return research_interest_id;
        }

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


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

                                          
                if (aResearchInterest != null && !ObjectUtils.equals(aResearchInterest.getId(), v))
                {
            aResearchInterest = 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 ResearchInterest aResearchInterest;

    /**
     * Declares an association between this object and a ResearchInterest object
     *
     * @param v ResearchInterest
     * @throws TorqueException
     */
    public void setResearchInterest(ResearchInterest v) throws TorqueException
    {
           if (v == null)
        {
                         setResearchInterestId((Integer)null);
                    }
        else
        {
            setResearchInterestId(v.getId());
        }
           aResearchInterest = v;
    }

                 
    /**
     * Get the associated ResearchInterest object
     *
     * @return the associated ResearchInterest object
     * @throws TorqueException
     */
    public ResearchInterest getResearchInterest() throws TorqueException
    {
        if (aResearchInterest == null && (!ObjectUtils.equals(this.research_interest_id, null)))
        {
              aResearchInterest = ResearchInterestPeer.retrieveByPK(SimpleKey.keyFor(this.research_interest_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.
               ResearchInterest obj = ResearchInterestPeer.retrieveByPK(this.research_interest_id);
               obj.addResearchInterestCulturalAreas(this);
             */
        }
        return aResearchInterest;
    }

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

    /**
     * Declares an association between this object and a CulturalArea object
     *
     * @param v CulturalArea
     * @throws TorqueException
     */
    public void setCulturalArea(CulturalArea v) throws TorqueException
    {
           if (v == null)
        {
                         setCulturalAreaId((Integer)null);
                    }
        else
        {
            setCulturalAreaId(v.getId());
        }
           aCulturalArea = v;
    }

                 
    /**
     * Get the associated CulturalArea object
     *
     * @return the associated CulturalArea object
     * @throws TorqueException
     */
    public CulturalArea getCulturalArea() throws TorqueException
    {
        if (aCulturalArea == null && (!ObjectUtils.equals(this.cultural_area_id, null)))
        {
              aCulturalArea = CulturalAreaPeer.retrieveByPK(SimpleKey.keyFor(this.cultural_area_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.
               CulturalArea obj = CulturalAreaPeer.retrieveByPK(this.cultural_area_id);
               obj.addResearchInterestCulturalAreas(this);
             */
        }
        return aCulturalArea;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setCulturalAreaKey(ObjectKey key) throws TorqueException
    {
    
                                        setCulturalAreaId(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("CulturalAreaId");
            fieldNames.add("ResearchInterestId");
            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("CulturalAreaId"))
    {
              return getCulturalAreaId();
          }
            if (name.equals("ResearchInterestId"))
    {
              return getResearchInterestId();
          }
            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(ResearchInterestCulturalAreaPeer.ID))
        {
              return getId();
          }
            if (name.equals(ResearchInterestCulturalAreaPeer.CULTURAL_AREA_ID))
        {
              return getCulturalAreaId();
          }
            if (name.equals(ResearchInterestCulturalAreaPeer.RESEARCH_INTEREST_ID))
        {
              return getResearchInterestId();
          }
            if (name.equals(ResearchInterestCulturalAreaPeer.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 getCulturalAreaId();
          }
            if (pos == 2)
    {
              return getResearchInterestId();
          }
            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(ResearchInterestCulturalAreaPeer.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())
            {
                ResearchInterestCulturalAreaPeer.doInsert((ResearchInterestCulturalArea) this, con);
                setNew(false);
            }
            else
            {
                ResearchInterestCulturalAreaPeer.doUpdate((ResearchInterestCulturalArea) 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 ResearchInterestCulturalArea copy() throws TorqueException
    {
        return copyInto(new ResearchInterestCulturalArea());
    }

    protected ResearchInterestCulturalArea copyInto(ResearchInterestCulturalArea copyObj) throws TorqueException
    {
        copyObj.setId(id);
        copyObj.setCulturalAreaId(cultural_area_id);
        copyObj.setResearchInterestId(research_interest_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 ResearchInterestCulturalAreaPeer getPeer()
    {
        return peer;
    }
}
