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

                  
        /**
         * The value for the id field
         */
        private Integer id;
              
        /**
         * The value for the organization_type_id field
         */
        private Integer organization_type_id;
              
        /**
         * The value for the organization_data_id field
         */
        private Integer organization_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 OrganizationTypeId
         *
         * @return Integer
         */
        public Integer getOrganizationTypeId()
        {
            return organization_type_id;
        }

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


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

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


        /**
         * Get the OrganizationDataId
         *
         * @return Integer
         */
        public Integer getOrganizationDataId()
        {
            return organization_data_id;
        }

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


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

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

    /**
     * Declares an association between this object and a OrganizationData object
     *
     * @param v OrganizationData
     * @throws TorqueException
     */
    public void setOrganizationData(OrganizationData v) throws TorqueException
    {
           if (v == null)
        {
                         setOrganizationDataId((Integer)null);
                    }
        else
        {
            setOrganizationDataId(v.getId());
        }
           aOrganizationData = v;
    }

                 
    /**
     * Get the associated OrganizationData object
     *
     * @return the associated OrganizationData object
     * @throws TorqueException
     */
    public OrganizationData getOrganizationData() throws TorqueException
    {
        if (aOrganizationData == null && (!ObjectUtils.equals(this.organization_data_id, null)))
        {
              aOrganizationData = OrganizationDataPeer.retrieveByPK(SimpleKey.keyFor(this.organization_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.
               OrganizationData obj = OrganizationDataPeer.retrieveByPK(this.organization_data_id);
               obj.addOrganizationOrganizationTypes(this);
             */
        }
        return aOrganizationData;
    }

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

    /**
     * Declares an association between this object and a OrganizationType object
     *
     * @param v OrganizationType
     * @throws TorqueException
     */
    public void setOrganizationType(OrganizationType v) throws TorqueException
    {
           if (v == null)
        {
                         setOrganizationTypeId((Integer)null);
                    }
        else
        {
            setOrganizationTypeId(v.getId());
        }
           aOrganizationType = v;
    }

                 
    /**
     * Get the associated OrganizationType object
     *
     * @return the associated OrganizationType object
     * @throws TorqueException
     */
    public OrganizationType getOrganizationType() throws TorqueException
    {
        if (aOrganizationType == null && (!ObjectUtils.equals(this.organization_type_id, null)))
        {
              aOrganizationType = OrganizationTypePeer.retrieveByPK(SimpleKey.keyFor(this.organization_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.
               OrganizationType obj = OrganizationTypePeer.retrieveByPK(this.organization_type_id);
               obj.addOrganizationOrganizationTypes(this);
             */
        }
        return aOrganizationType;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setOrganizationTypeKey(ObjectKey key) throws TorqueException
    {
    
                                        setOrganizationTypeId(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("OrganizationTypeId");
            fieldNames.add("OrganizationDataId");
            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("OrganizationTypeId"))
    {
              return getOrganizationTypeId();
          }
            if (name.equals("OrganizationDataId"))
    {
              return getOrganizationDataId();
          }
            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(OrganizationOrganizationTypePeer.ID))
        {
              return getId();
          }
            if (name.equals(OrganizationOrganizationTypePeer.ORGANIZATION_TYPE_ID))
        {
              return getOrganizationTypeId();
          }
            if (name.equals(OrganizationOrganizationTypePeer.ORGANIZATION_DATA_ID))
        {
              return getOrganizationDataId();
          }
            if (name.equals(OrganizationOrganizationTypePeer.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 getOrganizationTypeId();
          }
            if (pos == 2)
    {
              return getOrganizationDataId();
          }
            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(OrganizationOrganizationTypePeer.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())
            {
                OrganizationOrganizationTypePeer.doInsert((OrganizationOrganizationType) this, con);
                setNew(false);
            }
            else
            {
                OrganizationOrganizationTypePeer.doUpdate((OrganizationOrganizationType) 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 OrganizationOrganizationType copy() throws TorqueException
    {
        return copyInto(new OrganizationOrganizationType());
    }

    protected OrganizationOrganizationType copyInto(OrganizationOrganizationType copyObj) throws TorqueException
    {
        copyObj.setId(id);
        copyObj.setOrganizationTypeId(organization_type_id);
        copyObj.setOrganizationDataId(organization_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 OrganizationOrganizationTypePeer getPeer()
    {
        return peer;
    }
}
