You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by dl...@apache.org on 2001/08/17 23:42:29 UTC

cvs commit: jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model Unique.java

dlr         01/08/17 14:42:29

  Modified:    src/java/org/apache/torque/engine/database/model Unique.java
  Log:
  Most of the implementation for this Unique index class is the same as
  for Index, so we now subclass.
  
  Revision  Changes    Path
  1.2       +20 -63    jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Unique.java
  
  Index: Unique.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Unique.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- Unique.java	2001/08/02 05:08:32	1.1
  +++ Unique.java	2001/08/17 21:42:29	1.2
  @@ -59,98 +59,55 @@
   import org.xml.sax.Attributes;
   
   /**
  - * A Class for information about unique indices of a table
  + * Information about unique indices of a table.
    *
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: Unique.java,v 1.1 2001/08/02 05:08:32 jvanzyl Exp $
  + * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
  + * @version $Id: Unique.java,v 1.2 2001/08/17 21:42:29 dlr Exp $
    */
  -public class Unique
  +public class Unique extends Index
   {
  -    private String indexName;
  -    private Table parentTable;
  -    private List indexColumns = new ArrayList(3);
  -
       /**
  -     * Default Constructor
  +     * Creates a new, unique <code>Index</code> instance.
        */
       public Unique()
       {
       }
   
  -    /**
  -     * Set the parent Table of the foreign key
  -     */
  -    public void setTable(Table parent)
  -    {
  -        parentTable = parent;
  -    }
  -
  -    /**
  -     * Get the parent Table of the foreign key
  -     */
  -    public Table getTable()
  -    {
  -        return parentTable;
  -    }
  -
       /**
  -     * Returns the Name of the table the foreign key is in
  +     * @see org.apache.torque.engine.database.model.Index#Index(List indexColumns)
        */
  -    public String getTableName()
  +    public Unique(List indexColumns)
       {
  -        return parentTable.getName();
  +        super(indexColumns);
       }
   
       /**
  -     *  adds a new column to an index
  +     * Returns <code>true</code>.
        */
  -    public void addColumn(Attributes attrib)
  +    public final boolean getUnique()
       {
  -        indexColumns.add(attrib.getValue("name"));
  +        return true;
       }
   
       /**
  -     * Creates a list of columns delimited by commas
  -     */
  -    private String makeColumnList(List cols)
  -    {
  -        StringBuffer res = new StringBuffer(cols.get(0).toString());
  -        for (int i=1; i < cols.size(); i++)
  -            res.append(", ")
  -                .append(cols.get(i).toString());
  -        return res.toString();
  -    }
  -
  -    /**
  -     * Return a comma delimited string of the index columns
  -     */
  -    public String getColumnList()
  -    {
  -        return makeColumnList(indexColumns);
  -    }
  -
  -    /**
  -     * Return the vector of local columns.  You should not edit
  -     * this vector.
  -     */
  -    public List getIndexColumns()
  -    {
  -        return indexColumns;
  -    }
  -
  -    /**
        * String representation of the index. This
        * is an xml representation.
        */
       public String toString()
       {
           StringBuffer result = new StringBuffer();
  -        result.append(" <unique>\n");
  -
  -        for (int i=0; i<indexColumns.size(); i++)
  +        result.append(" <unique name=\"")
  +            .append(getName())
  +            .append("\">\n");
  +
  +        List columns = getColumns();
  +        for (int i = 0; i < columns.size(); i++)
  +        {
               result.append("  <unique-column name=\"")
  -                .append(indexColumns.get(i))
  +                .append(columns.get(i))
                   .append("\"/>\n");
  +        }
           result.append(" </unique>\n");
           return result.toString();
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org