commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql TestDataModelRoundTrip.java
Date Tue, 10 Sep 2002 13:49:47 GMT
jstrachan    2002/09/10 06:49:46

  Modified:    sql/src/java/org/apache/commons/sql/builder
                        MSSqlBuilder.java SqlBuilder.java
                        OracleBuilder.java SybaseBuilder.java
                        MySqlBuilder.java
               sql/src/test/org/apache/commons/sql/builder TestBuilder.java
               sql/src/test-input datamodel.xml
               sql/src/test/org/apache/commons/sql
                        TestDataModelRoundTrip.java
  Added:       sql/src/java/org/apache/commons/sql/io DatabaseReader.java
                        DatabaseWriter.java package.html
               sql/src/java/org/apache/commons/sql/task/velocity
                        CreateDatabase.java DataDumpTask.java
                        DocumentationTask.java DataModelTask.java
                        DataSQLTask.java DataDTDTask.java SQLTask.java
                        package.html
               sql/src/java/org/apache/commons/sql/task package.html
               sql/src/java/org/apache/commons/sql/builder package.html
               sql/src/java/org/apache/commons/sql/model package.html
  Removed:     sql/src/java/org/apache/commons/sql/task DataDumpTask.java
                        DocumentationTask.java DataModelTask.java
                        DataSQLTask.java DataDTDTask.java SQLTask.java
                        CreateDatabase.java
  Log:
  * Reoganized the SqlBuilder code a bit to make it easier to derive and use.
  
  * added an IO package to hide the details of using Betwixt with commons-sql
  
  * the basic Oracle, MSSql, MySql and Sybase builders seem to work fine now
  
  * added licences to code
  
  * moved the Ant tasks which depend on Velocity/Texen into a seperate package, so its easy to know which Ant tasks can be used with just commons code and which requires Velocity/Texen
  Right now I don't think the Velocity tasks are working on the new commons-sql model.
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/io/DatabaseReader.java
  
  Index: DatabaseReader.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/CompilableTag.java,v 1.5 2002/05/17 15:18:12 jstrachan Exp $
   * $Revision: 1.5 $
   * $Date: 2002/05/17 15:18:12 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: CompilableTag.java,v 1.5 2002/05/17 15:18:12 jstrachan Exp $
   */
  
  package org.apache.commons.sql.io;
  
  import java.beans.IntrospectionException;
  import java.io.IOException;
  import java.io.Writer;
  
  import org.apache.commons.betwixt.XMLIntrospector;
  import org.apache.commons.betwixt.io.BeanReader;
  import org.apache.commons.betwixt.strategy.HyphenatedNameMapper;
  
  import org.apache.commons.sql.model.Database;
  
  /**
   * This class parsers XML and creates a fully populated Database bean.
   * This class is-a Digester and so can support configuration via custom rules.
   * 
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.14 $
   */
  public class DatabaseReader extends BeanReader {
      
      public DatabaseReader() throws IntrospectionException {
          setXMLIntrospector( newXMLIntrospector() );
          registerBeanClass(Database.class);
      }
  
      /**
       * A factory method to create the default introspector used to turn
       * the Database object model into XML
       */    
      protected static XMLIntrospector newXMLIntrospector() {
          XMLIntrospector introspector = new XMLIntrospector();
  
          // configure the style of the XML, to brief and attribute based
          introspector.setAttributesForPrimitives(true);
          introspector.setWrapCollectionsInElement(false);
  
          // set the mixed case name mapper
          introspector.setElementNameMapper(new HyphenatedNameMapper());
          //introspector.setElementNameMapper(new DecapitalizeNameMapper());
  
          return introspector;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/io/DatabaseWriter.java
  
  Index: DatabaseWriter.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/CompilableTag.java,v 1.5 2002/05/17 15:18:12 jstrachan Exp $
   * $Revision: 1.5 $
   * $Date: 2002/05/17 15:18:12 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: CompilableTag.java,v 1.5 2002/05/17 15:18:12 jstrachan Exp $
   */
  
  package org.apache.commons.sql.io;
  
  import java.io.OutputStream;
  import java.io.Writer;
  
  import org.apache.commons.betwixt.XMLIntrospector;
  import org.apache.commons.betwixt.io.BeanWriter;
  
  import org.apache.commons.sql.model.Database;
  
  /**
   * This class outputs a fully populated Database bean as XML.
   * 
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.14 $
   */
  public class DatabaseWriter extends BeanWriter {
      
      public DatabaseWriter(OutputStream out) {
          super(out);
          init();
      }
      
      public DatabaseWriter(Writer writer) {
          super(writer);
          init();
      }
      
      /**
       * Common initialization code
       */
      private void init() {
          setXMLIntrospector( DatabaseReader.newXMLIntrospector() );
          enablePrettyPrint();
          setWriteIDs(false);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/io/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
    <p>
    	This package contains IO classes for reading and writing database models to and from XML using the
    	<a href="http://jakarta.apache.org/commons/betwixt/">Betwixt</a> library.
    </p>
  </body>
  </html>
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/task/velocity/CreateDatabase.java
  
  Index: CreateDatabase.java
  ===================================================================
  package org.apache.commons.sql.task.velocity;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.velocity.context.Context;
  
  /**
   * An extended Texen task used for generating simple scripts
   * for creating databases on various platforms.
   *
   * @author <a href="mailto:jvanzyl@zenplex.com">Jason van Zyl</a>
   * @version $Id: TorqueCreateDatabase.java,v 1.6 2002/04/11 22:02:06 mpoeschl Exp $
   */
  public class CreateDatabase 
      extends DataModelTask
  {
      /**
       * The target database vendor: MySQL, Oracle.
       */
      private String targetDatabase;
  
      /**
       * Get the target database.
       *
       * @return String target database.
       */
      public String getTargetDatabase()
      {
          return targetDatabase;
      }
  
      /**
       * Set the target database.
       *
       * @param String target database(s)
       */
      public void setTargetDatabase(String v)
      {
          targetDatabase = v;
      }
  
      /**
       * Place our target database and target platform
       * values into the context for use in the
       * templates.
       */
      public Context initControlContext() throws Exception
      {   
          super.initControlContext();
          context.put("targetDatabase", targetDatabase);
          return context;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/task/velocity/DataDumpTask.java
  
  Index: DataDumpTask.java
  ===================================================================
  package org.apache.commons.sql.task.velocity;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  import java.sql.Statement;
  import org.apache.tools.ant.Project;
  import org.apache.velocity.context.Context;
  
  import com.workingdogs.village.QueryDataSet;
  import com.workingdogs.village.Record;
  
  /**
   * An extended Texen task used for dumping data from db into XML
   *
   * @author <a href="mailto:fedor.karpelevitch@home.com">Fedor Karpelevitch</a>
   * @author <a href="jvanzyl@zenplex.com">Jason van Zyl</a>
   * @author <a href="dlr@finemaltcoding.com">Daniel Rall</a>
   * @version $Id: TorqueDataDumpTask.java,v 1.7 2002/04/11 22:02:06 mpoeschl Exp $
   */
  public class DataDumpTask 
      extends DataModelTask
  {
      /**
       * Database name.
       */
      private String databaseName;
  
      /**
       *  Database URL used for JDBC connection.
       */
      private String databaseUrl;
  
      /**
       *  Database driver used for JDBC connection.
       */
      private String databaseDriver;
  
      /**
       *  Database user used for JDBC connection.
       */
      private String databaseUser;
  
      /**
       *  Database password used for JDBC connection.
       */
      private String databasePassword;
  
      /**
       * The database connection used to retrieve the data to dump.
       */
      private Connection conn;
  
      /**
       * The statement used to acquire the data to dump.
       */
      private Statement stmt;
  
      /**
       *  Get the database name to dump
       *
       * @return  The DatabaseName value
       */
      public String getDatabaseName()
      {
          return databaseName;
      }
  
      /**
       *  Set the database name
       *
       * @param  v The new DatabaseName value
       */
      public void setDatabaseName(String v)
      {
          databaseName = v;
      }
  
      /**
       *  Get the database url
       *
       * @return  The DatabaseUrl value
       */
      public String getDatabaseUrl()
      {
          return databaseUrl;
      }
  
      /**
       *  Set the database url
       *
       * @param  v The new DatabaseUrl value
       */
      public void setDatabaseUrl(String v)
      {
          databaseUrl = v;
      }
  
      /**
       *  Get the database driver name
       *
       * @return  String database driver name
       */
      public String getDatabaseDriver()
      {
          return databaseDriver;
      }
  
      /**
       *  Set the database driver name
       *
       * @param  v The new DatabaseDriver value
       */
      public void setDatabaseDriver(String v)
      {
          databaseDriver = v;
      }
  
      /**
       *  Get the database user
       *
       * @return  String database user
       */
      public String getDatabaseUser()
      {
          return databaseUser;
      }
  
      /**
       *  Set the database user
       *
       * @param  v The new DatabaseUser value
       */
      public void setDatabaseUser(String v)
      {
          databaseUser = v;
      }
  
      /**
       *  Get the database password
       *
       * @return  String database password
       */
      public String getDatabasePassword()
      {
          return databasePassword;
      }
  
      /**
       *  Set the database password
       *
       * @param  v The new DatabasePassword value
       */
      public void setDatabasePassword(String v)
      {
          databasePassword = v;
      }
  
      /**
       *  Initializes initial context
       *
       * @return  Description of the Returned Value
       */
      public Context initControlContext()
          throws Exception
      {
          super.initControlContext();
          
          context.put("dataset", "all");
  
          StringBuffer buf = new StringBuffer("Database settings:\n")
              .append(" driver: ").append(databaseDriver).append('\n')
              .append(" URL: ").append(databaseUrl).append('\n')
              .append(" user: ").append(databaseUser).append('\n')
              .append(" password: ").append(databasePassword).append('\n');
          log(buf.toString(), Project.MSG_DEBUG);
  
          try
          {
              Class.forName(databaseDriver);
              log("DB driver instantiated sucessfuly", Project.MSG_DEBUG);
  
              conn = DriverManager.getConnection(
                      databaseUrl, databaseUser, databasePassword);
  
              log("DB connection established", Project.MSG_DEBUG);
              context.put("tableTool", new TableTool());
          }
          catch (SQLException se)
          {
              System.err.println("SQLException while connecting to DB:");
              se.printStackTrace();
          }
          catch (ClassNotFoundException cnfe)
          {
              System.err.println("cannot load driver:");
              cnfe.printStackTrace();
          }
  
          return context;
      }
  
      /**
       * Closes <code>rs</code> and <code>conn</code>, overriding the
       * <code>cleanup()</code> hook method in <code>TexenTask</code>.
       *
       * @exception Exception Database problem while closing resource.
       */
      protected void cleanup() throws Exception
      {
          if (stmt != null)
          {
              stmt.close();
          }
  
          if (conn != null)
          {
              conn.close();
          }
      }
  
      /**
       *  A nasty do-it-all tool class. It serves as:
       *  <ul>
       *  <li>context tool to fetch a table iterator</li>
       *  <li>the abovenamed iterator which iterates over the table</li>
       *  <li>getter for the table fields</li>
       *  </ul>
       *
       * @author  fedor
       */
      public class TableTool implements Iterator
      {
          private QueryDataSet qds;
          private boolean isEmpty;
          private int curIndex = -1;
          private Record curRec = null;
  
          /**
           *  Constructor for the TableTool object
           */
          public TableTool()
          {
          }
  
          /**
           *  Constructor for the TableTool object
           *
           * @param  rs Description of Parameter
           * @exception SQLException Problem using database record set
           * cursor.
           */
          protected TableTool(QueryDataSet qds) throws Exception
          {
              this.qds = qds;
              this.qds.fetchRecords();
              this.isEmpty = !(qds.size() > 0);
          }
  
          /**
           *  Fetches an <code>Iterator</code> for the data in the named
           *  table.
           *
           * @param  tableName Description of Parameter
           * @return <code>Iterator</code> for the fetched data.
           * @exception SQLException Problem creating connection or
           * executing query.
           */
          public TableTool fetch(String tableName) throws Exception
          {
              log("Fetching data for table " + tableName, Project.MSG_INFO);
              // Set Statement object in associated TorqueDataDump
              // instance
              return new TableTool
                  (new QueryDataSet(conn, "SELECT * FROM " + tableName));
          }
  
          /**
           *  Description of the Method
           *
           * @return  Description of the Returned Value
           */
          public boolean hasNext()
          {
              try
              {
                  return ((this.curIndex < this.qds.size() - 1) && (!isEmpty));
              }
              catch (Exception se)
              {
                  System.err.println("Exception :");
                  se.printStackTrace();
              }
              return false;
          }
  
          /**
           * load the next record from the QueryDataSet
           *
           * @return Description of the Returned Value
           * @exception NoSuchElementException Description of Exception
           */
          public Object next() throws NoSuchElementException
          {
              try
              {
                  System.err.print(".");
                  this.curRec = this.qds.getRecord(++curIndex);
              }
              catch (Exception se)
              {
                  System.err.println("Exception while iterating:");
                  se.printStackTrace();
                  throw new NoSuchElementException(se.getMessage());
              }
              return this;
          }
  
          /**
           * Retruns the value for the column
           *
           * @param  columnName name of the column
           * @return  value of the column or null if it doesn't exist
           */
          public String get(String columnName)
          {
              try
              {
                  return(this.curRec.getValue(columnName).asString());
              }
              catch (Exception se)
              {
                  log("Exception fetching value " + columnName + ": " +
                      se.getMessage(), Project.MSG_ERR);
              }
              return null;
          }
  
          /**
           * unsupported! always throws Exception
           *
           * @exception UnsupportedOperationException
           */
          public void remove() throws UnsupportedOperationException
          {
              throw new UnsupportedOperationException();
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/task/velocity/DocumentationTask.java
  
  Index: DocumentationTask.java
  ===================================================================
  package org.apache.commons.sql.task.velocity;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.velocity.context.Context;
  
  /**
   * An ant task for generating output by using Velocity
   *
   * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
   * @version $Id: TorqueDocumentationTask.java,v 1.2 2002/04/11 22:02:06 mpoeschl Exp $
   */
  public class DocumentationTask 
      extends DataModelTask
  {
  
      /**
       * The target database(s) we are generating SQL
       * for. Right now we can only deal with a single
       * target, but we will support multiple targets
       * soon.
       */
      private String targetDatabase;
  
      private String outputFormat;
  
  
      /**
       * Get the current target package.
       *
       * @return String target database(s)
       */
      public String getTargetDatabase()
      {
          return targetDatabase;
      }
  
      /**
       * Set the current target package.  This is where
       * generated java classes will live.
       *
       * @param v target database(s)
       */
      public void setTargetDatabase(String v)
      {
          targetDatabase = v;
      }
  
      /**
       * Get the current output format.
       *
       * @return the current output format
       */
      public String getOutputFormat()
      {
          return outputFormat;
      }
  
      /**
       * Set the current output format.
       *
       * @param v output format
       */
      public void setOutputFormat(String v)
      {
          outputFormat = v;
      }
  
      /**
       * Place our target package value into the context for use in the templates.
       */
      public Context initControlContext() throws Exception
      {
          super.initControlContext();
          context.put("targetDatabase", targetDatabase);
          context.put("outputFormat", outputFormat);
          return context;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/task/velocity/DataModelTask.java
  
  Index: DataModelTask.java
  ===================================================================
  package org.apache.commons.sql.task.velocity;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.File;
  import java.util.Hashtable;
  import java.util.Iterator;
  import java.util.Vector;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.DirectoryScanner;
  import org.apache.tools.ant.types.FileSet;
  import org.apache.velocity.context.Context;
  import org.apache.velocity.VelocityContext;
  import org.apache.velocity.texen.ant.TexenTask;
  
  /**
   * A base torque task that uses either a single XML schema
   * representing a data model, or a &lt;fileset&gt; of XML schemas.
   * We are making the assumption that an XML schema representing
   * a data model contains tables for a <strong>single</strong>
   * database.
   *
   * @author <a href="mailto:jvanzyl@zenplex.com">Jason van Zyl</a>
   * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
   */
  public class DataModelTask
      extends TexenTask
  {
      /**
       *  XML that describes the database model, this is transformed
       *  into the application model object.
       */
      protected String xmlFile;
  
      /**
       * Fileset of XML schemas which represent our data models.
       */
      protected Vector filesets = new Vector();
      
      /**
       * Data models that we collect. One from each XML schema file.
       */
      protected Vector dataModels = new Vector();
  
      /**
       * Velocity context which exposes our objects
       * in the templates.
       */
      protected Context context;
  
      /**
       * Map of data model name to database name.
       * Should probably stick to the convention
       * of them being the same but I know right now
       * in a lot of cases they won't be.
       */
      protected Hashtable dataModelDbMap;
      
      /**
       * Hashtable containing the names of all the databases
       * in our collection of schemas.
       */
      protected Hashtable databaseNames;
  
      //!! This is probably a crappy idea having the sql file -> db map
      // here. I can't remember why I put it here at the moment ...
      // maybe I was going to map something else. It can probably 
      // move into the SQL task.
  
      /**
       * Name of the properties file that maps an SQL file
       * to a particular database.
       */
      protected String sqldbmap;
  
      /**
       * The path to properties file containing db idiosyncrasies is
       * constructed by appending the "getTargetDatabase()/db.props
       * to this path.
       */
      private String basePathToDbProps;
  
      /**
       * The target database(s) we are generating SQL
       * for. Right now we can only deal with a single
       * target, but we will support multiple targets
       * soon.
       */
      private String targetDatabase;
  
      /**
       * Set the sqldbmap.
       *
       * @param sqldbmap th db map 
       */
      public void setSqlDbMap(String sqldbmap)
      {
          //!! Make all these references files not strings.
          this.sqldbmap = project.resolveFile(sqldbmap).toString();
      }
      
      /**
       * Get the sqldbmap.
       *
       * @return String sqldbmap.
       */
      public String getSqlDbMap()
      {
          return sqldbmap;
      }        
  
      /**
       * Return the data models that have been
       * processed.
       *
       * @return Vector data models
       */
      public Vector getDataModels()
      {
          return dataModels;
      }        
  
      /**
       * Return the data model to database name map.
       *
       * @return Hashtable data model name to database name map.
       */
      public Hashtable getDataModelDbMap()
      {
          return dataModelDbMap;
      }        
  
      /**
       * Get the xml schema describing the application model.
       *
       * @return  String xml schema file.
       */
      public String getXmlFile()
      {
          return xmlFile;
      }
  
      /**
       * Set the xml schema describing the application model.
       *
       * @param xmlFile The new XmlFile value
       */
      public void setXmlFile(String xmlFile)
      {
          this.xmlFile = project.resolveFile(xmlFile).toString();
      }
  
      /**
       * Adds a set of files (nested fileset attribute).
       */
      public void addFileset(FileSet set) 
      {
          filesets.addElement(set);
      }
  
      /**
       * Get the current target package.
       *
       * @return String target database(s)
       */
      public String getTargetDatabase()
      {
          return targetDatabase;
      }
  
      /**
       * Set the current target package.  This is where
       * generated java classes will live.
       *
       * @param v target database(s)
       */
      public void setTargetDatabase(String v)
      {
          targetDatabase = v;
      }
      
      /**
       * The path to properties file containing db idiosyncrasies is
       * constructed by appending the "getTargetDatabase()/db.props
       * to this path.
       */
      public String getBasePathToDbProps() 
      {
          return basePathToDbProps;
      }
      
      /**
       * The path to properties file containing db idiosyncrasies is
       * constructed by appending the "getTargetDatabase()/db.props
       * to this path.
       */
      public void setBasePathToDbProps(String  v) 
      {
          this.basePathToDbProps = v;
      }
      
      /**
       * Set up the initialial context for generating the SQL from the XML schema.
       *
       * @return  Description of the Returned Value
       */
      public Context initControlContext() 
          throws Exception
      {
          if (xmlFile == null && filesets.isEmpty())
          {
              throw new BuildException("You must specify an XML schema or " +
                  "fileset of XML schemas!");
          }            
  
          if (xmlFile != null)
          {
              // Transform the XML database schema into
              // data model object.
              //dataModels.addElement(ad);
          } 
          else 
          { 
              // Deal with the filesets.
              for (int i = 0; i < filesets.size(); i++) 
              {
                  FileSet fs = (FileSet) filesets.elementAt(i);
                  DirectoryScanner ds = fs.getDirectoryScanner(project);
                  File srcDir = fs.getDir(project);
  
                  String[] dataModelFiles = ds.getIncludedFiles();
  
                  // Make a transaction for each file
                  for (int j = 0; j < dataModelFiles.length; j++)
                  {
                      //dataModels.addElement(ad);
                  }
              }
          }
          
          Iterator i = dataModels.iterator();
          databaseNames = new Hashtable();
          dataModelDbMap = new Hashtable();        
          
          // Different datamodels may state the same database
          // names, we just want the unique names of databases.
          
          /*
          while (i.hasNext())
          {
              AppData ad = (AppData) i.next();
              Database database = ad.getDatabase();
              databaseNames.put(database.getName(), database.getName());
              dataModelDbMap.put(ad.getName(), database.getName());
          }
          */
  
          // Create a new Velocity context.
          context = new VelocityContext();
          
          // Place our set of data models into the context along
          // with the names of the databases as a convenience for
          // now. 
          context.put("dataModels", dataModels);
          context.put("databaseNames", databaseNames);
      
          return context;
      }
  
      /**
       * Gets a name to use for the application's data model.
       *
       * @param xmlFile The path to the XML file housing the data model.
       * @return The name to use for the <code>AppData</code>.
       */
      private String grokName(String xmlFile)
      {
          // This can't be set from the file name as it is an unreliable
          // method of naming the descriptor. Not everyone uses the same
          // method as I do in the TDK. jvz.
  
          String name = "data-model";
          int i = xmlFile.lastIndexOf(System.getProperty("file.separator"));
          if (i != -1)
          {
              // Creep forward to the start of the file name.
              i++;
  
              int j = xmlFile.lastIndexOf('.');
              if (i < j)
              {
                  name = xmlFile.substring(i, j);
              }
              else
              {
                  // Weirdo
                  name = xmlFile.substring(i);
              }
          }
          return name;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/task/velocity/DataSQLTask.java
  
  Index: DataSQLTask.java
  ===================================================================
  package org.apache.commons.sql.task.velocity;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.util.List;
  import java.util.Properties;
  import org.apache.velocity.context.Context;
  
  import org.apache.commons.sql.model.Database;
  
  /**
   * An extended Texen task used for generating SQL source from an XML data file
   *
   * @author <a href="mailto:jason@zenplex.com"> Jason van Zyl </a>
   * @author <a href="mailto:jmcnally@collab.net"> John McNally </a>
   * @author <a href="mailto:fedor.karpelevitch@home.com"> Fedor Karpelevitch </a>
   * @version $Id: TorqueDataSQLTask.java,v 1.8 2002/04/11 22:02:06 mpoeschl Exp $
   */
  public class DataSQLTask 
      extends DataModelTask
  {
      private String dataXmlFile;
      private String dataDTD;
  
      /**
       * The target database(s) we are generating SQL for. Right now we can only
       * deal with a single target, but we will support multiple targets soon.
       */
      private String targetDatabase;
  
      /**
       * Sets the DataXmlFile attribute of the TorqueDataSQLTask object
       *
       * @param  dataXmlFile The new DataXmlFile value
       */
      public void setDataXmlFile(String dataXmlFile)
      {
          this.dataXmlFile = project.resolveFile(dataXmlFile).toString();
      }
  
      /**
       * Gets the DataXmlFile attribute of the TorqueDataSQLTask object
       *
       * @return  The DataXmlFile value
       */
      public String getDataXmlFile()
      {
          return dataXmlFile;
      }
  
      /**
       * Get the current target database.
       *
       * @return  String target database(s)
       */
      public String getTargetDatabase()
      {
          return targetDatabase;
      }
  
      /**
       * Set the current target database.  This is where generated java classes
       * will live.
       *
       * @param  v The new TargetDatabase value
       */
      public void setTargetDatabase(String v)
      {
          targetDatabase = v;
      }
  
      /**
       * Gets the DataDTD attribute of the TorqueDataSQLTask object
       *
       * @return  The DataDTD value
       */
      public String getDataDTD()
      {
          return dataDTD;
      }
  
      /**
       * Sets the DataDTD attribute of the TorqueDataSQLTask object
       *
       * @param  dataDTD The new DataDTD value
       */
      public void setDataDTD(String dataDTD)
      {
          this.dataDTD = project.resolveFile(dataDTD).toString();
      }
  
      /**
       * Set up the initialial context for generating the SQL from the XML schema.
       *
       * @return  Description of the Returned Value
       */
      public Context initControlContext()
          throws Exception
      {
          super.initControlContext();
          
          /*
          
          AppData app = (AppData) getDataModels().elementAt(0);
          Database db = app.getDatabase();
  
          try
          {
              XmlToData dataXmlParser = new XmlToData(db, dataDTD);
              List data = dataXmlParser.parseFile(dataXmlFile);
              context.put("data", data);
          }
          catch (Exception e)
          {
              throw new Exception("Exception parsing data XML:");
          }
  
          // Place our model in the context.
          context.put("appData", app);
  
          */
  
          Database db = null;
  
          // Place the target database in the context.
          context.put("targetDatabase", targetDatabase);
  
          Properties p = new Properties();
          FileInputStream fis = new FileInputStream(getSqlDbMap());
          p.load(fis);
          fis.close();
  
          p.setProperty(getOutputFile(), db.getName());
          p.store(new FileOutputStream(getSqlDbMap()), "Sqlfile -> Database map");
  
          return context;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/task/velocity/DataDTDTask.java
  
  Index: DataDTDTask.java
  ===================================================================
  package org.apache.commons.sql.task.velocity;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  /**
   * An extended Texen task used for generating data DTD from
   * an XML schema describing a database structure.
   *
   * @author <a href="mailto:fedor.karpelevitch@home.com"> Fedor Karpelevitch </a>
   * @author <a href="mailto:jvanzyl@zenplex.com">Jason van Zyl</a>
   * @version  $Id: TorqueDataDTDTask.java,v 1.3 2001/10/27 19:04:38 jvanzyl Exp $
   */
  public class DataDTDTask 
      extends DataModelTask
  {
  }
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/task/velocity/SQLTask.java
  
  Index: SQLTask.java
  ===================================================================
  package org.apache.commons.sql.task.velocity;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache Turbine" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.util.Properties;
  import java.util.Iterator;
  import org.apache.velocity.context.Context;
  import org.apache.velocity.VelocityContext;
  
  /**
   * An extended Texen task used for generating SQL source from
   * an XML schema describing a database structure.
   *
   * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
   * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
   * @version $Id: TorqueSQLTask.java,v 1.11 2002/04/10 21:08:43 dlr Exp $
   */
  public class SQLTask 
      extends DataModelTask
  {
      // if the database is set than all generated sql files
      // will be placed in the specified database, the database
      // will not be taken from the data model schema file.
  
      private String database;
      private String suffix = "";
      
      public void setDatabase(String database)
      {
          this.database = database;
      }
      
      public String getDatabase()
      {
          return database;
      }        
  
      public void setSuffix(String suffix)
      {
          this.suffix = suffix;
      }
      
      public String getSuffix()
      {
          return suffix;
      }        
  
      private void createSqlDbMap()
          throws Exception
      {
          if (getSqlDbMap() == null)
          {
              return;
          }        
          
          // Produce the sql -> database map
          Properties sqldbmap = new Properties();
          
          // Check to see if the sqldbmap has already been created.
          File file = new File(getSqlDbMap());
          
          if (file.exists())
          {
              FileInputStream fis = new FileInputStream(file);
              sqldbmap.load(fis);
              fis.close();
          }
          
          Iterator i = getDataModelDbMap().keySet().iterator();
          
          while (i.hasNext())
          {
              String dataModelName = (String) i.next();
              String sqlFile = dataModelName + suffix + ".sql";
              
              String databaseName;
              
              if (getDatabase() == null)
              {
                  databaseName = (String) getDataModelDbMap().get(dataModelName);
              }
              else
              {   
                  databaseName = getDatabase();
              }
              
              sqldbmap.setProperty(sqlFile,databaseName);
          }
          
          sqldbmap.store(new FileOutputStream(getSqlDbMap()),"Sqlfile -> Database map");
      }
  
      /**
       * Place our target database and target platform
       * values into the context for use in the
       * templates.
       */
      public Context initControlContext()
          throws Exception
      {   
          super.initControlContext();
          context.put("targetDatabase", getTargetDatabase());
          createSqlDbMap();
          return context;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/task/velocity/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
    <p>
    	This package contains all the 
    	<a href="http://jakarta.apache.org/ant/">Ant</a> Tasks which require
    	<a href="http://jakarta.apache.org/velocity/">Velocity</a> to function.
    </p>
  </body>
  </html>
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/task/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
    <p>
    	This package contains all the 
    	<a href="http://jakarta.apache.org/ant/">Ant</a> Tasks which allow 
    	commons-sql to be invoked from inside 
    	<a href="http://jakarta.apache.org/ant/">Ant</a> or 
    	<a href="http://jakarta.apache.org/Maven/">Maven</a> builds.
    </p>
  </body>
  </html>
  
  
  
  1.2       +115 -1    jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/MSSqlBuilder.java
  
  Index: MSSqlBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/MSSqlBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MSSqlBuilder.java	9 Sep 2002 18:15:03 -0000	1.1
  +++ MSSqlBuilder.java	10 Sep 2002 13:49:44 -0000	1.2
  @@ -1,12 +1,75 @@
  +/*
  + * $Header$
  + * $Revision$
  + * $Date$
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowlegement may appear in the software itself,
  + *    if and wherever such third-party acknowlegements normally appear.
  + *
  + * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  + *    Foundation" must not be used to endorse or promote products derived
  + *    from this software without prior written permission. For written
  + *    permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache"
  + *    nor may "Apache" appear in their names without prior written
  + *    permission of the Apache Group.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + * 
  + * $Id$
  + */
  +
   package org.apache.commons.sql.builder;
   
   import java.io.IOException;
  -import java.io.PrintWriter;
  +import java.io.Writer;
   import java.util.Iterator;
   import java.util.List;
   
   import org.apache.commons.sql.model.Column;
   import org.apache.commons.sql.model.Database;
  +import org.apache.commons.sql.model.ForeignKey;
   import org.apache.commons.sql.model.Table;
   
   /**
  @@ -18,5 +81,56 @@
   public class MSSqlBuilder extends SqlBuilder {
       
       public MSSqlBuilder() {
  +    }
  +    
  +    public void dropTable(Table table) throws IOException { 
  +        // this method is one example that might be a bit simpler if implemented in Velocity...
  +        
  +        String tableName = table.getName();
  +
  +        // drop the foreign key contraints
  +        int counter = 1;
  +        for (Iterator iter = table.getForeignKeys().iterator(); iter.hasNext(); ) {
  +            ForeignKey key = (ForeignKey) iter.next();
  +            
  +            String constraintName = tableName + "_FK_" + counter;
  +            println("IF EXISTS (SELECT 1 FROM sysobjects WHERE type ='RI' AND name='" 
  +                + constraintName + "'"
  +            );
  +            printIndent();
  +            print("ALTER TABLE " + tableName + " DROP CONSTRAINT " + constraintName );
  +            printEndOfStatement();
  +        }
  +        
  +        // now drop the table
  +        println( "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = '" + tableName + "')" );
  +        println( "BEGIN" );
  +        println( "     DECLARE @reftable nvarchar(60), @constraintname nvarchar(60)" );
  +        println( "     DECLARE refcursor CURSOR FOR" );
  +        println( "     select reftables.name tablename, cons.name constraitname" );
  +        println( "      from sysobjects tables," );
  +        println( "           sysobjects reftables," );
  +        println( "           sysobjects cons," );
  +        println( "           sysreferences ref" );
  +        println( "       where tables.id = ref.rkeyid" );
  +        println( "         and cons.id = ref.constid" );
  +        println( "         and reftables.id = ref.fkeyid" );
  +        println( "         and tables.name = '" + tableName + "'" );
  +        println( "     OPEN refcursor" );
  +        println( "     FETCH NEXT from refcursor into @reftable, @constraintname" );
  +        println( "     while @@FETCH_STATUS = 0" );
  +        println( "     BEGIN" );
  +        println( "       exec ('alter table '+@reftable+' drop constraint '+@constraintname)" );
  +        println( "       FETCH NEXT from refcursor into @reftable, @constraintname" );
  +        println( "     END" );
  +        println( "     CLOSE refcursor" );
  +        println( "     DEALLOCATE refcursor" );
  +        println( "     DROP TABLE " + tableName );
  +        print( "END" );
  +        printEndOfStatement();
  +    }
  +    
  +    protected void printAutoIncrementColumn() throws IOException { 
  +        print( "IDENTITY (1,1) " );
       }
   }
  
  
  
  1.3       +234 -146  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/SqlBuilder.java
  
  Index: SqlBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/SqlBuilder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SqlBuilder.java	9 Sep 2002 20:47:54 -0000	1.2
  +++ SqlBuilder.java	10 Sep 2002 13:49:44 -0000	1.3
  @@ -1,10 +1,13 @@
   package org.apache.commons.sql.builder;
   
   import java.io.IOException;
  -import java.io.PrintWriter;
  +import java.io.Writer;
   import java.util.Iterator;
   import java.util.List;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +
   import org.apache.commons.sql.model.Column;
   import org.apache.commons.sql.model.Database;
   import org.apache.commons.sql.model.ForeignKey;
  @@ -26,21 +29,33 @@
    * @version $Revision$
    */
   public class SqlBuilder {
  +
  +    /** The Log to which logging calls will be made. */
  +    private static final Log log = LogFactory.getLog(SqlBuilder.class);
       
  -    protected PrintWriter writer;
  +    /** The current Writer used to output the SQL to */
  +    private Writer writer;
       
  -    /** used for generating sequential constraints */
  -    protected int counter;
  +    /** A counter used to count the constraints */
  +    private int counter;
       
  -    public SqlBuilder() {
  -    }
  +    /** The indentation used to indent commands */
  +    private String indent = "    ";
       
  +    /** Whether or not primary key constraints are embedded inside the create table statement */
  +    private boolean primaryKeyEmbedded = true;
       
  +    /** Whether or not foreign key constraints are embedded inside the create table statement */
  +    private boolean foreignKeysEmbedded;
  +
  +    public SqlBuilder() {
  +    }
  +
       /**
        * Outputs the DDL required to drop and recreate the database 
        */
       public void createDatabase(Database database) throws IOException {
  -        for ( Iterator iter = database.getTables().iterator(); iter.hasNext(); ) {
  +        for (Iterator iter = database.getTables().iterator(); iter.hasNext(); ) {
               Table table = (Table) iter.next();
               tableComment(table);
               dropTable(table);
  @@ -52,7 +67,7 @@
        * Outputs the DDL required to drop the database 
        */
       public void dropDatabase(Database database) throws IOException {
  -        for ( Iterator iter = database.getTables().iterator(); iter.hasNext(); ) {
  +        for (Iterator iter = database.getTables().iterator(); iter.hasNext(); ) {
               Table table = (Table) iter.next();
               tableComment(table);
               dropTable(table);
  @@ -61,96 +76,140 @@
   
       /** 
        * Outputs a comment for the table
  -     */    
  -    public void tableComment(Table table) throws IOException { 
  -        writeComment(  "-----------------------------------------------------------------------" );
  -        writeComment(  table.getName() );
  -        writeComment(  "-----------------------------------------------------------------------" );
  -        writer.println();
  +     */
  +    public void tableComment(Table table) throws IOException {
  +        printComment("-----------------------------------------------------------------------");
  +        printComment(table.getName());
  +        printComment("-----------------------------------------------------------------------");
  +        println();
       }
  -    
   
       /**
        * Outputs the DDL to drop the table
        */
  -    public void dropTable(Table table) throws IOException { 
  -        writer.write( "drop table " );
  -        writer.write( table.getName() );
  -        writeEndOfStatement();
  +    public void dropTable(Table table) throws IOException {
  +        print("drop table ");
  +        print(table.getName());
  +        printEndOfStatement();
       }
  -    
  +
       /** 
        * Outputs the DDL to create the table along with any constraints
        */
  -    public void createTable(Table table) throws IOException { 
  -        writer.write( "create table " );
  -        writer.write( table.getName() );
  -        writer.println( " (" );
  +    public void createTable(Table table) throws IOException {
  +        print("create table ");
  +        println(table.getName());
  +        println("(");
   
           writeColumnTypes(table);
  -        
  +
           if (isPrimaryKeyEmbedded()) {
               writePrimaryKeys(table);
           }
           if (isForeignKeysEmbedded()) {
               writeForeignKeys(table);
           }
  -        writer.println();
  -        writer.write( ")" );
  -        writeEndOfStatement();
  -        
  -        if (! isPrimaryKeyEmbedded()) {
  +        println();
  +        print(")");
  +        printEndOfStatement();
  +
  +        if (!isPrimaryKeyEmbedded()) {
               writePrimaryKeysAlterTable(table);
           }
  -        if (! isForeignKeysEmbedded()) {
  +        if (!isForeignKeysEmbedded()) {
               writeForeignKeysAlterTable(table);
           }
       }
  -    
  +
       /** 
        * Outputs the DDL to add a column to a table.
        */
       public void createColumn(Column column) throws IOException {
  -        writer.write( column.getName() );
  -        writer.write( " " );
  -        writer.write( getSqlType( column ) );
  -        writer.write( " " );
  -        if ( column.isAutoIncrement() ) {
  -            writeAutoIncrementColumn();
  -        }
  -        if ( column.isRequired() ) {
  -            writer.write( "NOT NULL" );
  +        print(column.getName());
  +        print(" ");
  +        print(getSqlType(column));
  +        print(" ");
  +        if (column.isRequired()) {
  +            print("NOT NULL");
           }
           else {
  -            writer.write( "NULL" );
  +            print("NULL");
  +        }
  +        if (column.isAutoIncrement()) {
  +            printAutoIncrementColumn();
           }
       }
   
  -
       // Properties
       //-------------------------------------------------------------------------                
  -        
  +
       /**
  -     * Returns the writer.
  -     * @return PrintWriter
  +     * @return the Writer used to print the DDL to
        */
  -    public PrintWriter getWriter() {
  +    public Writer getWriter() {
           return writer;
       }
   
       /**
  -     * Sets the writer.
  -     * @param writer The writer to set
  +     * Sets the writer used to print the DDL to
        */
  -    public void setWriter(PrintWriter writer) {
  +    public void setWriter(Writer writer) {
           this.writer = writer;
       }
   
  +    /** 
  +     * @return the indentation used to indent the SQL
  +     */
  +    public String getIndent() {
  +        return indent;
  +    }
  +
  +    /**
  +     * Sets the indentation used to indent the SQL
  +     */
  +    public void setIndent(String indent) {
  +        this.indent = indent;
  +    }
  +
  +    /**
  +     * @return whether the primary key constraint is embedded in the create 
  +     * table clause or as a seperate alter table.
  +     * The default is true.
  +     */
  +    public boolean isPrimaryKeyEmbedded() {
  +        return primaryKeyEmbedded;
  +    }
  +
  +    /**
  +     * Sets whether the primary key constraint is embedded in the create 
  +     * table clause or as a seperate alter table.
  +     * The default is true.
  +     */
  +    public void setPrimaryKeyEmbedded(boolean primaryKeyEmbedded) {
  +        this.primaryKeyEmbedded = primaryKeyEmbedded;
  +    }
  +
  +    /**
  +     * @return whether the foreign key constraints are embedded in the create 
  +     * table clause or as a seperate alter table statements.
  +     * The default is false.
  +     */
  +    public boolean isForeignKeysEmbedded() {
  +        return foreignKeysEmbedded;
  +    }
  +
  +    /**
  +     * Sets whether the foreign key constraints are embedded in the create 
  +     * table clause or as a seperate alter table statements.
  +     * The default is false.
  +     */
  +    public void setForeignKeysEmbedded(boolean foreignKeysEmbedded) {
  +        this.foreignKeysEmbedded = foreignKeysEmbedded;
  +    }
   
       // Implementation methods
       //-------------------------------------------------------------------------                
  -        
  -    
  +
       /**
        * @return the full SQL type string including the size
        */
  @@ -160,128 +219,142 @@
   
       /**
        * Writes the column types for a table 
  -     */    
  +     */
       protected void writeColumnTypes(Table table) throws IOException {
  -        boolean first = true;        
  -        for (Iterator iter = table.getColumns().iterator(); iter.hasNext(); ) {
  +        boolean first = true;
  +        for (Iterator iter = table.getColumns().iterator(); iter.hasNext();) {
               Column column = (Column) iter.next();
               if (first) {
                   first = false;
               }
               else {
  -                writer.println(",");
  +                println(",");
               }
  -            writer.write( "  " );
  +            printIndent();
               createColumn(column);
           }
       }
  -    
  +
       /**
        * Writes the primary key constraints inside a create table () clause.
  -     */    
  +     */
       protected void writePrimaryKeys(Table table) throws IOException {
           List primaryKeyColumns = table.getPrimaryKeyColumns();
  -        if ( primaryKeyColumns.size() > 0 ) {
  -            writer.println( "," );
  +        if (primaryKeyColumns.size() > 0) {
  +            println(",");
  +            printIndent();
               writePrimaryKeyStatement(primaryKeyColumns);
           }
       }
  -    
  +
       /**
        * Writes the primary key constraints as an AlterTable clause.
  -     */    
  +     */
       protected void writePrimaryKeysAlterTable(Table table) throws IOException {
           List primaryKeyColumns = table.getPrimaryKeyColumns();
  -        if ( primaryKeyColumns.size() > 0 ) {
  -            writer.write( "ALTER TABLE " );
  -            writer.println( table.getName() );
  -            writer.write( "    ADD CONSTRAINT " );
  -            writer.write( table.getName() );
  -            writer.println( "_PK" );
  +        if (primaryKeyColumns.size() > 0) {
  +            print("ALTER TABLE ");
  +            println(table.getName());
  +
  +            printIndent();
  +            print("ADD CONSTRAINT ");
  +            print(table.getName());
  +            println("_PK");
               writePrimaryKeyStatement(primaryKeyColumns);
  -            writeEndOfStatement();
  -            writer.println();
  +            printEndOfStatement();
  +            println();
           }
       }
   
       /**
        * Writes the 'PRIMARY KEY(A,B,...,N)' statement
        */
  -    protected void writePrimaryKeyStatement(List primaryKeyColumns) throws IOException {
  -        writer.write( "PRIMARY KEY (" );
  -        
  +    protected void writePrimaryKeyStatement(List primaryKeyColumns)
  +        throws IOException {
  +        print("PRIMARY KEY (");
  +
           boolean first = true;
  -        for (Iterator iter = primaryKeyColumns.iterator(); iter.hasNext(); ) {
  +        for (Iterator iter = primaryKeyColumns.iterator(); iter.hasNext();) {
               Column column = (Column) iter.next();
               if (first) {
                   first = false;
               }
               else {
  -                writer.write(", " );
  +                print(", ");
               }
  -            writer.write(column.getName());
  +            print(column.getName());
           }
  -        writer.write( ")" );
  +        print(")");
       }
  -    
  +
       /**
        * Writes the foreign key constraints inside a create table () clause.
  -     */    
  +     */
       protected void writeForeignKeys(Table table) throws IOException {
  -        for (Iterator keyIter = table.getForeignKeys().iterator(); keyIter.hasNext(); ) {
  +        for (Iterator keyIter = table.getForeignKeys().iterator();
  +            keyIter.hasNext();
  +            ) {
               ForeignKey key = (ForeignKey) keyIter.next();
               if (key.getForeignTable() == null) {
  -                System.err.println( "WARN: foreign key table is null for key: " + key );
  +                System.err.println(
  +                    "WARN: foreign key table is null for key: " + key);
               }
               else {
  -                writer.println( "," );
  -    
  -                writer.write( "  CONSTRAINT " );
  -                writer.write( table.getName() );
  -                writer.write( "_FK_" );
  -                writer.write( Integer.toString(++counter) );
  -                writer.write( " FOREIGN KEY (" );            
  -                writeLocalReferences(key);            
  -                writer.write( key.getForeignTable() );
  -                writer.println( ")" );
  -                
  -                writer.write( "  REFERENCES " );
  -                writer.write( key.getForeignTable() );
  -                writer.write( " (" );
  +                println(",");
  +
  +                printIndent();
  +                print("CONSTRAINT ");
  +                print(table.getName());
  +                print("_FK_");
  +                print(Integer.toString(++counter));
  +                print(" FOREIGN KEY (");
  +                writeLocalReferences(key);
  +                print(key.getForeignTable());
  +                println(")");
  +
  +                printIndent();
  +                print("REFERENCES ");
  +                print(key.getForeignTable());
  +                print(" (");
                   writeForeignReferences(key);
  -                writer.println( ")" );
  +                println(")");
               }
           }
       }
   
       /**
        * Writes the foreign key constraints as an AlterTable clause.
  -     */    
  +     */
       protected void writeForeignKeysAlterTable(Table table) throws IOException {
           counter = 0;
  -        for (Iterator keyIter = table.getForeignKeys().iterator(); keyIter.hasNext(); ) {
  +        for (Iterator keyIter = table.getForeignKeys().iterator();
  +            keyIter.hasNext();
  +            ) {
               ForeignKey key = (ForeignKey) keyIter.next();
               if (key.getForeignTable() == null) {
  -                System.err.println( "WARN: foreign key table is null for key: " + key );
  +                System.err.println(
  +                    "WARN: foreign key table is null for key: " + key);
               }
               else {
  -                writer.write( "ALTER TABLE " );
  -                writer.println( table.getName() );
  -                
  -                writer.write( "  ADD CONSTRAINT " );
  -                writer.write( table.getName() );
  -                writer.write( "_FK_" );
  -                writer.write( Integer.toString(++counter) );
  -                writer.write( " FOREIGN KEY (" );            
  -                writeLocalReferences(key);            
  -                writer.println( ")" );
  -                
  -                writer.write( "  REFERENCES " );
  -                writer.write( key.getForeignTable() );
  -                writer.write( " (" );
  +                print("ALTER TABLE ");
  +                println(table.getName());
  +
  +                printIndent();
  +                print("ADD CONSTRAINT ");
  +                print(table.getName());
  +                print("_FK_");
  +                print(Integer.toString(++counter));
  +                print(" FOREIGN KEY (");
  +                writeLocalReferences(key);
  +                println(")");
  +
  +                printIndent();
  +                print("REFERENCES ");
  +                print(key.getForeignTable());
  +                print(" (");
                   writeForeignReferences(key);
  -                writer.println( ")" );
  -                writeEndOfStatement();
  +                println(")");
  +                printEndOfStatement();
               }
           }
       }
  @@ -291,73 +364,88 @@
        */
       protected void writeLocalReferences(ForeignKey key) throws IOException {
           boolean first = true;
  -        for (Iterator iter = key.getReferences().iterator(); iter.hasNext(); ) {
  +        for (Iterator iter = key.getReferences().iterator(); iter.hasNext();) {
               Reference reference = (Reference) iter.next();
               if (first) {
                   first = false;
               }
               else {
  -                writer.write( ", " );
  +                print(", ");
               }
  -            writer.write( reference.getLocal() );
  +            print(reference.getLocal());
           }
       }
  -            
  +
       /**
        * Writes a list of foreign references for the given key
        */
       protected void writeForeignReferences(ForeignKey key) throws IOException {
           boolean first = true;
  -        for (Iterator iter = key.getReferences().iterator(); iter.hasNext(); ) {
  +        for (Iterator iter = key.getReferences().iterator(); iter.hasNext();) {
               Reference reference = (Reference) iter.next();
               if (first) {
                   first = false;
               }
               else {
  -                writer.write( ", " );
  +                print(", ");
               }
  -            writer.write( reference.getForeign() );
  +            print(reference.getForeign());
           }
       }
  -            
  -    
  +   
  +   
  +    /**
  +     * Prints an SQL comment to the current stream
  +     */
  +    protected void printComment(String text) throws IOException {
  +        print("# ");
  +        println(text);
  +    }
  +
       /** 
  -     * Writes the end of statement text, which is typically a semi colon followed by 
  +     * Prints the end of statement text, which is typically a semi colon followed by 
        * a carriage return
        */
  -    protected void writeEndOfStatement() throws IOException {
  -        writer.println( ";" );
  -        writer.println();
  +    protected void printEndOfStatement() throws IOException {
  +        println(";");
  +        println();
       }
   
  +    /** 
  +     * Prints a new line
  +     */
  +    protected void println() throws IOException {
  +        print("\n");
  +    }
   
       /**
  -     * Write a comment to the DDL stream
  -     */    
  -    protected void writeComment(String text) throws IOException { 
  -        writer.write( "# " );
  -        writer.println( text );
  +     * Prints some text
  +     */
  +    protected void print(String text) throws IOException {
  +        writer.write(text);
       }
  -    
  +
       /**
  -     * Outputs that the current column is an auto increment
  +     * Prints some text then a newline
        */
  -    protected void writeAutoIncrementColumn() throws IOException { 
  +    protected void println(String text) throws IOException {
  +        print(text);
  +        println();
       }
  -    
  +
       /**
  -     * Should the primary key constraints be embedded inside the create table statement
  +     * Prints the indentation used to indent SQL
        */
  -    protected boolean isPrimaryKeyEmbedded() {
  -        return false;
  +    protected void printIndent() throws IOException {
  +        print(getIndent());
       }
  -    
  +
       /**
  -     * Should the foreign key constraints be embedded inside the create table statement
  -     */
  -    protected boolean isForeignKeysEmbedded() {
  -        return false;
  +     * Outputs the fact that this column is an auto increment column.
  +     */ 
  +    protected void printAutoIncrementColumn() throws IOException {
       }
  +
   
   
   }
  
  
  
  1.2       +74 -11    jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/OracleBuilder.java
  
  Index: OracleBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/OracleBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- OracleBuilder.java	9 Sep 2002 18:15:03 -0000	1.1
  +++ OracleBuilder.java	10 Sep 2002 13:49:44 -0000	1.2
  @@ -1,7 +1,69 @@
  +/*
  + * $Header$
  + * $Revision$
  + * $Date$
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowlegement may appear in the software itself,
  + *    if and wherever such third-party acknowlegements normally appear.
  + *
  + * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  + *    Foundation" must not be used to endorse or promote products derived
  + *    from this software without prior written permission. For written
  + *    permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache"
  + *    nor may "Apache" appear in their names without prior written
  + *    permission of the Apache Group.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + * 
  + * $Id$
  + */
  +
   package org.apache.commons.sql.builder;
   
   import java.io.IOException;
  -import java.io.PrintWriter;
  +import java.io.Writer;
   import java.util.Iterator;
   import java.util.List;
   
  @@ -18,20 +80,21 @@
   public class OracleBuilder extends SqlBuilder {
       
       public OracleBuilder() {
  +        setPrimaryKeyEmbedded(false);
       }
       
       public void dropTable(Table table) throws IOException { 
  -        writer.write( "drop table " );
  -        writer.write( table.getName() );
  -        writer.write( " CASCADE CONSTRAINTS" );
  -        writeEndOfStatement();
  -    }
  -    
  -    protected boolean isPrimaryKeyEmbedded() {
  -        return true;
  +        print( "drop table " );
  +        print( table.getName() );
  +        print( " CASCADE CONSTRAINTS" );
  +        printEndOfStatement();
       }
       
  -    protected boolean isForeignKeysEmbedded() {
  -        return true;
  +    protected void printComment(String text) throws IOException { 
  +        print( "--" );
  +        if (! text.startsWith( "-" ) ) {
  +            print(" ");
  +        }                
  +        println( text );
       }
   }
  
  
  
  1.2       +96 -5     jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/SybaseBuilder.java
  
  Index: SybaseBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/SybaseBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SybaseBuilder.java	9 Sep 2002 18:15:03 -0000	1.1
  +++ SybaseBuilder.java	10 Sep 2002 13:49:44 -0000	1.2
  @@ -1,12 +1,75 @@
  +/*
  + * $Header$
  + * $Revision$
  + * $Date$
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowlegement may appear in the software itself,
  + *    if and wherever such third-party acknowlegements normally appear.
  + *
  + * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  + *    Foundation" must not be used to endorse or promote products derived
  + *    from this software without prior written permission. For written
  + *    permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache"
  + *    nor may "Apache" appear in their names without prior written
  + *    permission of the Apache Group.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + * 
  + * $Id$
  + */
  +
   package org.apache.commons.sql.builder;
   
   import java.io.IOException;
  -import java.io.PrintWriter;
  +import java.io.Writer;
   import java.util.Iterator;
   import java.util.List;
   
   import org.apache.commons.sql.model.Column;
   import org.apache.commons.sql.model.Database;
  +import org.apache.commons.sql.model.ForeignKey;
   import org.apache.commons.sql.model.Table;
   
   /**
  @@ -20,9 +83,37 @@
       public SybaseBuilder() {
       }
       
  -    protected void writeComment(String text) throws IOException { 
  -        writer.write( "/* " );
  -        writer.write( text );
  -        writer.println( " */" );
  +    public void dropTable(Table table) throws IOException { 
  +        String tableName = table.getName();
  +
  +        // drop the foreign key contraints
  +        int counter = 1;
  +        for (Iterator iter = table.getForeignKeys().iterator(); iter.hasNext(); ) {
  +            ForeignKey key = (ForeignKey) iter.next();
  +            
  +            String constraintName = tableName + "_FK_" + counter;
  +            println("IF EXISTS (SELECT 1 FROM sysobjects WHERE type ='RI' AND name=''" 
  +                + constraintName + "')"
  +            );
  +            printIndent();
  +            print("ALTER TABLE " + tableName + " DROP CONSTRAINT " + constraintName );
  +            printEndOfStatement();
  +        }
  +        
  +        // now drop the table
  +        println( "IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = '" 
  +            + tableName + "')" 
  +        );
  +        println( "BEGIN" );
  +        printIndent();
  +        println( "DROP TABLE " + tableName );
  +        print( "END" );
  +        printEndOfStatement();
  +    }
  +
  +    protected void printComment(String text) throws IOException { 
  +        print( "/* " );
  +        print( text );
  +        println( " */" );
       }
   }
  
  
  
  1.2       +69 -6     jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/MySqlBuilder.java
  
  Index: MySqlBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/MySqlBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MySqlBuilder.java	9 Sep 2002 18:15:03 -0000	1.1
  +++ MySqlBuilder.java	10 Sep 2002 13:49:44 -0000	1.2
  @@ -1,7 +1,69 @@
  +/*
  + * $Header$
  + * $Revision$
  + * $Date$
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowlegement may appear in the software itself,
  + *    if and wherever such third-party acknowlegements normally appear.
  + *
  + * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  + *    Foundation" must not be used to endorse or promote products derived
  + *    from this software without prior written permission. For written
  + *    permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache"
  + *    nor may "Apache" appear in their names without prior written
  + *    permission of the Apache Group.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + * 
  + * $Id$
  + */
  +
   package org.apache.commons.sql.builder;
   
   import java.io.IOException;
  -import java.io.PrintWriter;
  +import java.io.Writer;
   import java.util.Iterator;
   import java.util.List;
   
  @@ -18,15 +80,16 @@
   public class MySqlBuilder extends SqlBuilder {
       
       public MySqlBuilder() {
  +        setForeignKeysEmbedded(true);
       }
       
       public void dropTable(Table table) throws IOException { 
  -        writer.write( "drop table if exists " );
  -        writer.write( table.getName() );
  -        writeEndOfStatement();
  +        print( "drop table if exists " );
  +        print( table.getName() );
  +        printEndOfStatement();
       }
       
  -    protected void writeAutoIncrementColumn() throws IOException { 
  -        writer.write( "AUTO_INCREMENT " );
  +    protected void printAutoIncrementColumn() throws IOException { 
  +        print( "AUTO_INCREMENT " );
       }
   }
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/builder/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
    <p>
    	This package contains classes to generate DDL and SQL for different database implementations.
    </p>
  </body>
  </html>
  
  
  
  1.2       +4 -31     jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/builder/TestBuilder.java
  
  Index: TestBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/builder/TestBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestBuilder.java	9 Sep 2002 18:15:03 -0000	1.1
  +++ TestBuilder.java	10 Sep 2002 13:49:44 -0000	1.2
  @@ -13,24 +13,19 @@
   import java.io.IOException;
   import java.io.FileInputStream;
   import java.io.FileWriter;
  -import java.io.PrintWriter;
   
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   import junit.textui.TestRunner;
   
  -import org.apache.commons.betwixt.XMLIntrospector;
  -import org.apache.commons.betwixt.io.BeanReader;
  -import org.apache.commons.betwixt.io.BeanWriter;
  -import org.apache.commons.betwixt.strategy.DecapitalizeNameMapper;
  -
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.commons.logging.impl.SimpleLog;
   
   import org.apache.commons.sql.builder.*;
   import org.apache.commons.sql.model.*;
  +import org.apache.commons.sql.io.DatabaseReader;
   
   /**
    * Test harness for the SqlBuilder for various databases.
  @@ -68,14 +63,11 @@
           super.setUp();
           
           baseDir = System.getProperty("basedir", ".");
  -        
           String uri = baseDir + "/src/test-input/datamodel.xml";
           
  -        BeanReader reader = new BeanReader();
  -        reader.setXMLIntrospector(createXMLIntrospector());
  -        reader.registerBeanClass(Database.class);
  -
  +        DatabaseReader reader = new DatabaseReader ();
           database = (Database) reader.parse(new FileInputStream(uri));
  +        
           assertTrue("Loaded a valid database", database != null);
       }
   
  @@ -94,30 +86,11 @@
       protected void testBuilder(SqlBuilder builder, String fileName) throws Exception 
       {
           String name = baseDir + "/target/" + fileName;
  -        PrintWriter writer = new PrintWriter( new FileWriter( name ) );
           
  +        FileWriter writer = new FileWriter( name );
           builder.setWriter( writer );
           builder.createDatabase( database );
           writer.close();
       }
  -    
  -    /**
  -     * ### it would be really nice to move this somewhere shareable across Maven
  -     * / Turbine projects. Maybe a static helper method - question is what to
  -     * call it???
  -     */
  -    protected XMLIntrospector createXMLIntrospector()
  -    {
  -        XMLIntrospector introspector = new XMLIntrospector();
  -
  -        // set elements for attributes to true
  -        introspector.setAttributesForPrimitives(false);
  -
  -        // turn bean elements into lower case
  -        introspector.setElementNameMapper(new DecapitalizeNameMapper());
  -
  -        return introspector;
  -    }
  -
   }
   
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/model/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
    <p>
    	The model objects that make up the logical model of the relational database.
    	These beans can then be used via Java code or inside bean templating engines like
    	<a href="http://jakarta.apache.org/velocity/">Velocity</a> or 
    	<a href="http://jakarta.apache.org/commons/sandbox/jelly/">Jelly</a>
    	to generate documentation or code etc.
    </p>
  </body>
  </html>
  
  
  
  1.2       +27 -80    jakarta-commons-sandbox/sql/src/test-input/datamodel.xml
  
  Index: datamodel.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/test-input/datamodel.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- datamodel.xml	31 Jul 2002 17:00:00 -0000	1.1
  +++ datamodel.xml	10 Sep 2002 13:49:46 -0000	1.2
  @@ -1,82 +1,29 @@
  -<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
  -<!DOCTYPE database SYSTEM "http://jakarta.apache.org/turbine/dtd/database.dtd">
  +<?xml version="1.0" encoding="ISO-8859-1"?>
  +
  +<database name="bookstore">
  +
  +  <!-- =================================================== -->
  +  <!-- B O O K  T A B L E                                  -->
  +  <!-- =================================================== -->
  +
  +  <table name="book">
  +    <column name="book_id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true"/>
  +    <column name="isbn" type="VARCHAR" size="15" required="true"/>
  +    <column name="author_id" type="INTEGER" required="true"/>
  +    <column name="title" type="VARCHAR" size="255" required="true"/>
  +	    
  +	  <foreign-key foreignTable="author">
  +	    <reference local="author_id" foreign="author_id"/>
  +	  </foreign-key>  
  +  </table>
  +
  +	<!-- =================================================== -->
  +  <!-- A U T H O R  T A B L E                              -->
  +  <!-- =================================================== -->
  +
  +  <table name="author">
  +    <column name="author_id" type="INTEGER" primaryKey="true" required="true"/>
  +    <column name="name" type="VARCHAR" size="50" required="true"/>
  +	</table>
   
  -<database>
  -  <name>bookstore</name>
  -  
  -  <tables>
  -  
  -    <!-- =================================================== -->
  -    <!-- B O O K  T A B L E                                  -->
  -    <!-- =================================================== -->
  -  
  -    <table>
  -      <name>book</name>
  -    
  -      <columns>
  -        <column>
  -          <name>book_id</name>
  -          <required>true</required>
  -          <primaryKey>true</primaryKey>
  -          <type>INTEGER</type>
  -        </column>
  -        
  -        <column>
  -          <name>isbn</name>
  -          <required>true</required>
  -          <type>VARCHAR</type>
  -          <size>15</size>
  -        </column>
  -        
  -        <column>
  -          <name>author_id</name>
  -          <required>true</required>
  -          <type>INTEGER</type>
  -        </column>
  -        
  -        <column>
  -          <name>title</name>
  -          <required>true</required>
  -          <type>VARCHAR</type>
  -          <size>255</size>
  -        </column>
  -      </columns>
  -    
  -      <!-- Same deal, maybe these should be defined outside the table? -->
  -      <foreignKeys>
  -        <foreignKey>
  -          <foreigntable>author</foreigntable>
  -          <reference>
  -            <local>author_id</local>
  -            <foreign>author_id</foreign>
  -          </reference>
  -        </foreignKey>
  -      </foreignKeys>
  -    </table>
  -
  -    <!-- =================================================== -->
  -    <!-- A U T H O R  T A B L E                              -->
  -    <!-- =================================================== -->
  -
  -    <table>
  -      <name>author</name>
  -    
  -      <columns>
  -        <column>
  -          <name>author_id</name>
  -          <required>true</required>
  -          <primaryKey>true</primaryKey>
  -          <type>INTEGER</type>
  -        </column>
  -        
  -        <column>
  -          <name>name</name>
  -          <required>true</required>
  -          <type>VARCHAR</type>
  -          <size>50</size>
  -        </column>
  -      </columns>
  -    </table>
  -  
  -  </tables>
   </database>
  
  
  
  1.2       +24 -32    jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/TestDataModelRoundTrip.java
  
  Index: TestDataModelRoundTrip.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/TestDataModelRoundTrip.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestDataModelRoundTrip.java	9 Sep 2002 13:47:57 -0000	1.1
  +++ TestDataModelRoundTrip.java	10 Sep 2002 13:49:46 -0000	1.2
  @@ -12,25 +12,23 @@
   import java.io.InputStream;
   import java.io.IOException;
   import java.io.FileInputStream;
  +import java.io.StringWriter;
  +import java.util.List;
   
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   import junit.textui.TestRunner;
   
  -import org.apache.commons.betwixt.XMLIntrospector;
  -import org.apache.commons.betwixt.io.BeanReader;
  -import org.apache.commons.betwixt.io.BeanWriter;
  -import org.apache.commons.betwixt.strategy.DecapitalizeNameMapper;
  -
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.commons.logging.impl.SimpleLog;
   
   import org.apache.commons.sql.model.*;
  +import org.apache.commons.sql.io.*;
   
   /**
  - * Test harness for the BeanReader that deals with project definitions.
  + * Test harness for the IO package
    *
    * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
    * @version $Revision$
  @@ -75,13 +73,11 @@
       /**
        * A unit test for JUnit
        */
  -    public void testBeanWriter()
  +    public void testDatabaseReader()
           throws Exception
       {
   
  -        BeanReader reader = new BeanReader();
  -        reader.setXMLIntrospector(createXMLIntrospector());
  -        reader.registerBeanClass(getBeanClass());
  +        DatabaseReader reader = new DatabaseReader();
           InputStream in = getXMLInput();
   
           try
  @@ -105,6 +101,21 @@
               assertEquals("isbn", c1.getName());
               assertTrue("isbn is required", c1.isRequired());
               assertTrue("isbn is not primary key", ! c1.isPrimaryKey());
  +
  +            List keyList0 = t0.getForeignKeys();
  +            assertEquals( "Foreign key count", 1, keyList0.size() );
  +            
  +            ForeignKey key0 = (ForeignKey) keyList0.get(0);
  +            assertEquals("foreignTable is correct", "author", key0.getForeignTable());
  +            
  +            List refList0 = key0.getReferences();
  +            assertEquals( "Reference count", 1, refList0.size() );
  +            
  +            Reference r0 = (Reference) refList0.get(0);
  +            assertTrue("Found a reference", r0 != null);
  +                        
  +            assertEquals("local is correct", "author_id", r0.getLocal());
  +            assertEquals("foreign is correct", "author_id", r0.getForeign());
               
               // Write out the bean
               //writeBean(database);
  @@ -129,9 +140,10 @@
       public void writeBean(Object bean)
           throws Exception
       {
  -        BeanWriter writer = new BeanWriter();
  -        writer.enablePrettyPrint();
  +        StringWriter buffer = new StringWriter();
  +        DatabaseWriter writer = new DatabaseWriter(buffer);
           writer.write(bean);
  +        String text = buffer.toString();
       }
   
       /**
  @@ -151,25 +163,5 @@
           //return getClass().getResourceAsStream("datamodel.xml");
           return new FileInputStream(TEST_DOCUMENT);
       }
  -
  -
  -    /**
  -     * ### it would be really nice to move this somewhere shareable across Maven
  -     * / Turbine projects. Maybe a static helper method - question is what to
  -     * call it???
  -     */
  -    protected XMLIntrospector createXMLIntrospector()
  -    {
  -        XMLIntrospector introspector = new XMLIntrospector();
  -
  -        // set elements for attributes to true
  -        introspector.setAttributesForPrimitives(false);
  -
  -        // turn bean elements into lower case
  -        introspector.setElementNameMapper(new DecapitalizeNameMapper());
  -
  -        return introspector;
  -    }
  -
   }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message