db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpoes...@apache.org
Subject cvs commit: db-torque/src/generator/src/test/org/apache/torque/engine/database/model TableTest.java
Date Mon, 01 Dec 2003 16:56:30 GMT
mpoeschl    2003/12/01 08:56:30

  Modified:    src/generator/src/java/org/apache/torque/engine/database/model
                        Table.java Index.java Database.java Column.java
               src/generator/src/test/org/apache/torque/engine/database/model
                        TableTest.java
  Log:
  replace all []s and return the internal Lists
  
  Revision  Changes    Path
  1.5       +19 -39    db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Table.java
  
  Index: Table.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Table.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Table.java	25 Nov 2003 16:57:13 -0000	1.4
  +++ Table.java	1 Dec 2003 16:56:30 -0000	1.5
  @@ -814,17 +814,13 @@
       }
   
       /**
  -     * Returns an Array containing all the columns in the table
  +     * Returns a List containing all the columns in the table
  +     * 
  +     * @return a List containing all the columns
        */
  -    public Column[] getColumns()
  +    public List getColumns()
       {
  -        int size = columnList.size();
  -        Column[] tbls = new Column[size];
  -        for (int i = 0; i < size; i++)
  -        {
  -            tbls[i] = (Column) columnList.get(i);
  -        }
  -        return tbls;
  +        return columnList;
       }
   
       /**
  @@ -836,17 +832,13 @@
       }
   
       /**
  -     * Returns an Array containing all the FKs in the table
  +     * Returns a List containing all the FKs in the table
  +     * 
  +     * @return a List containing all the FKs
        */
  -    public ForeignKey[] getForeignKeys()
  +    public List getForeignKeys()
       {
  -        int size = foreignKeys.size();
  -        ForeignKey[] tbls = new ForeignKey[size];
  -        for (int i = 0; i < size; i++)
  -        {
  -            tbls[i] = (ForeignKey) foreignKeys.get(i);
  -        }
  -        return tbls;
  +        return foreignKeys;
       }
   
       /**
  @@ -882,35 +874,23 @@
       }
   
       /**
  -     * Returns an Array containing all the indices in the table
  +     * Returns a List containing all the indices in the table
        *
  -     * @return An array containing all the indices
  +     * @return A List containing all the indices
        */
  -    public Index[] getIndices()
  +    public List getIndices()
       {
  -        int size = indices.size();
  -        Index[] tbls = new Index[size];
  -        for (int i = 0; i < size; i++)
  -        {
  -            tbls[i] = (Index) indices.get(i);
  -        }
  -        return tbls;
  +        return indices;
       }
   
       /**
  -     * Returns an Array containing all the UKs in the table
  +     * Returns a List containing all the UKs in the table
        *
  -     * @return An array containing all the UKs
  +     * @return A List containing all the UKs
        */
  -    public Unique[] getUnices()
  +    public List getUnices()
       {
  -        int size = unices.size();
  -        Unique[] tbls = new Unique[size];
  -        for (int i = 0; i < size; i++)
  -        {
  -            tbls[i] = (Unique) unices.get(i);
  -        }
  -        return tbls;
  +        return unices;
       }
   
       /**
  
  
  
  1.3       +2 -2      db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Index.java
  
  Index: Index.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Index.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Index.java	26 Jun 2003 06:59:56 -0000	1.2
  +++ Index.java	1 Dec 2003 16:56:30 -0000	1.3
  @@ -146,7 +146,7 @@
               inputs.add("I");
           }
           // ASSUMPTION: This Index not yet added to the list.
  -        inputs.add(new Integer(table.getIndices().length + 1));
  +        inputs.add(new Integer(table.getIndices().size() + 1));
           indexName = NameFactory.generateName(
                   NameFactory.CONSTRAINT_GENERATOR, inputs);
       }
  
  
  
  1.13      +24 -25    db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Database.java
  
  Index: Database.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Database.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Database.java	25 Nov 2003 16:57:13 -0000	1.12
  +++ Database.java	1 Dec 2003 16:56:30 -0000	1.13
  @@ -288,19 +288,13 @@
       }
   
       /**
  -     * Return an array of all tables
  +     * Return an List of all tables
        *
  -     * @return array of all tables
  +     * @return List of all tables
        */
  -    public Table[] getTables()
  +    public List getTables()
       {
  -        int size = tableList.size();
  -        Table[] tbls = new Table[size];
  -        for (int i = 0; i < size; i++)
  -        {
  -            tbls[i] = (Table) tableList.get(i);
  -        }
  -        return tbls;
  +        return tableList;
       }
   
       /**
  @@ -392,10 +386,11 @@
        */
       public boolean requiresIdTable()
       {
  -        Table table[] = getTables();
  -        for (int i = 0; i < table.length; i++)
  +        Iterator iter = getTables().iterator();
  +        while (iter.hasNext())
           {
  -            if (table[i].getIdMethod().equals(IDMethod.ID_BROKER))
  +            Table table = (Table) iter.next();
  +            if (table.getIdMethod().equals(IDMethod.ID_BROKER))
               {
                   return true;
               }
  @@ -403,13 +398,17 @@
           return false;
       }
   
  -    public void doFinalInitialization()
  -            throws EngineException
  +    /**
  +     * Initializes the model.
  +     * 
  +     * @throws EngineException
  +     */
  +    public void doFinalInitialization() throws EngineException
       {
  -        Table[] tables = getTables();
  -        for (int i = 0; i < tables.length; i++)
  +        Iterator iter = getTables().iterator();
  +        while (iter.hasNext())
           {
  -            Table currTable = tables[i];
  +            Table currTable = (Table) iter.next();
   
               // check schema integrity
               // if idMethod="autoincrement", make sure a column is
  @@ -418,11 +417,11 @@
               // TODO autoincrement is no longer supported!!!
               if (currTable.getIdMethod().equals("autoincrement"))
               {
  -                Column[] columns = currTable.getColumns();
                   boolean foundOne = false;
  -                for (int j = 0; j < columns.length && !foundOne; j++)
  +                Iterator colIter = currTable.getColumns().iterator();
  +                while (colIter.hasNext() && !foundOne)
                   {
  -                    foundOne = columns[j].isAutoIncrement();
  +                    foundOne = ((Column) colIter.next()).isAutoIncrement();
                   }
   
                   if (!foundOne)
  @@ -438,10 +437,10 @@
               currTable.doFinalInitialization();
   
               // setup reverse fk relations
  -            ForeignKey[] fks = currTable.getForeignKeys();
  -            for (int j = 0; j < fks.length; j++)
  +            Iterator fks = currTable.getForeignKeys().iterator();
  +            while (fks.hasNext())
               {
  -                ForeignKey currFK = fks[j];
  +                ForeignKey currFK = (ForeignKey) fks.next();
                   Table foreignTable = getTable(currFK.getForeignTableName());
                   if (foreignTable == null)
                   {
  
  
  
  1.15      +7 -6      db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Column.java
  
  Index: Column.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Column.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Column.java	25 Nov 2003 19:19:06 -0000	1.14
  +++ Column.java	1 Dec 2003 16:56:30 -0000	1.15
  @@ -55,6 +55,7 @@
    */
   
   import java.util.ArrayList;
  +import java.util.Iterator;
   import java.util.List;
   
   import org.apache.commons.lang.StringUtils;
  @@ -493,12 +494,12 @@
           ForeignKey fk = getForeignKey();
           if (fk != null)
           {
  -            ForeignKey[] fks = parentTable.getForeignKeys();
  -            for (int i = 0; i < fks.length; i++)
  +            Iterator fks = parentTable.getForeignKeys().iterator();
  +            while (fks.hasNext())
               {
  -                if (fks[i].getForeignTableName()
  -                        .equals(fk.getForeignTableName())
  -                        && !fks[i].getLocalColumns().contains(this.name))
  +                ForeignKey key = (ForeignKey) fks.next();
  +                if (key.getForeignTableName().equals(fk.getForeignTableName())
  +                        && !key.getLocalColumns().contains(this.name))
                   {
                       return true;
                   }
  
  
  
  1.7       +10 -10    db-torque/src/generator/src/test/org/apache/torque/engine/database/model/TableTest.java
  
  Index: TableTest.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/test/org/apache/torque/engine/database/model/TableTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TableTest.java	5 Oct 2003 14:14:03 -0000	1.6
  +++ TableTest.java	1 Dec 2003 16:56:30 -0000	1.7
  @@ -136,9 +136,9 @@
       public void testSingleFk() throws Exception
       {
           Table table = db.getTable("singlefk");
  -        ForeignKey[] fks = table.getForeignKeys();
  -        assertTrue(fks.length == 1);
  -        ForeignKey fk = fks[0];
  +        List fks = table.getForeignKeys();
  +        assertTrue(fks.size() == 1);
  +        ForeignKey fk = (ForeignKey) fks.get(0);
           assertEquals(fk.getForeignTableName(), "singlepk");
           assertTrue(fk.getForeignColumns().size() == 1);
       }
  @@ -146,9 +146,9 @@
       public void testMultiFk() throws Exception
       {
           Table table = db.getTable("multifk");
  -        ForeignKey[] fks = table.getForeignKeys();
  -        assertTrue(fks.length == 1);
  -        ForeignKey fk = fks[0];
  +        List fks = table.getForeignKeys();
  +        assertTrue(fks.size() == 1);
  +        ForeignKey fk = (ForeignKey) fks.get(0);
           assertEquals(fk.getForeignTableName(), "multipk");
           assertTrue(fk.getForeignColumns().size() == 2);
       }
  @@ -165,9 +165,9 @@
       public void testUnique() throws Exception
       {
           Table table = db.getTable("unique_test");
  -        Unique[] unices = table.getUnices();
  -        assertTrue(unices.length == 1);
  -        Unique unique = unices[0];
  +        List unices = table.getUnices();
  +        assertTrue(unices.size() == 1);
  +        Unique unique = (Unique) unices.get(0);
           assertEquals(unique.getName(), "unique_name");   
           assertTrue(unique.getColumns().size() == 2);     
       }
  
  
  

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


Mime
View raw message