You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Dan Bachelder <ch...@chowda.net> on 2001/10/30 15:53:14 UTC

RE: cvs commit:jakarta-turbine-torque/src/java/org/apache/torque/taskTorqueJDBCTransformTask.java

There have been some changes to this task since I wrote that patch.. I wouldn't mind creating a new one.. I would also like to change the System.out logging I did over to something better... what is the desired way to do logging in Torque tasks going forward? log()? I think I read in the ant 1.4 release notes that using System for logging of any kind can now cause "bad things" to happen. I would also like to add the ability to use regex in the include/exclude stuff.. if that is desireable which regex package should I use? anyone care?

On Tue, 30 October 2001, "Howard Lin" wrote:

> 
> Jason and Daniel:
> 
> About two weeks ago, there was a patch submitted by Dan Bachelder for
> TorqueJDBCTransformTask. The patch fixed "out of cursor" problem and
> also add some new features, like specifying schema, being able to
> include/exclue tables. Can you take a look at the patch and check these
> features into CVS? 
> 
> Howard Lin
> 
> > -----Original Message-----
> > From: Jason van Zyl [mailto:jvanzyl@zenplex.com]
> > Sent: Tuesday, October 30, 2001 9:06 AM
> > To: Turbine Developers List
> > Subject: Re: cvs
> > commit:jakarta-turbine-torque/src/java/org/apache/torque/taskT
> > orqueJDBCT
> > ransformTask.java
> > 
> > 
> > On 10/30/01 2:05 AM, "dlr@apache.org" <dl...@apache.org> wrote:
> > 
> > > dlr         01/10/29 23:05:02
> > > 
> > > Modified:    src/java/org/apache/torque/task 
> > TorqueJDBCTransformTask.java
> > > Log:
> > > o Calls to close() should always be in try/finally blocks, 
> > wrapped w/
> > > a test for null.
> > > 
> > > o Interfaces should always be used to reference implementations
> > > (i.e. use the List interface to reference Vector).
> > > 
> > > o Meaningful variable names are a nice plus.
> > 
> > Nice catches :-)
> > 
> > > 
> > > Revision  Changes    Path
> > > 1.4       +112 -74
> > > 
> > jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueJ
> > DBCTransformTask
> > > .java
> > > 
> > > Index: TorqueJDBCTransformTask.java
> > > ===================================================================
> > > RCS file: 
> > > 
> > /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/ta
> > sk/TorqueJDBCTra
> > > nsformTask.java,v
> > > retrieving revision 1.3
> > > retrieving revision 1.4
> > > diff -u -u -r1.3 -r1.4
> > > --- TorqueJDBCTransformTask.java    2001/10/30 00:35:59    1.3
> > > +++ TorqueJDBCTransformTask.java    2001/10/30 07:05:02    1.4
> > > @@ -92,7 +92,7 @@
> > >   *
> > >   *  @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
> > >   *  @author <a href="mailto:fedor.karpelevitch@barra.com">Fedor
> > > Karpelevitch</a>
> > > - *  @version $Id: TorqueJDBCTransformTask.java,v 1.3 
> > 2001/10/30 00:35:59
> > > jvanzyl Exp $
> > > + *  @version $Id: TorqueJDBCTransformTask.java,v 1.4 
> > 2001/10/30 07:05:02 dlr
> > > Exp $
> > >   */
> > >  public class TorqueJDBCTransformTask extends Task
> > >  {
> > > @@ -217,7 +217,7 @@
> > >          DatabaseMetaData dbMetaData = con.getMetaData();
> > >  
> > >          // The database map.
> > > -        Vector tableList = getTableNames(dbMetaData);
> > > +        List tableList = getTableNames(dbMetaData);
> > >  
> > >          appData = doc.createElement("app-data");
> > >          database = doc.createElement("database");
> > > @@ -227,13 +227,13 @@
> > >  
> > >          for (int i = 0; i < tableList.size(); i++)
> > >          {
> > > -            String curTable = (String) tableList.elementAt(i);
> > > -            Vector columns = getColumns(dbMetaData, curTable);
> > > +            String curTable = (String) tableList.get(i);
> > > +            List columns = getColumns(dbMetaData, curTable);
> > >  
> > >              for (int j = 0; j < columns.size(); j++)
> > >              {
> > > -                Vector v = (Vector) columns.elementAt(j);
> > > -                String name = (String) v.elementAt(0);
> > > +                List col = (List) columns.get(j);
> > > +                String name = (String) col.get(0);
> > >  
> > >                  columnTableMap.put(name, curTable);
> > >              }
> > > @@ -242,7 +242,7 @@
> > >          for (int i = 0; i < tableList.size(); i++)
> > >          {
> > >              // Add Table.
> > > -            String curTable = (String) tableList.elementAt(i);
> > > +            String curTable = (String) tableList.get(i);
> > >              // dbMap.addTable(curTable);
> > >  
> > >              Element table = doc.createElement("table");
> > > @@ -270,10 +270,10 @@
> > >  
> > >              for (int j = 0; j < columns.size(); j++)
> > >              {
> > > -                Vector v = (Vector) columns.get(j);
> > > -                String name = (String) v.elementAt(0);
> > > -                Integer type = ((Integer) v.elementAt(1));
> > > -                int size = ((Integer) v.elementAt(2)).intValue();
> > > +                List col = (List) columns.get(j);
> > > +                String name = (String) col.get(0);
> > > +                Integer type = ((Integer) col.get(1));
> > > +                int size = ((Integer) col.get(2)).intValue();
> > >  
> > >                  // From DatabaseMetaData.java
> > >                  //
> > > @@ -287,8 +287,8 @@
> > >                  // Indicates NULLABILITY of column is unknown.
> > >                  /* int columnNullableUnknown = 2; */
> > >  
> > > -                Integer nullType = (Integer) v.elementAt(3);
> > > -                String defValue = (String)v.elementAt(4);
> > > +                Integer nullType = (Integer) col.get(3);
> > > +                String defValue = (String) col.get(4);
> > >  
> > >                  Element column = doc.createElement("column");
> > >                  column.setAttribute("name", name);
> > > @@ -343,7 +343,7 @@
> > >              {
> > >                  Object[] forKey = (Object[]) l.next();
> > >                  String foreignKeyTable = (String)forKey[0];
> > > -                Vector refs = (Vector)forKey[1];
> > > +                List refs = (List) forKey[1];
> > >                  Element fk = doc.createElement("foreign-key");
> > >                  fk.setAttribute("foreignTable", foreignKeyTable);
> > >                  for (int m=0; m<refs.size(); m++)
> > > @@ -369,24 +369,34 @@
> > >       * system tables.
> > >       *
> > >       * @param dbMeta JDBC database metadata.
> > > -     * @return A Vector with all the tables in a database.
> > > -     * @exception SQLException.
> > > +     * @return The list of all the tables in a database.
> > > +     * @exception SQLException
> > >       */
> > > -    public Vector getTableNames(DatabaseMetaData dbMeta)
> > > +    public List getTableNames(DatabaseMetaData dbMeta)
> > >          throws SQLException
> > >      {
> > > -        ResultSet tableNames = dbMeta.getTables(null,null, 
> > "%",null);
> > > -        Vector tables = new Vector();
> > > -        while (tableNames.next())
> > > +        List tables = new Vector();
> > > +        ResultSet tableNames = null;
> > > +        try
> > >          {
> > > -            String name = tableNames.getString(3);
> > > -            String type = tableNames.getString(4);
> > > -            if (type.equals("TABLE"))
> > > +            tableNames = dbMeta.getTables(null,null, "%",null);
> > > +            while (tableNames.next())
> > >              {
> > > -                tables.addElement(name);
> > > +                String name = tableNames.getString(3);
> > > +                String type = tableNames.getString(4);
> > > +                if (type.equals("TABLE"))
> > > +                {
> > > +                    tables.add(name);
> > > +                }
> > >              }
> > >          }
> > > -       tableNames.close();
> > > +        finally
> > > +        {
> > > +            if (tableNames != null)
> > > +            {
> > > +                tableNames.close();
> > > +            }
> > > +        }
> > >          return tables;
> > >      }
> > >  
> > > @@ -403,31 +413,40 @@
> > >       * @param dbMeta JDBC metadata.
> > >       * @param tableName Table from which to retrieve column
> > >       * information.
> > > -     * @return A Vector with the list of columns in tableName.
> > > +     * @return The list of columns in <code>tableName</code>.
> > >       */
> > > -    public Vector getColumns(DatabaseMetaData dbMeta,
> > > -                             String tableName)
> > > +    public List getColumns(DatabaseMetaData dbMeta, String 
> > tableName)
> > >          throws SQLException
> > >      {
> > > -        ResultSet columnSet = dbMeta.getColumns(null,null, 
> > tableName, null);
> > > -        Vector columns = new Vector();
> > > -        while (columnSet.next())
> > > -        {
> > > -            String name = columnSet.getString(4);
> > > -            Integer sqlType = new Integer(columnSet.getString(5));
> > > -            Integer size = new Integer(columnSet.getInt(7));
> > > -            Integer nullType = new Integer(columnSet.getInt(11));
> > > -            String defValue = columnSet.getString(13);
> > > -
> > > -            Vector v = new Vector();
> > > -            v.addElement (name);
> > > -            v.addElement (sqlType);
> > > -            v.addElement (size);
> > > -            v.addElement (nullType);
> > > -            v.addElement (defValue);
> > > -            columns.addElement (v);
> > > +        List columns = new Vector();
> > > +        ResultSet columnSet = null;
> > > +        try
> > > +        {
> > > +            columnSet = dbMeta.getColumns(null,null, 
> > tableName, null);
> > > +            while (columnSet.next())
> > > +            {
> > > +                String name = columnSet.getString(4);
> > > +                Integer sqlType = new 
> > Integer(columnSet.getString(5));
> > > +                Integer size = new Integer(columnSet.getInt(7));
> > > +                Integer nullType = new 
> > Integer(columnSet.getInt(11));
> > > +                String defValue = columnSet.getString(13);
> > > +
> > > +                List col = new Vector(5);
> > > +                col.add(name);
> > > +                col.add(sqlType);
> > > +                col.add(size);
> > > +                col.add(nullType);
> > > +                col.add(defValue);
> > > +                columns.add(col);
> > > +            }
> > > +        }
> > > +        finally
> > > +        {
> > > +            if (columnSet != null)
> > > +            {
> > > +                columnSet.close();
> > > +            }
> > >          }
> > > -       columnSet.close();
> > >          return columns;
> > >      }
> > >  
> > > @@ -442,14 +461,23 @@
> > >      public List getPrimaryKeys(DatabaseMetaData dbMeta, 
> > String tableName)
> > >          throws SQLException
> > >      {
> > > -        ResultSet parts = dbMeta.getPrimaryKeys(null, 
> > null, tableName);
> > >          List pk = new Vector();
> > > -        while (parts.next())
> > > +        ResultSet parts = null;
> > > +        try
> > >          {
> > > -            pk.add(parts.getString(4));
> > > +            parts = dbMeta.getPrimaryKeys(null, null, tableName);
> > > +            while (parts.next())
> > > +            {
> > > +                pk.add(parts.getString(4));
> > > +            }
> > >          }
> > > -       
> > > -        parts.close();
> > > +        finally
> > > +        {
> > > +            if (parts != null)
> > > +            {
> > > +                parts.close();
> > > +            }
> > > +        }
> > >          return pk;
> > >      }
> > >  
> > > @@ -463,36 +491,46 @@
> > >      public Collection getForeignKeys(DatabaseMetaData 
> > dbMeta, String
> > > tableName)
> > >          throws SQLException
> > >      {
> > > -        ResultSet foreignKeys = dbMeta.getImportedKeys(null, null,
> > > tableName);
> > >          Hashtable fks = new Hashtable();
> > > -        while (foreignKeys.next())
> > > +        ResultSet foreignKeys = null;
> > > +        try
> > >          {
> > > -            String fkName = foreignKeys.getString(12);
> > > -            // if FK has no name - make it up (use 
> > tablename instead)
> > > -            if (fkName==null)
> > > -            {
> > > -                fkName = foreignKeys.getString(3);
> > > -            }
> > > -            Object[] fk = (Object[])fks.get(fkName);
> > > -            Vector refs;
> > > -            if (fk==null)
> > > +            foreignKeys = dbMeta.getImportedKeys(null, 
> > null, tableName);
> > > +            while (foreignKeys.next())
> > >              {
> > > -                fk = new Object[2];
> > > -                fk[0] = foreignKeys.getString(3); 
> > //referenced table name
> > > -                refs = new Vector();
> > > -                fk[1] = refs;
> > > -                fks.put(fkName, fk);
> > > +                String fkName = foreignKeys.getString(12);
> > > +                // if FK has no name - make it up (use 
> > tablename instead)
> > > +                if (fkName==null)
> > > +                {
> > > +                    fkName = foreignKeys.getString(3);
> > > +                }
> > > +                Object[] fk = (Object[])fks.get(fkName);
> > > +                List refs;
> > > +                if (fk==null)
> > > +                {
> > > +                    fk = new Object[2];
> > > +                    fk[0] = foreignKeys.getString(3); 
> > //referenced table name
> > > +                    refs = new Vector();
> > > +                    fk[1] = refs;
> > > +                    fks.put(fkName, fk);
> > > +                }
> > > +                else
> > > +                {
> > > +                    refs = (Vector)fk[1];
> > > +                }
> > > +                String[] ref = new String[2];
> > > +                ref[0] = foreignKeys.getString(8); //local column
> > > +                ref[1] = foreignKeys.getString(4); //foreign column
> > > +                refs.add(ref);
> > >              }
> > > -            else
> > > +        }
> > > +        finally
> > > +        {
> > > +            if (foreignKeys != null)
> > >              {
> > > -                refs = (Vector)fk[1];
> > > +                foreignKeys.close();
> > >              }
> > > -            String[] ref = new String[2];
> > > -            ref[0] = foreignKeys.getString(8); //local column
> > > -            ref[1] = foreignKeys.getString(4); //foreign column
> > > -            refs.add(ref);
> > >          }
> > > -       foreignKeys.close();
> > >          return fks.values();
> > >      }
> > >  }
> > > 
> > > 
> > > 
> > > 
> > > --
> > > To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> -- 
> 
> jvz.
> 
> Jason van Zyl
> 
> http://tambora.zenplex.org
> http://jakarta.apache.org/turbine
> http://jakarta.apache.org/velocity
> http://jakarta.apache.org/alexandria
> http://jakarta.apache.org/commons
> 
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

</dan>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit:jakarta-turbine-torque/src/java/org/apache/torque/taskTorqueJDBCTran sformTask.java

Posted by Jason van Zyl <jv...@zenplex.com>.
On 11/1/01 12:37 PM, "Daniel Rall" <dl...@finemaltcoding.com> wrote:

> Dan Bachelder <ch...@chowda.net> writes:
> 
>> There have been some changes to this task since I wrote that
>> patch.. I wouldn't mind creating a new one.. I would also like to
>> change the System.out logging I did over to something better... what
>> is the desired way to do logging in Torque tasks going forward?
>> log()? I think I read in the ant 1.4 release notes that using System
>> for logging of any kind can now cause "bad things" to happen. I
>> would also like to add the ability to use regex in the
>> include/exclude stuff.. if that is desireable which regex package
>> should I use? anyone care?
> 
> I dunno if I already replied to this, but once Jason finishes merging
> it would be great to get another copy of your patch, Dan.
> 
> Jason, any thoughts on the logging question?  I believe that Ant
> logging is available from Task subclasses--that strikes me as the
> right way to go.

I agree, get rid of all the System.println calls with the log() available in
the tasks.
 
> I'm -1 on adding another library for only regex matching in one task.
> The globbing patterns provided by Ant are generally enough.

We don't need regex methods. As the standard build-torque.xml gets cleaned
up for general use I think it will cover all cases well. This included the
multiple database scenerio. I started using the <fileset> options in the
build-torque.xml so that it doesn't matter if you have 1 or 10 datamodel
descriptors the actions taken will be the same.
 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cvs commit:jakarta-turbine-torque/src/java/org/apache/torque/taskTorqueJDBCTransformTask.java

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Dan Bachelder <ch...@chowda.net> writes:

> There have been some changes to this task since I wrote that
> patch.. I wouldn't mind creating a new one.. I would also like to
> change the System.out logging I did over to something better... what
> is the desired way to do logging in Torque tasks going forward? 
> log()? I think I read in the ant 1.4 release notes that using System
> for logging of any kind can now cause "bad things" to happen. I
> would also like to add the ability to use regex in the
> include/exclude stuff.. if that is desireable which regex package
> should I use? anyone care?

I dunno if I already replied to this, but once Jason finishes merging
it would be great to get another copy of your patch, Dan.

Jason, any thoughts on the logging question?  I believe that Ant
logging is available from Task subclasses--that strikes me as the
right way to go.

I'm -1 on adding another library for only regex matching in one task.
The globbing patterns provided by Ant are generally enough.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>