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/16 05:18:07 UTC

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

dlr         01/08/15 20:18:07

  Modified:    src/java/org/apache/torque/engine/database/model Index.java
  Log:
  Added new ctor to be used to do heavy indexing for primary keys, and
  removed the need for makeColumnList(List cols).
  
  Revision  Changes    Path
  1.2       +60 -18    jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Index.java
  
  Index: Index.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Index.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- Index.java	2001/08/02 05:08:31	1.1
  +++ Index.java	2001/08/16 03:18:07	1.2
  @@ -55,27 +55,73 @@
    */
   
   import java.util.ArrayList;
  +import java.util.Iterator;
   import java.util.List;
  +
  +import org.apache.torque.TorqueException;
  +
   import org.xml.sax.Attributes;
   
   /**
    * A Class for information about indices of a table
    *
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: Index.java,v 1.1 2001/08/02 05:08:31 jvanzyl Exp $
  + * @author <a href="mailto:dlr@finemaltcoding.com>Daniel Rall</a>
  + * @version $Id: Index.java,v 1.2 2001/08/16 03:18:07 dlr Exp $
    */
   public class Index
   {
  +    private static final boolean DEBUG = true;
  +
       private String indexName;
       private Table parentTable;
  -    private List indexColumns = new ArrayList(3);
  +    private List indexColumns;
       private boolean isUnique;
   
       /**
  -     * Default Constructor
  +     * Creates a new instance with default characteristics (no name or
  +     * parent table, small column list size allocation, non-unique).
        */
       public Index()
       {
  +        indexColumns = new ArrayList(3);
  +        isUnique = false;
  +    }
  +
  +    /**
  +     * Creates a new instance for the list of columns composing an
  +     * index.  Otherwise performs as {@link #Index()}.
  +     *
  +     * @param indexColumns The list of {@link
  +     * org.apache.torque.engine.database.model.Column} objects which
  +     * make up this index.  Cannot be empty.
  +     * @see #Index()
  +     */
  +    public Index(List indexColumns)
  +    {
  +        this();
  +        System.out.println("indexColumns.size()=" + indexColumns.size());
  +        if (indexColumns.size() > 0)
  +        {
  +            StringBuffer buf = new StringBuffer();
  +            Iterator i = indexColumns.iterator();
  +            while (i.hasNext())
  +            {
  +                Column c = (Column) i.next();
  +                buf.append(c.getName()).append('_');
  +            }
  +            indexName = buf.append('I').toString();
  +            this.indexColumns = indexColumns;
  +            System.out.println("Created Index named " + indexName + " with " +
  +                               indexColumns + " columns");
  +        }
  +        else
  +        {
  +            // FIXME: This should be an exception, but I'm too lazy to
  +            // propagate it today.
  +            System.err.println("Cannot create a new Index using an " +
  +                               "empty list Column object");
  +        }
       }
   
       /**
  @@ -139,7 +185,7 @@
       }
   
       /**
  -     *  adds a new column to an index
  +     * Adds a new column to an index.
        */
       public void addColumn(Attributes attrib)
       {
  @@ -147,23 +193,19 @@
       }
   
       /**
  -     * Creates a list of columns delimited by commas
  +     * Return a comma delimited string of the columns which compose
  +     * this index.
        */
  -    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 getIndexColumnList()
       {
  -        return makeColumnList(indexColumns);
  +        Column c = (Column) indexColumns.get(0);
  +        StringBuffer res = new StringBuffer(c.getName());
  +        for (int i = 1; i < indexColumns.size(); i++)
  +        {
  +            c = (Column) indexColumns.get(i);
  +            res.append(", ").append(c.getName());
  +        }
  +        return res.toString();
       }
   
       /**
  
  
  

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