You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by to...@apache.org on 2004/07/18 23:55:58 UTC

cvs commit: jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/dynabean DynaSql.java

tomdz       2004/07/18 14:55:58

  Modified:    sql/src/java/org/apache/commons/sql/model Column.java
                        Table.java
               sql/src/java/org/apache/commons/sql/builder SqlBuilder.java
                        MySqlBuilder.java
               sql/src/java/org/apache/commons/sql/util DDLExecutor.java
               sql/src/test/org/apache/commons/sql/builder
                        TestEverything.java
               sql      build.xml build.properties
               sql/src/java/org/apache/commons/sql/io JdbcModelReader.java
                        DatabaseReader.java
               sql/src/java/org/apache/commons/sql/type Mapping.java
                        Types.java
               sql/src/java/org/apache/commons/sql/ddl
                        DefaultDatabaseMapper.java
               sql/src/test/org/apache/commons/sql/model TestColumn.java
               sql/src/java/org/apache/commons/sql/dynabean DynaSql.java
  Added:       sql/src/test/org/apache/commons/sql/builder
                        TestColumnTypes.java
               sql/src/java/org/apache/commons/sql/io
                        LocalEntityResolver.java
               sql/src/resources database.dtd
  Log:
  Added generation of insert/update/delete sql for dynabeans
  Fixed bug with size specification of decimal/numeric types
  Added javaName property to table and column
  Added database.dtd and entity resolver that uses it to avoid internet lookup
  
  Revision  Changes    Path
  1.12      +37 -8     jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/model/Column.java
  
  Index: Column.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/model/Column.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Column.java	28 Feb 2004 03:35:48 -0000	1.11
  +++ Column.java	18 Jul 2004 21:55:58 -0000	1.12
  @@ -19,12 +19,13 @@
   public class Column
   {
       private String name;
  +    private String javaName;
       private boolean primaryKey = false;
       private boolean required = false;
       private boolean autoIncrement = false;
       private int typeCode;
       private String type;
  -    private int size = 0;
  +    private String size = null;
       private String defaultValue = null;
       private int scale = 0;
       private int precisionRadix = 10;
  @@ -35,10 +36,11 @@
       }
   
   
  -    public Column(String name, int typeCode, int size, boolean required, boolean
  +    public Column(String name, String javaName, int typeCode, String size, boolean required, boolean
                     primaryKey, boolean autoIncrement, String defaultValue)
       {
           this.name = name;
  +        this.javaName = javaName;
           this.typeCode = typeCode;
           this.type = TypeMap.getJdbcTypeName(typeCode);
           this.size = size;
  @@ -48,17 +50,18 @@
           this.defaultValue = defaultValue;
       }
   
  -    public Column(String name, String type, int size, boolean required, boolean
  +    public Column(String name, String javaName, String type, String size, boolean required, boolean
                     primaryKey, boolean autoIncrement, String defaultValue  )
       {
  -        this(name, TypeMap.getJdbcTypeCode(type), size, required, primaryKey, autoIncrement, defaultValue);
  +        this(name, javaName, TypeMap.getJdbcTypeCode(type), size, required, primaryKey, autoIncrement, defaultValue);
       }
   
  -    public Column(String name, int typeCode, int size, boolean required, boolean
  +    public Column(String name, String javaName, int typeCode, String size, boolean required, boolean
                     primaryKey, boolean autoIncrement, String defaultValue,
                     int scale)
       {
           this.name = name;
  +        this.javaName = javaName;
           this.typeCode = typeCode;
           this.type = TypeMap.getJdbcTypeName(typeCode);
           this.size = size;
  @@ -77,6 +80,7 @@
       public String toStringAll()
       {
           return "Column[name=" + name +
  +            ";javaName=" + javaName +
               ";type=" + type +
               ";typeCode=" + typeCode +
               ";size=" + size +
  @@ -100,6 +104,16 @@
           this.name = name;
       }
   
  +    public String getJavaName()
  +    {
  +        return javaName;
  +    }
  +
  +    public void setJavaName(String javaName)
  +    {
  +        this.javaName = javaName;
  +    }
  +
       public boolean isPrimaryKey()
       {
           return primaryKey;
  @@ -155,16 +169,31 @@
           this.typeCode = TypeMap.getJdbcTypeCode(type);
       }
   
  -    public int getSize()
  +    public String getSize()
       {
           return size;
       }
   
  -    public void setSize(int size)
  +    public int getSizeAsInt()
       {
  -        this.size = size;
  +        return size == null ? 0 : Integer.parseInt(size);
       }
   
  +    public void setSize(String size)
  +    {
  +        int pos = size.indexOf(",");
  +
  +        if (pos < 0)
  +        {
  +            this.size = size;
  +        }
  +        else
  +        {
  +            this.size = size.substring(0, pos);
  +            scale     = Integer.parseInt(size.substring(pos + 1));
  +        }
  +    }
  +    
       public int getScale()
       {
           return this.scale;
  
  
  
  1.13      +12 -0     jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/model/Table.java
  
  Index: Table.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/model/Table.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Table.java	28 Feb 2004 03:35:48 -0000	1.12
  +++ Table.java	18 Jul 2004 21:55:58 -0000	1.13
  @@ -41,6 +41,8 @@
   
       private String name = null;
   
  +    private String javaName = null;
  +
       private String schema = null;
   
       private String remarks = null;
  @@ -105,6 +107,16 @@
       public void setName(String name)
       {
           this.name=name;
  +    }
  +
  +    public String getJavaName()
  +    {
  +        return javaName;
  +    }
  +
  +    public void setJavaName(String javaName)
  +    {
  +        this.javaName = javaName;
       }
   
       public void addColumn(Column column)
  
  
  
  1.18      +25 -6     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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SqlBuilder.java	15 Jul 2004 21:45:56 -0000	1.17
  +++ SqlBuilder.java	18 Jul 2004 21:55:58 -0000	1.18
  @@ -191,6 +191,16 @@
           }
       }
   
  +    /**
  +     * Determines whether this database reequires the specification of NULL as the default value.
  +     *  
  +     * @return Whether the database requires NULL for the default value
  +     */
  +    protected boolean requiresNullAsDefault()
  +    {
  +        return false;
  +    }
  +
       /** 
        * Outputs the DDL to add a column to a table.
        */
  @@ -209,7 +219,7 @@
           if (column.isRequired()) {
               printNotNullable();
           }
  -        else {
  +        else if (requiresNullAsDefault()) {
               printNullable();
           }
           print(" ");
  @@ -347,7 +357,7 @@
        */
       protected String getSqlType(Column column) {
           StringBuffer sqlType = new StringBuffer(getNativeType(column));
  -        if ( column.getSize() > 0 ) {
  +        if ( column.getSize() != null ) {
               sqlType.append(" (");
               sqlType.append(column.getSize());
               if ( TypeMap.isDecimalType(column.getType()) ){
  @@ -599,13 +609,22 @@
               print(reference.getForeign());
           }
       }
  -   
  -   
  +
  +    /**
  +     * Returns the string that denotes a comment if put at the beginning of a line.
  +     *  
  +     * @return The comment prefix
  +     */
  +    protected String getCommentPrefix()
  +    {
  +        return "--";
  +    }
  +
       /**
        * Prints an SQL comment to the current stream
        */
       protected void printComment(String text) throws IOException { 
  -        print( "--" );
  +        print(getCommentPrefix());
           
          // MySql insists on a space after the first 2 dashes.
          // http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#Comments
  @@ -950,7 +969,7 @@
           boolean defaultsEqual = desiredDefault == null ||
               desiredDefault.equals(currentDefault);
   
  -        boolean sizeMatters = desired.getSize() > 0;
  +        boolean sizeMatters = desired.getSize() != null;
   
           if ( desired.getTypeCode() != current.getTypeCode() ||
                   desired.isRequired() != current.isRequired() ||
  
  
  
  1.9       +36 -13    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MySqlBuilder.java	9 Jul 2004 12:53:19 -0000	1.8
  +++ MySqlBuilder.java	18 Jul 2004 21:55:58 -0000	1.9
  @@ -31,7 +31,8 @@
    * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
    * @version $Revision$
    */
  -public class MySqlBuilder extends SqlBuilder {
  +public class MySqlBuilder extends SqlBuilder
  +{
       private HashMap _specialTypes = new HashMap();
   
       public MySqlBuilder() {
  @@ -40,25 +41,44 @@
           _specialTypes.put("blob",          "LONGBLOB");
           _specialTypes.put("boolean",       "BIT");
           _specialTypes.put("clob",          "LONGTEXT");
  -        _specialTypes.put("float",         "DOUBLE");
  -        _specialTypes.put("longvarbinary", "MEDIUMBLOB");
  +        _specialTypes.put("float",         "FLOAT");
  +        _specialTypes.put("longvarbinary", "LONGBLOB");
           _specialTypes.put("longvarchar",   "MEDIUMTEXT");
           _specialTypes.put("real",          "FLOAT");
  -        _specialTypes.put("timestamp",     "DATETIME");
  -        _specialTypes.put("varbinary",     "BLOB");
  +        _specialTypes.put("varbinary",     "MEDIUMBLOB");
       }
  -    
  -    public void dropTable(Table table) throws IOException { 
  -        print( "drop table if exists " );
  -        print( table.getName() );
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.commons.sql.builder.SqlBuilder#getCommentPrefix()
  +     */
  +    protected String getCommentPrefix()
  +    {
  +        return "#";
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.commons.sql.builder.SqlBuilder#dropTable(Table)
  +     */
  +    public void dropTable(Table table) throws IOException
  +    { 
  +        print("drop table if exists ");
  +        print(table.getName());
           printEndOfStatement();
       }
  -    
  -    protected void printAutoIncrementColumn(Table table, Column column) throws IOException {
  -        print( "AUTO_INCREMENT" );
  +
  +    /* (non-Javadoc)
  +     * @see org.apache.commons.sql.builder.SqlBuilder#printAutoIncrementColumn(Table,Column)
  +     */
  +    protected void printAutoIncrementColumn(Table table, Column column) throws IOException
  +    {
  +        print("AUTO_INCREMENT");
       }
   
  -    protected boolean shouldGeneratePrimaryKeys(List primaryKeyColumns) {
  +    /* (non-Javadoc)
  +     * @see org.apache.commons.sql.builder.SqlBuilder#shouldGeneratePrimaryKeys(List)
  +     */
  +    protected boolean shouldGeneratePrimaryKeys(List primaryKeyColumns)
  +    {
           /*
            * mySQL requires primary key indication for autoincrement key columns
            * I'm not sure why the default skips the pk statement if all are identity
  @@ -66,6 +86,9 @@
           return true;
       }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.commons.sql.builder.SqlBuilder#getNativeType(Column)
  +     */
       protected String getNativeType(Column column){
           String type        = column.getType();
           String specialType = (String)_specialTypes.get(type.toLowerCase());
  
  
  
  1.6       +2 -1      jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/util/DDLExecutor.java
  
  Index: DDLExecutor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/util/DDLExecutor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DDLExecutor.java	28 Feb 2004 03:35:48 -0000	1.5
  +++ DDLExecutor.java	18 Jul 2004 21:55:58 -0000	1.6
  @@ -178,7 +178,8 @@
                           }
                       }
                       catch (SQLException e) {
  -                        log.error( "Command failed: " + command + ". Reason: " + e );
  +                        log.error("Command " + command + " failed", e);
  +                        System.err.println("Command " + command + " failed with " + e);
                           errors++;
                       }
                   }
  
  
  
  1.2       +3 -3      jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/builder/TestEverything.java
  
  Index: TestEverything.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/builder/TestEverything.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestEverything.java	16 Dec 2003 16:03:07 -0000	1.1
  +++ TestEverything.java	18 Jul 2004 21:55:58 -0000	1.2
  @@ -190,7 +190,7 @@
   
   
           //check adding column with default
  -        Column newCol = new Column( "defaulted", Types.INTEGER, 11, true, false, false, "50" );
  +        Column newCol = new Column("defaulted", "defaulted", Types.INTEGER, "11", true, false, false, "50");
           table.addColumn( newCol );
           updateDatabase( db, false );
   
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/builder/TestColumnTypes.java
  
  Index: TestColumnTypes.java
  ===================================================================
  package org.apache.commons.sql.builder;
  
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2003 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 acknowledgement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgement may appear in the software itself,
   *    if and wherever such third-party acknowledgements 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 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.beans.IntrospectionException;
  import java.io.*;
  import java.util.*;
  
  import org.apache.commons.sql.io.DatabaseReader;
  import org.apache.commons.sql.model.Database;
  import org.xml.sax.SAXException;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * Tests the jdbc type<->column type mapping.
   */
  public class TestColumnTypes extends TestCase
  {
      /** Path of the mappings file */
      private static final String MAPPING_FILE = "src/test-input/jdbc-type-mappings.csv";
  
      /** The mappings (one hashmap per database) */
      private static HashMap _mappingPerDB = new HashMap();
      /** The number of tests to run */
      private static int _numTests;
      /** The iterator over the database names */
      private static Iterator _curDBIt;
      /** The name of the current db */
      private static String _dbName;
      /** The iterator over the jdbc type names (per db) */
      private static Iterator _curJdbcTypeIt;
      
      /**
       * Reads the mappings fro an external CSV file that contains the mapping in the form:
       * Jdbc Type;Database 1;Database 2;...
       * 
       * @param filename The filename
       * @throws IOException If an i/o error happened
       */
      private static void loadMappings(String filename) throws IOException
      {
          BufferedReader input   = new BufferedReader(new FileReader(filename));
          ArrayList      dbs     = new ArrayList();
          boolean        isFirst = true;
          HashMap        mapping;
          String         line, jdbcType, dbName;
  
          _mappingPerDB.clear();
          _numTests = 0;
          while ((line = input.readLine()) != null)
          {
              StringTokenizer tokenizer = new StringTokenizer(line, ";");
  
              if (isFirst)
              {
                  // skipping first token
                  tokenizer.nextToken();
                  while (tokenizer.hasMoreTokens())
                  {
                      dbName  = tokenizer.nextToken().trim();
                      mapping = new HashMap();
                      _mappingPerDB.put(dbName, mapping);
                      dbs.add(mapping);
                  }
                  isFirst = false;
              }
              else
              {
                  jdbcType = tokenizer.nextToken().trim();
                  for (int idx = 0; tokenizer.hasMoreTokens() && (idx < dbs.size()); idx++)
                  {
                      mapping = (HashMap)dbs.get(idx);
                      mapping.put(jdbcType, tokenizer.nextToken().trim());
                      _numTests++;
                  }
              }
          }
      }
  
      /**
       * Creates the test suite.
       * 
       * @return The test suite
       */
      public static Test suite() throws IOException
      {
          loadMappings(MAPPING_FILE);
  
          TestSuite suite = new TestSuite();
  
          // we're running the same test method over and over again, but each time it
          // tests a different db or jdbc type
          for (int idx = 0; idx < _numTests; idx++)
          {
              suite.addTest(new TestColumnTypes("testColumnType"));
          }
          _curDBIt       = _mappingPerDB.keySet().iterator();
          _dbName        = (String)_curDBIt.next();
          _curJdbcTypeIt = ((HashMap)_mappingPerDB.get(_dbName)).keySet().iterator();
          return suite;
      }
  
      public TestColumnTypes(String name)
      {
          super(name);
      }
  
      public void testColumnType() throws IntrospectionException, SAXException, IOException, InstantiationException, IllegalAccessException
      {
          if (!_curJdbcTypeIt.hasNext())
          {
              _dbName        = (String)_curDBIt.next();
              _curJdbcTypeIt = ((HashMap)_mappingPerDB.get(_dbName)).keySet().iterator();
          }
  
          String jdbcType   = (String)_curJdbcTypeIt.next();
          String columnType = (String)((HashMap)_mappingPerDB.get(_dbName)).get(jdbcType);
          String dbDef      = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
                              "<database name=\"columntest\">\n" +
                              "<table name=\"coltype\">\n" +
                              "<column name=\"TEST_COLUMN\" primaryKey=\"false\" required=\"false\" type=\""+jdbcType+"\"/>\n" +
                              "</table>\n" +
                              "</database>";
  
          DatabaseReader reader   = new DatabaseReader();
          Database       database = (Database)reader.parse(new StringReader(dbDef));
          StringWriter   writer   = new StringWriter();
          SqlBuilder     builder  = SqlBuilderFactory.newSqlBuilder(_dbName);
  
          builder.setWriter(writer);
          builder.createDatabase(database, true);
  
          String createdSql = writer.getBuffer().toString();
          int    typePos    = createdSql.indexOf("TEST_COLUMN") + "TEST_COLUMN".length();
  
          assertEquals(columnType,
                       createdSql.substring(typePos).trim().substring(0, columnType.length()));
                      
      }
  }
  
  
  
  1.8       +4 -2      jakarta-commons-sandbox/sql/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/build.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- build.xml	17 Jul 2004 10:27:22 -0000	1.7
  +++ build.xml	18 Jul 2004 21:55:58 -0000	1.8
  @@ -53,9 +53,11 @@
       <target name="jar"
               description="Creates the jar"
               depends="compile">
  +        <copy todir="${build.java.dir}/resources">
  +            <fileset dir="${src.resources.dir}"/>
  +        </copy>
           <jar jarfile="${dist.dir}/${dist-filename-prefix}.jar"
  -            basedir="${build.java.dir}"
  -             includes="org/**"/>
  +             basedir="${build.java.dir}"/>
       </target>
   
       <target name="clean"
  
  
  
  1.2       +1 -0      jakarta-commons-sandbox/sql/build.properties
  
  Index: build.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/build.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.properties	17 Jul 2004 10:27:22 -0000	1.1
  +++ build.properties	18 Jul 2004 21:55:58 -0000	1.2
  @@ -17,6 +17,7 @@
   src.dir=src
   src.java.dir=${src.dir}/java
   src.test.dir=${src.dir}/test
  +src.resources.dir=${src.dir}/resources
   
   build.dir=target
   build.java.dir=${build.dir}/classes
  
  
  
  1.7       +7 -7      jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/io/JdbcModelReader.java
  
  Index: JdbcModelReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/io/JdbcModelReader.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JdbcModelReader.java	28 Feb 2004 03:35:48 -0000	1.6
  +++ JdbcModelReader.java	18 Jul 2004 21:55:58 -0000	1.7
  @@ -238,17 +238,17 @@
                    * number of characters, for numeric or decimal types this is 
                    * precision.
                    */
  -                int columnSize =
  +                String columnSize =
                       columnInfoColumns.contains("COLUMN_SIZE")
  -                        ? columnData.getInt("COLUMN_SIZE")
  -                        : 0;
  +                        ? columnData.getString("COLUMN_SIZE")
  +                        : null;
                   /* the number of fractional digits */
  -                int columnDecimalDigits =
  +                int columnScale =
                       columnInfoColumns.contains("DECIMAL_DIGITS")
                           ? columnData.getInt("DECIMAL_DIGITS")
                           : 0;
                   /* Radix (typically either 10 or 2) */
  -                int columnRadix =
  +                int columnPrecision =
                       columnInfoColumns.contains("NUM_PREC_RADIX")
                           ? columnData.getInt("NUM_PREC_RADIX")
                           : 10;
  @@ -344,8 +344,8 @@
                   else {
                       col.setPrimaryKey(false);
                   }
  -                col.setPrecisionRadix(columnRadix);
  -                col.setScale(columnDecimalDigits);
  +                col.setPrecisionRadix(columnPrecision);
  +                col.setScale(columnScale);
                   columns.add(col);
               }
               return columns;
  
  
  
  1.5       +34 -2     jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/io/DatabaseReader.java
  
  Index: DatabaseReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/io/DatabaseReader.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DatabaseReader.java	28 Feb 2004 03:35:48 -0000	1.4
  +++ DatabaseReader.java	18 Jul 2004 21:55:58 -0000	1.5
  @@ -30,11 +30,43 @@
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision$
    */
  -public class DatabaseReader extends BeanReader {
  -    
  +public class DatabaseReader extends BeanReader
  +{
  +    /** Whether to use the internal dtd that comes with commons-sql */
  +    private boolean _useInternalDtd = false;
  +
       public DatabaseReader() throws IntrospectionException {
           setXMLIntrospector( newXMLIntrospector() );
           registerBeanClass(Database.class);
  +        setValidating(false);
  +    }
  +
  +    /**
  +     * Returns whether the internal dtd that comes with commons-sql is used.
  +     * 
  +     * @return <code>true</code> if parsing uses the internal dtd
  +     */
  +    public boolean isUseInternalDtd()
  +    {
  +        return _useInternalDtd;
  +    }
  +
  +    /**
  +     * Specifies whether the internal dtd is to be used.
  +     *
  +     * @param useInternalDtd Whether to use the internal dtd 
  +     */
  +    public void setUseInternalDtd(boolean useInternalDtd)
  +    {
  +        _useInternalDtd = useInternalDtd;
  +        if (_useInternalDtd)
  +        {
  +            setEntityResolver(new LocalEntityResolver());
  +        }
  +        else
  +        {
  +            setEntityResolver(this);
  +        }
       }
   
       /**
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/io/LocalEntityResolver.java
  
  Index: LocalEntityResolver.java
  ===================================================================
  package org.apache.commons.sql.io;
  
  /*
   * Copyright 1999-2002,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import java.io.FileInputStream;
  import java.io.InputStream;
  import java.net.URL;
  
  import org.xml.sax.EntityResolver;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  /**
   * An entity resolver that matches the specific database dtds to the one that comes
   * with commons-sql, and that can handle file url's.
   * 
   * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
   */
  public class LocalEntityResolver implements EntityResolver
  {
      private static final String DTD_PREFIX = "http://db.apache.org/torque/dtd/database";
  
      /* (non-Javadoc)
       * @see org.xml.sax.EntityResolver#resolveEntity(java.lang.String, java.lang.String)
       */
      public InputSource resolveEntity(String publicId, String systemId) throws SAXException
      {
          InputSource result = null;
  
          if (systemId.startsWith(DTD_PREFIX))
          {
              InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("resources/database.dtd");
  
              if (input != null)
              {
                  result = new InputSource(input);
              }
          }
          else if (systemId.startsWith("file:"))
          {
              try
              {
                  URL url = new URL(systemId);
  
                  if ("file".equals(url.getProtocol()))
                  {
                      String path = systemId.substring("file:".length());
  
                      if (path.startsWith("//"))
                      {
                          path = path.substring(2);
                      }
                      result = new InputSource(new FileInputStream(path));
                  }
                  else
                  {
                      result = new InputSource(url.openStream());
                  }
              }
              catch (Exception ex)
              {
                  throw new SAXException(ex);
              }
          }
          return result;
      }
  }
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/type/Mapping.java
  
  Index: Mapping.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/type/Mapping.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Mapping.java	5 Feb 2003 08:08:37 -0000	1.1
  +++ Mapping.java	18 Jul 2004 21:55:58 -0000	1.2
  @@ -7,7 +7,7 @@
    * This class describes a mapping between a standard JDBC type and the 
    * provider specific implementation of that type.
    * 
  - * @version     $Revision$ $Date$
  + * @version     1.1 2003/02/05 08:08:37
    * @author      <a href="mailto:tima@intalio.com">Tim Anderson</a>
    */
   public class Mapping {
  @@ -77,7 +77,7 @@
   
       public String getSQLType(Column column) {
           StringBuffer result = new StringBuffer(sqlName);
  -        int size = column.getSize();
  +        int size = column.getSizeAsInt();
           int scale = column.getScale();
           if (SIZE_FORMAT.equals(format)) {
               if (size > 1) {
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/type/Types.java
  
  Index: Types.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/type/Types.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Types.java	5 Feb 2003 08:08:37 -0000	1.1
  +++ Types.java	18 Jul 2004 21:55:58 -0000	1.2
  @@ -15,7 +15,7 @@
    * Manages the set of types supported by a database provider, 
    * and the mappings from standard JDBC types to the provider types.
    * 
  - * @version     $Revision$ $Date$
  + * @version     1.1 2003/02/05 08:08:37
    * @author      <a href="mailto:tima@intalio.com">Tim Anderson</a>
    */
   public class Types {
  @@ -265,7 +265,7 @@
       public String getSQLType(Column column) {
           String result = null;
           TypeMapping mapping = getTypeMapping(column.getType(), 
  -                                             column.getSize());
  +                                             column.getSizeAsInt());
           if (mapping != null) {
               result = mapping.getSQLType(column);
           }
  
  
  
  1.1                  jakarta-commons-sandbox/sql/src/resources/database.dtd
  
  Index: database.dtd
  ===================================================================
  <!--
      Torque XML database schema DTD
      $Id: database.dtd,v 1.13 2002/06/20 23:55:14 jmcnally Exp $
  -->
  
  <!--
  For: database.defaultIdMethod and table.idMethod
  
  Do not use autoincrement or sequence. They are deprecated in favor of
  using native which will use the Turbine Connection pool to determine
  which database it is talking to (yes, it knows that) and then use
  whatever native database methodology for insert increments that it can.
  Otherwise, you should use idbroker or none. none is good if you have a
  table that is just a join table. idbroker is good if you want a
  centralized repository for brokering out clumps of id's in a database
  agnostic way.
  -->
  
  <!--
  
  defaultJavaNamingMethod determines how a table or column name,
  from the name attribute in the xml database file, is converted to a
  Java class or method name.
  
       nochange   - indicates not change is performed.
       underscore - Underscores are removed, First letter is
                capitalized, first letter after an underscore
                is capitalized, the rest of the letters are
                converted to lowercase.
       javaname   - same as underscore, but no letters are converted
                to lowercase.
  -->
  
  <!ELEMENT database (external-schema*, table+)>
  <!ATTLIST database
    name CDATA #IMPLIED
    defaultIdMethod (idbroker|native|autoincrement|sequence|none) "none"
    defaultJavaType (object|primitive) "primitive"
    package CDATA #IMPLIED
    baseClass CDATA #IMPLIED
    basePeer CDATA #IMPLIED
    defaultJavaNamingMethod (nochange|underscore|javaname) "underscore"
    heavyIndexing (true|false) "false"
  >
  
  <!ELEMENT external-schema EMPTY>
  <!ATTLIST external-schema
    filename CDATA #REQUIRED
  >
  
  <!-- 
       note: the interface="true", requires that useManagers=true in the
       properties file. 
  -->
  <!ELEMENT table (column+,(foreign-key|index|unique|id-method-parameter)*)>
  <!ATTLIST table
    name CDATA #REQUIRED
    javaName CDATA #IMPLIED
    idMethod (idbroker|native|autoincrement|sequence|none|null) "null"
    skipSql (true|false) "false"
    abstract (true|false) "false"
    baseClass CDATA #IMPLIED
    basePeer CDATA #IMPLIED
    alias CDATA #IMPLIED
    interface CDATA #IMPLIED
    javaNamingMethod (nochange|underscore|javaname) #IMPLIED
    heavyIndexing (true|false) #IMPLIED
    description CDATA #IMPLIED
  >
  
  <!ELEMENT id-method-parameter EMPTY>
  <!ATTLIST id-method-parameter
    name CDATA "default"
    value CDATA #REQUIRED
  >
  
  <!ELEMENT column (inheritance*)>
  <!ATTLIST column
    name CDATA #REQUIRED
    javaName CDATA #IMPLIED
    primaryKey (true|false) "false"
    required (true|false) "false"
    type
      (
            BIT  | TINYINT | SMALLINT    | INTEGER    | BIGINT    | FLOAT
          | REAL | NUMERIC | DECIMAL     | CHAR       | VARCHAR   | LONGVARCHAR
          | DATE | TIME    | TIMESTAMP   | BINARY     | VARBINARY | LONGVARBINARY
          | NULL | OTHER   | JAVA_OBJECT | DISTINCT   | STRUCT    | ARRAY
          | BLOB | CLOB    | REF         | BOOLEANINT | BOOLEANCHAR
          | DOUBLE
      ) "VARCHAR"
    javaType (object|primitive) #IMPLIED
    size CDATA #IMPLIED
    default CDATA #IMPLIED
    autoIncrement (true|false) "false"
    inheritance (single|false) "false"
    inputValidator CDATA #IMPLIED
    javaNamingMethod (nochange|underscore|javaname) #IMPLIED
    description CDATA #IMPLIED
  >
  
  <!ELEMENT inheritance EMPTY>
  <!ATTLIST inheritance
    key CDATA #REQUIRED
    class CDATA #REQUIRED
    extends CDATA #IMPLIED
  >
  
  <!ELEMENT foreign-key (reference+)>
  <!ATTLIST foreign-key
    foreignTable CDATA #REQUIRED
    name CDATA #IMPLIED
    onUpdate (cascade|setnull|restrict|none) "none"
    onDelete (cascade|setnull|restrict|none) "none"
  >
  
  <!ELEMENT reference EMPTY>
  <!ATTLIST reference
    local CDATA #REQUIRED
    foreign CDATA #REQUIRED
  >
  
  <!ELEMENT index (index-column+)>
  <!ATTLIST index
    name CDATA #IMPLIED
  >
  
  <!ELEMENT index-column EMPTY>
  <!ATTLIST index-column
    name CDATA #REQUIRED
    size CDATA #IMPLIED
  >
  
  <!ELEMENT unique (unique-column+)>
  <!ATTLIST unique
    name CDATA #IMPLIED
  >
  
  <!ELEMENT unique-column EMPTY>
  <!ATTLIST unique-column
    name CDATA #REQUIRED
  >
  
  
  
  1.3       +5 -5      jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/ddl/DefaultDatabaseMapper.java
  
  Index: DefaultDatabaseMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/ddl/DefaultDatabaseMapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultDatabaseMapper.java	30 Apr 2003 11:27:26 -0000	1.2
  +++ DefaultDatabaseMapper.java	18 Jul 2004 21:55:58 -0000	1.3
  @@ -53,7 +53,7 @@
       protected void mapColumn(Table table, Column column) throws SQLException {
           Types types = getTypes();
           String name = column.getType();
  -        int size = column.getSize();
  +        int size = column.getSizeAsInt();
           
           TypeMapping mapping = types.getTypeMapping(name, size);
           if (mapping == null) {
  @@ -62,7 +62,7 @@
           if (mapping == null) {
               throw new SQLException("Column not supported: " + column);
           }
  -        if (mapping.getSize() != 0 && column.getSize() > mapping.getSize()) {
  +        if (mapping.getSize() != 0 && column.getSizeAsInt() > mapping.getSize()) {
               // if the target type specifies a size of zero, and the
               // requested column specifies > 0, just ignore - assume that
               // the type has unlimited size
  @@ -77,7 +77,7 @@
   
           Column column = table.getAutoIncrementColumn();
           String name = column.getType();
  -        int size = column.getSize();
  +        int size = column.getSizeAsInt();
   
           if (!types.getAutoIncrementMappings().isEmpty()) {
               // database provider supports auto-increment columns - 
  @@ -117,8 +117,8 @@
       protected void promoteColumn(Table table, Column column, 
                                    TypeMapping mapping) {
           column.setType(mapping.getName());
  -        if (mapping.getSize() < column.getSize()) {
  -            column.setSize((int) mapping.getSize()); 
  +        if (mapping.getSize() < column.getSizeAsInt()) {
  +            column.setSize(String.valueOf(mapping.getSize())); 
               // @todo - oracle returns column sizes of type long
           }
           
  
  
  
  1.7       +3 -3      jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/model/TestColumn.java
  
  Index: TestColumn.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/test/org/apache/commons/sql/model/TestColumn.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestColumn.java	28 Feb 2004 03:35:49 -0000	1.6
  +++ TestColumn.java	18 Jul 2004 21:55:58 -0000	1.7
  @@ -65,7 +65,7 @@
       public void testColumn()
           throws Exception
       {
  -        Column column = new Column("Test1",Types.INTEGER,255,true,true,true,"");
  +        Column column = new Column("Test1", "Test1",Types.INTEGER,"255",true,true,true,"");
           assertTrue("Column is null", column != null);
           assertTrue("Column toString does not end with [name=Test1;type=INTEGER]", 
                  ((String)column.toString()).endsWith("[name=Test1;type=INTEGER]"));
  @@ -76,7 +76,7 @@
       public void testTypeName()
           throws Exception
       {
  -        Column column = new Column("Test1","INTEGER",0, true,true,true,"");
  +        Column column = new Column("Test1","Test1", "INTEGER","0", true,true,true,"");
           
           assertEquals("INTEGER", column.getType());                           
           assertEquals(Types.INTEGER, column.getTypeCode());
  
  
  
  1.12      +134 -53   jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/dynabean/DynaSql.java
  
  Index: DynaSql.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/sql/src/java/org/apache/commons/sql/dynabean/DynaSql.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DynaSql.java	28 Feb 2004 03:35:48 -0000	1.11
  +++ DynaSql.java	18 Jul 2004 21:55:58 -0000	1.12
  @@ -57,10 +57,11 @@
       /** A cache of the SqlDynaClasses per table name */
       private Map dynaClassCache = new HashMap();
   
  -    public DynaSql() {
  -    }
  +    public DynaSql()
  +    {}
   
  -    public DynaSql(DataSource dataSource, Database database) {
  +    public DynaSql(DataSource dataSource, Database database)
  +    {
           super(dataSource);
           this.database = database;
       }
  @@ -196,6 +197,27 @@
           }
       }
   
  +
  +    /**
  +     * Returns the sql for inserting the bean.
  +     * 
  +     * @param dynaBean The bean
  +     * @return The sql
  +     */
  +    public String getInsertSql(DynaBean dynaBean)
  +    {
  +        SqlDynaClass      dynaClass  = getSqlDynaClass(dynaBean);
  +        SqlDynaProperty[] properties = dynaClass.getSqlDynaProperties();
  +
  +        if (properties.length == 0)
  +        {
  +            log.info("Cannot insert type " + dynaClass + " as there are no properties");
  +            return null;
  +        }
  +
  +        return createInsertSql(dynaClass, properties);
  +    }
  +
       /**
        * Inserts the given DynaBean in the database, assuming the primary key values are specified.
        */
  @@ -210,6 +232,26 @@
       }
   
       /**
  +     * Returns the sql for updating the given bean in the database.
  +     * 
  +     * @param dynaBean The bean
  +     * @return The sql
  +     */
  +    public String getUpdateSql(DynaBean dynaBean)
  +    {
  +        SqlDynaClass      dynaClass   = getSqlDynaClass(dynaBean);
  +        SqlDynaProperty[] primaryKeys = dynaClass.getPrimaryKeyProperties();
  +
  +        if (primaryKeys.length == 0)
  +        {
  +            log.info("Cannot update type " + dynaClass + " as there are no primary keys to update");
  +            return null;
  +        }
  +
  +        return createUpdateSql(dynaClass, primaryKeys, dynaClass.getNonPrimaryKeyProperties());
  +    }
  +
  +    /**
        * Updates the given DynaBean in the database, assuming the primary key values are specified.
        */
       public void update(DynaBean dynaBean) throws SQLException {
  @@ -233,7 +275,7 @@
               SqlDynaProperty[] primaryKeys = dynaClass.getPrimaryKeyProperties();
               int size = primaryKeys.length;
               if (size == 0) {
  -                log.info( "Cannot update type: " + dynaClass + " as there are no primary keys to update" );
  +                log.info( "Cannot delete type " + dynaClass + " as there are no primary keys" );
                   return;
               }
               String sql = createDeleteSql(dynaClass, primaryKeys);
  @@ -262,6 +304,25 @@
           }
       }
   
  +    /**
  +     * Returns the sql for deleting the given DynaBean from the database.
  +     * 
  +     * @param dynaBean The bean
  +     * @return The sql
  +     */
  +    public String getDeleteSql(DynaBean dynaBean)
  +    {
  +        SqlDynaClass      dynaClass   = getSqlDynaClass(dynaBean);
  +        SqlDynaProperty[] primaryKeys = dynaClass.getPrimaryKeyProperties();
  +
  +        if (primaryKeys.length == 0)
  +        {
  +            log.warn("Cannot delete type " + dynaClass + " as there are no primary keys");
  +            return null;
  +        }
  +
  +        return createDeleteSql(dynaClass, primaryKeys);
  +    }
   
       // Properties
       //-------------------------------------------------------------------------
  @@ -297,85 +358,105 @@
       }
   
       /**
  -     * Creates a new primary key value, inserts the bean and returns the new item.
  -     */
  -    protected void insert(DynaBean dynaBean, Connection connection) throws SQLException {
  -        SqlDynaClass dynaClass = getSqlDynaClass(dynaBean);
  +     * Inserts the bean.
  +     * 
  +     * @param dynaBean   The bean
  +     * @param connection The database connection
  +     */
  +    protected void insert(DynaBean dynaBean, Connection connection) throws SQLException
  +    {
  +        SqlDynaClass      dynaClass  = getSqlDynaClass(dynaBean);
           SqlDynaProperty[] properties = dynaClass.getSqlDynaProperties();
  -        int size = properties.length;
  -        if (size == 0) {
  -            log.info( "Cannot insert type: " + dynaClass + " as there are no properties" );
  +
  +        if (properties.length == 0)
  +        {
  +            log.info("Cannot insert type " + dynaClass + " as there are no properties");
               return;
           }
   
  -        String sql = createInsertSql(dynaClass, properties);
  +        String            sql       = createInsertSql(dynaClass, properties);
  +        PreparedStatement statement = null;
   
  -        if (log.isDebugEnabled()) {
  -            log.debug( "About to execute SQL: " + sql );
  +        if (log.isDebugEnabled())
  +        {
  +            log.debug("About to execute SQL: " + sql);
           }
   
  -        PreparedStatement statement = null;
  -        try {
  -            statement = connection.prepareStatement( sql );
  +        try
  +        {
  +            statement = connection.prepareStatement(sql);
   
  -            for ( int i = 0; i < size; i++ ) {
  -                SqlDynaProperty property = properties[i];
  -                setObject(statement, 1+i, dynaBean, property);
  +            for (int idx = 0; idx < properties.length; idx++ )
  +            {
  +                setObject(statement, idx + 1, dynaBean, properties[idx]);
               }
  +
               int count = statement.executeUpdate();
  -            if ( count != 1 ) {
  -                log.warn( "Attempted to insert a single row : " + dynaBean
  -                    + " in table: " + dynaClass.getTableName()
  -                    + " but changed: " + count + " row(s)"
  -                );
  +
  +            if (count != 1)
  +            {
  +                log.warn("Attempted to insert a single row : " + dynaBean +
  +                         " in table: " + dynaClass.getTableName() +
  +                         " but changed: " + count + " row(s)");
               }
           }
  -        finally {
  +        finally
  +        {
               closeStatement(statement);
           }
       }
   
       /**
  -     * Updates the row which maps to the given dynabean
  -     */
  -    protected void update(DynaBean dynaBean, Connection connection) throws SQLException {
  -        SqlDynaClass dynaClass = getSqlDynaClass(dynaBean);
  +     * Updates the row which maps to the given dynabean.
  +     * 
  +     * @param dynaBean   The bean
  +     * @param connection The database connection
  +     */
  +    protected void update(DynaBean dynaBean, Connection connection) throws SQLException
  +    {
  +        SqlDynaClass      dynaClass   = getSqlDynaClass(dynaBean);
           SqlDynaProperty[] primaryKeys = dynaClass.getPrimaryKeyProperties();
  -        if (primaryKeys.length == 0) {
  -            log.info( "Cannot update type: " + dynaClass + " as there are no primary keys to update" );
  +
  +        if (primaryKeys.length == 0)
  +        {
  +            log.info("Cannot update type " + dynaClass + " as there are no primary keys to update");
               return;
           }
   
           SqlDynaProperty[] properties = dynaClass.getNonPrimaryKeyProperties();
  +        String            sql        = createUpdateSql(dynaClass, primaryKeys, properties);
  +        PreparedStatement statement  = null;
   
  -        String sql = createUpdateSql(dynaClass, primaryKeys, properties);
  -
  -        if (log.isDebugEnabled()) {
  -            log.debug( "About to execute SQL: " + sql );
  +        if (log.isDebugEnabled())
  +        {
  +            log.debug("About to execute SQL: " + sql);
           }
  -
  -        PreparedStatement statement = null;
  -        try {
  -            statement = connection.prepareStatement( sql );
  +        try
  +        {
  +            statement = connection.prepareStatement(sql);
   
               int sqlIndex = 1;
  -            for ( int i = 0, size = properties.length; i < size; i++ ) {
  -                SqlDynaProperty property = properties[i];
  -                setObject(statement, sqlIndex++, dynaBean, property);
  -            }
  -            for ( int i = 0, size = primaryKeys.length; i < size; i++ ) {
  -                SqlDynaProperty primaryKey = primaryKeys[i];
  -                setObject(statement, sqlIndex++, dynaBean, primaryKey);
  +
  +            for (int idx = 0; idx < properties.length; idx++)
  +            {
  +                setObject(statement, sqlIndex++, dynaBean, properties[idx]);
  +            }
  +            for (int idx = 0; idx < properties.length; idx++)
  +            {
  +                setObject(statement, sqlIndex++, dynaBean, primaryKeys[idx]);
               }
  +
               int count = statement.executeUpdate();
  -            if ( count != 1 ) {
  -                log.warn( "Attempted to insert a single row : " + dynaBean
  -                    + " in table: " + dynaClass.getTableName()
  -                    + " but changed: " + count + " row(s)"
  -                );
  +
  +            if (count != 1 )
  +            {
  +                log.warn("Attempted to insert a single row : " + dynaBean +
  +                         " in table: " + dynaClass.getTableName() +
  +                         " but changed: " + count + " row(s)");
               }
           }
  -        finally {
  +        finally
  +        {
               closeStatement(statement);
           }
       }
  
  
  

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