head	1.2;
access;
symbols;
locks; strict;
comment	@# @;


1.2
date	2001.05.03.01.09.21;	author dlr;	state dead;
branches;
next	1.1;

1.1
date	2001.05.03.00.03.18;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.2
log
@BaseXxx classes should not be in CVS and should be blocked by the .cvsignore file.  I do not know how this got in.
@
text
@package org.tigris.helm.om;

        
// JDK classes
import java.util.*;
import java.math.*;

// Turbine classes
import org.apache.turbine.om.*;
import org.apache.turbine.om.peer.BasePeer;
import org.apache.turbine.util.db.Criteria;
import org.apache.turbine.util.ObjectUtils;
import org.apache.turbine.util.StringUtils;
import org.apache.turbine.util.ParameterParser;
import org.apache.turbine.util.Log;
import org.apache.turbine.util.db.pool.DBConnection;

/** 
 * This class was autogenerated by Torque on:
 *
 * [Wed May 02 17:07:44 GMT-07:00 2001]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to Attribute 
 */
public abstract class BaseAttribute extends org.tigris.helm.om.HelmObject
{
        /** the value for the attribute_id field */
    private NumberKey attribute_id;
        /** the value for the type_id field */
    private NumberKey type_id;
        /** the value for the entity_type field */
    private String entity_type;
        /** the value for the name field */
    private String name;
                            /** the value for the default_value field */
    private String default_value="";
                            /** the value for the description field */
    private String description="";


    /**
     * Get the AttributeId
     * @@return NumberKey
     */
     public NumberKey getAttributeId()
     {
          return attribute_id;
     }

                            
    /**
     * Set the value of AttributeId
     */
     public void setAttributeId(NumberKey v ) throws Exception
     {
  
       
        
                
          // update associated AttributeValue
          if (collAttributeValues != null )
          {
              for (int i=0; i<collAttributeValues.size(); i++)
              {
                  ((AttributeValue)collAttributeValues.get(i))
                      .setAttributeId(v);
              }
          }
       

         if ( !ObjectUtils.equals(this.attribute_id, v) )
        {
                       if (this.attribute_id == null)
            {
                NumberKey copyKey = new NumberKey(v);
                this.attribute_id = copyKey;
            }
            else
            {
                this.attribute_id.setValue(v);
            }
                      setModified(true);
        }
     }

     /**
    * Set the value of AttributeId as a string.
    */
    public void setAttributeId(String v ) throws Exception
    {
         setAttributeId(new NumberKey(v));
    }
  
    /**
     * Get the TypeId
     * @@return NumberKey
     */
     public NumberKey getTypeId()
     {
          return type_id;
     }

            
    /**
     * Set the value of TypeId
     */
     public void setTypeId(NumberKey v ) throws Exception
     {
              aAttributeType = null;
  
  

         if ( !ObjectUtils.equals(this.type_id, v) )
        {
                       if (this.type_id == null)
            {
                NumberKey copyKey = new NumberKey(v);
                this.type_id = copyKey;
            }
            else
            {
                this.type_id.setValue(v);
            }
                      setModified(true);
        }
     }

     /**
    * Set the value of TypeId as a string.
    */
    public void setTypeId(String v ) throws Exception
    {
         setTypeId(new NumberKey(v));
    }
  
    /**
     * Get the EntityType
     * @@return String
     */
     public String getEntityType()
     {
          return entity_type;
     }

        
    /**
     * Set the value of EntityType
     */
     public void setEntityType(String v ) 
     {
  
  

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

  
    /**
     * Get the Name
     * @@return String
     */
     public String getName()
     {
          return name;
     }

        
    /**
     * Set the value of Name
     */
     public void setName(String v ) 
     {
  
  

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

  
    /**
     * Get the DefaultValue
     * @@return String
     */
     public String getDefaultValue()
     {
          return default_value;
     }

        
    /**
     * Set the value of DefaultValue
     */
     public void setDefaultValue(String v ) 
     {
  
  

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

  
    /**
     * Get the Description
     * @@return String
     */
     public String getDescription()
     {
          return description;
     }

        
    /**
     * Set the value of Description
     */
     public void setDescription(String v ) 
     {
  
  

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

  

 
 
   
             
   
   
    /**
     * Declares an association between this object and a AttributeType object
     *
     * @@param AttributeType v
     */
    private AttributeType aAttributeType;
    public void setAttributeType(AttributeType v) throws Exception
    {
           setTypeId(v.getAttributeTypeId());
           aAttributeType = v;
    }

                     
    public AttributeType getAttributeType() throws Exception
    {
        if ( aAttributeType==null && (!ObjectUtils.equals(this.type_id, null)) )
        {
            aAttributeType = AttributeTypePeer.retrieveByPK(this.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.  
            // AttributeType obj = AttributeTypePeer.retrieveByPK(this.type_id);
            // obj.addAttributes(this);
        }
        return aAttributeType;
    }


    /**
     * Provides convenient way to set a relationship based on a 
     * ObjectKey.  e.g. 
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setAttributeTypeKey(ObjectKey key) throws Exception
    {
            setTypeId((NumberKey)key);        
        }

    
                
      
    /**
     * Collection to store aggregation of collAttributeValues
     */
    private Vector collAttributeValues;
    /**
     * Temporary storage of collAttributeValues to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
//    private Vector tempcollAttributeValues;

    public void initAttributeValues()
    {
        if (collAttributeValues == null)
            collAttributeValues = new Vector();
    }

    /**
     * Method called to associate a AttributeValue object to this object
     * through the AttributeValue foreign key attribute
     *
     * @@param AttributeValue l
     */
    public void addAttributeValues(AttributeValue l) throws Exception
    {
        /*
        if (collAttributeValues == null)
        {
            if (tempcollAttributeValues == null)
            {
                tempcollAttributeValues = new Vector();
            }
            tempcollAttributeValues.add(l);
        }
        else
        {
            collAttributeValues.add(l);
        }
        */
        getAttributeValues().add(l);
        l.setAttribute((Attribute)this);
    }

    /**
     * The criteria used to select the current contents of collAttributeValues
     */
    private Criteria lastAttributeValuesCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of 
     * getAttributeValues(new Criteria())
     */
    public Vector getAttributeValues() throws Exception
    {
        if (collAttributeValues == null)
        {
            collAttributeValues = getAttributeValues(new Criteria(10));
        }
        return collAttributeValues;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection. 
     * Otherwise if this Attribute is new, it will return
     * an empty collection; or if this Attribute has previously
     * been saved, it will retrieve related AttributeValues from storage.
     */
    public Vector getAttributeValues(Criteria criteria) throws Exception
    {
        if (collAttributeValues == null)
        {
            if ( isNew() ) 
            {
               collAttributeValues = new Vector();       
            } 
            else
            {
                   criteria.add(AttributeValuePeer.ATTRIBUTE_ID, getAttributeId() );               
                   collAttributeValues = AttributeValuePeer.doSelect(criteria);
            }
/*
            if (tempcollAttributeValues != null)
            {
                for (int i=0; i<tempcollAttributeValues.size(); i++)
                {
                    collAttributeValues.add(tempcollAttributeValues.get(i));
                }
                tempcollAttributeValues = null;
            }
*/
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            boolean newCriteria = true;
                   criteria.add(AttributeValuePeer.ATTRIBUTE_ID, getAttributeId() );               
               if ( !lastAttributeValuesCriteria.equals(criteria)  )
            {
                collAttributeValues = AttributeValuePeer.doSelect(criteria);  
            }
        }
        lastAttributeValuesCriteria = criteria; 

        return collAttributeValues;
    }
   

        
      
         
          
                    
                
        
        
      



     
    
    private static Vector fieldNames_ = null;

    /**
     * Generate a list of field names.
     */
    public static synchronized List getFieldNames()
    {
      if (fieldNames_ == null)
      {
        fieldNames_ = new Vector();
            fieldNames_.add("AttributeId");
            fieldNames_.add("TypeId");
            fieldNames_.add("EntityType");
            fieldNames_.add("Name");
            fieldNames_.add("DefaultValue");
            fieldNames_.add("Description");
          }
      return fieldNames_;
    }

    /**
     * Retrieves a field from the object by name passed in
     * as a String.
     */
    public Object getByName(String name)
    {
            if (name.equals("AttributeId"))
	{
	  	    return getAttributeId();
	  	}
            if (name.equals("TypeId"))
	{
	  	    return getTypeId();
	  	}
            if (name.equals("EntityType"))
	{
	  	    return getEntityType();
	  	}
            if (name.equals("Name"))
	{
	  	    return getName();
	  	}
            if (name.equals("DefaultValue"))
	{
	  	    return getDefaultValue();
	  	}
            if (name.equals("Description"))
	{
	  	    return getDescription();
	  	}
            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.
     */
    public Object getByPeerName(String name)
    {
            if (name.equals(AttributePeer.ATTRIBUTE_ID ))
	    {
	  	    return getAttributeId();
	  	}
            if (name.equals(AttributePeer.TYPE_ID ))
	    {
	  	    return getTypeId();
	  	}
            if (name.equals(AttributePeer.ENTITY_TYPE ))
	    {
	  	    return getEntityType();
	  	}
            if (name.equals(AttributePeer.NAME ))
	    {
	  	    return getName();
	  	}
            if (name.equals(AttributePeer.DEFAULT_VALUE ))
	    {
	  	    return getDefaultValue();
	  	}
            if (name.equals(AttributePeer.DESCRIPTION ))
	    {
	  	    return getDescription();
	  	}
            return null; 
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     */
    public Object getByPosition(int pos)
    {
            if ( pos == 0 )
	{
	  	    return getAttributeId();
	  	}
            if ( pos == 1 )
	{
	  	    return getTypeId();
	  	}
            if ( pos == 2 )
	{
	  	    return getEntityType();
	  	}
            if ( pos == 3 )
	{
	  	    return getName();
	  	}
            if ( pos == 4 )
	{
	  	    return getDefaultValue();
	  	}
            if ( pos == 5 )
	{
	  	    return getDescription();
	  	}
                return null; 
    }

     	

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     */
    public void save() throws Exception
    {
         DBConnection dbCon = null;
        try
        {
            dbCon = BasePeer.beginTransaction(
                AttributePeer.getMapBuilder()
                .getDatabaseMap().getName());
            save(dbCon);
        }
        catch(Exception e)
        {
            BasePeer.rollBackTransaction(dbCon);
            throw e;
        }
        BasePeer.commitTransaction(dbCon);

     }

      // 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
     */
    public void save(DBConnection dbCon) throws Exception
    {
        if (!alreadyInSave)
      {
        alreadyInSave = true;
          if (isModified())
        {
            if (isNew())
            {
                AttributePeer.doInsert((Attribute)this, dbCon);
            }
            else
            {
                AttributePeer.doUpdate((Attribute)this, dbCon);
                setNew(false);
            }
        }

                                    
                
          if (collAttributeValues != null )
          {
              for (int i=0; i<collAttributeValues.size(); i++)
              {
                  ((AttributeValue)collAttributeValues.get(i)).save(dbCon);
              }
          }
                  alreadyInSave = false;
      }
      }

                        
    
    

        /** 
     * Set the PrimaryKey using ObjectKey.
     *
     * @@param ObjectKey attribute_id
     */
    public void setPrimaryKey(ObjectKey attribute_id) 
        throws Exception {
         setAttributeId((NumberKey)attribute_id);
    }

    /** 
     * Set the PrimaryKey using a String.
     */
    public void setPrimaryKey(String key) throws Exception
    {
        setAttributeId(new NumberKey(key) );
    }



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

    /**
     * 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 Attribute copyInto(Attribute copyObj) throws Exception
    {
        copyObj.setAttributeId(attribute_id);
        copyObj.setTypeId(type_id);
        copyObj.setEntityType(entity_type);
        copyObj.setName(name);
        copyObj.setDefaultValue(default_value);
        copyObj.setDescription(description);

                                
                
         List v = copyObj.getAttributeValues();
         for (int i=0; i<v.size(); i++)
         {
             ((Persistent)v.get(i)).setNew(true);
         }
            
            copyObj.setAttributeId((NumberKey)null);
                                return copyObj;
    }
}
@


1.1
log
@New Torque-generated extension classes.
@
text
@@

