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

                  
        /**
         * The value for the id field
         */
        private Integer id;
              
        /**
         * The value for the member_id field
         */
        private Integer member_id;
              
        /**
         * The value for the document_type_id field
         */
        private Integer document_type_id;
              
        /**
         * The value for the content_type field
         */
        private String content_type;
              
        /**
         * The value for the path field
         */
        private String path;
              
        /**
         * The value for the filename field
         */
        private String filename;
              
        /**
         * The value for the label field
         */
        private String label;
      
      
        /**
         * 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 MemberId
         *
         * @return Integer
         */
        public Integer getMemberId()
        {
            return member_id;
        }

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


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

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


        /**
         * Get the DocumentTypeId
         *
         * @return Integer
         */
        public Integer getDocumentTypeId()
        {
            return document_type_id;
        }

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


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

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


        /**
         * Get the ContentType
         *
         * @return String
         */
        public String getContentType()
        {
            return content_type;
        }

                                            
        /**
         * Set the value of ContentType
         *
         * @param v new value
         */
        public void setContentType(String v) 
        {
          


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

                  
                       }


        /**
         * Get the Path
         *
         * @return String
         */
        public String getPath()
        {
            return path;
        }

                                            
        /**
         * Set the value of Path
         *
         * @param v new value
         */
        public void setPath(String v) 
        {
          


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

                  
                       }


        /**
         * Get the Filename
         *
         * @return String
         */
        public String getFilename()
        {
            return filename;
        }

                                            
        /**
         * Set the value of Filename
         *
         * @param v new value
         */
        public void setFilename(String v) 
        {
          


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

                  
                       }


        /**
         * Get the Label
         *
         * @return String
         */
        public String getLabel()
        {
            return label;
        }

                                            
        /**
         * Set the value of Label
         *
         * @param v new value
         */
        public void setLabel(String v) 
        {
          


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

                  
                       }


 
     
   
             
   
       private Member aMember;

    /**
     * Declares an association between this object and a Member object
     *
     * @param v Member
     * @throws TorqueException
     */
    public void setMember(Member v) throws TorqueException
    {
           if (v == null)
        {
                         setMemberId((Integer)null);
                    }
        else
        {
            setMemberId(v.getId());
        }
           aMember = v;
    }

                 
    /**
     * Get the associated Member object
     *
     * @return the associated Member object
     * @throws TorqueException
     */
    public Member getMember() throws TorqueException
    {
        if (aMember == null && (!ObjectUtils.equals(this.member_id, null)))
        {
              aMember = MemberPeer.retrieveByPK(SimpleKey.keyFor(this.member_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.
               Member obj = MemberPeer.retrieveByPK(this.member_id);
               obj.addDocuments(this);
             */
        }
        return aMember;
    }

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

    /**
     * Declares an association between this object and a DocumentType object
     *
     * @param v DocumentType
     * @throws TorqueException
     */
    public void setDocumentType(DocumentType v) throws TorqueException
    {
           if (v == null)
        {
                         setDocumentTypeId((Integer)null);
                    }
        else
        {
            setDocumentTypeId(v.getId());
        }
           aDocumentType = v;
    }

                 
    /**
     * Get the associated DocumentType object
     *
     * @return the associated DocumentType object
     * @throws TorqueException
     */
    public DocumentType getDocumentType() throws TorqueException
    {
        if (aDocumentType == null && (!ObjectUtils.equals(this.document_type_id, null)))
        {
              aDocumentType = DocumentTypePeer.retrieveByPK(SimpleKey.keyFor(this.document_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.
               DocumentType obj = DocumentTypePeer.retrieveByPK(this.document_type_id);
               obj.addDocuments(this);
             */
        }
        return aDocumentType;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey.  e.g.
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setDocumentTypeKey(ObjectKey key) throws TorqueException
    {
    
                                        setDocumentTypeId(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("MemberId");
            fieldNames.add("DocumentTypeId");
            fieldNames.add("ContentType");
            fieldNames.add("Path");
            fieldNames.add("Filename");
            fieldNames.add("Label");
            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("MemberId"))
    {
              return getMemberId();
          }
            if (name.equals("DocumentTypeId"))
    {
              return getDocumentTypeId();
          }
            if (name.equals("ContentType"))
    {
              return getContentType();
          }
            if (name.equals("Path"))
    {
              return getPath();
          }
            if (name.equals("Filename"))
    {
              return getFilename();
          }
            if (name.equals("Label"))
    {
              return getLabel();
          }
            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(DocumentPeer.ID))
        {
              return getId();
          }
            if (name.equals(DocumentPeer.MEMBER_ID))
        {
              return getMemberId();
          }
            if (name.equals(DocumentPeer.DOCUMENT_TYPE_ID))
        {
              return getDocumentTypeId();
          }
            if (name.equals(DocumentPeer.CONTENT_TYPE))
        {
              return getContentType();
          }
            if (name.equals(DocumentPeer.PATH))
        {
              return getPath();
          }
            if (name.equals(DocumentPeer.FILENAME))
        {
              return getFilename();
          }
            if (name.equals(DocumentPeer.LABEL))
        {
              return getLabel();
          }
            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 getMemberId();
          }
            if (pos == 2)
    {
              return getDocumentTypeId();
          }
            if (pos == 3)
    {
              return getContentType();
          }
            if (pos == 4)
    {
              return getPath();
          }
            if (pos == 5)
    {
              return getFilename();
          }
            if (pos == 6)
    {
              return getLabel();
          }
                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(DocumentPeer.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())
            {
                DocumentPeer.doInsert((Document) this, con);
                setNew(false);
            }
            else
            {
                DocumentPeer.doUpdate((Document) 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 Document copy() throws TorqueException
    {
        return copyInto(new Document());
    }

    protected Document copyInto(Document copyObj) throws TorqueException
    {
        copyObj.setId(id);
        copyObj.setMemberId(member_id);
        copyObj.setDocumentTypeId(document_type_id);
        copyObj.setContentType(content_type);
        copyObj.setPath(path);
        copyObj.setFilename(filename);
        copyObj.setLabel(label);

  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 DocumentPeer getPeer()
    {
        return peer;
    }
}
