From torque-dev-return-3733-apmail-db-torque-dev-archive=db.apache.org@db.apache.org Tue Dec 02 02:14:41 2003 Return-Path: Delivered-To: apmail-db-torque-dev-archive@www.apache.org Received: (qmail 67649 invoked from network); 2 Dec 2003 02:14:41 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 2 Dec 2003 02:14:41 -0000 Received: (qmail 70017 invoked by uid 500); 2 Dec 2003 02:14:24 -0000 Delivered-To: apmail-db-torque-dev-archive@db.apache.org Received: (qmail 69999 invoked by uid 500); 2 Dec 2003 02:14:23 -0000 Mailing-List: contact torque-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Apache Torque Developers List" Reply-To: "Apache Torque Developers List" Delivered-To: mailing list torque-dev@db.apache.org Received: (qmail 69986 invoked from network); 2 Dec 2003 02:14:23 -0000 Received: from unknown (HELO localhost.localdomain) (208.185.179.196) by daedalus.apache.org with SMTP; 2 Dec 2003 02:14:23 -0000 Received: from finemaltcoding.com (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.12.8/8.12.8) with ESMTP id hB22EGIT002126 for ; Mon, 1 Dec 2003 18:14:17 -0800 Message-ID: <3FCBF578.5040309@finemaltcoding.com> Date: Mon, 01 Dec 2003 18:14:16 -0800 From: Daniel Rall User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030701 X-Accept-Language: en, en-us, ko, ja MIME-Version: 1.0 To: Apache Torque Developers List Subject: Re: cvs commit: db-torque/src/generator/src/test/org/apache/torque/engine/database/model TableTest.java References: <20031201165630.16429.qmail@minotaur.apache.org> In-Reply-To: <20031201165630.16429.qmail@minotaur.apache.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N If you aren't going to dup() the lists, it should be documented that handles to the internal storage are being returned. Otherwise, one could accidently modify the internal data structure without evening knowing it. mpoeschl@apache.org wrote: > 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