You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by mp...@apache.org on 2003/12/07 13:47:37 UTC

cvs commit: db-torque/src/generator/src/java/org/apache/torque/engine/database/model Domain.java Column.java

mpoeschl    2003/12/07 04:47:37

  Modified:    src/generator/src/test/org/apache/torque/engine/database/model
                        DomainTest.java PostgresqlDomainTest.java
                        OracleDomainTest.java
               src/generator/src/java/org/apache/torque/engine/database/model
                        Domain.java Column.java
  Added:       src/generator/src/test/org/apache/torque/engine/database/model
                        MssqlDomainTest.java
  Log:
  add Column.getSqlString() + more tests
  
  Revision  Changes    Path
  1.8       +10 -2     db-torque/src/generator/src/test/org/apache/torque/engine/database/model/DomainTest.java
  
  Index: DomainTest.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/test/org/apache/torque/engine/database/model/DomainTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DomainTest.java	5 Dec 2003 14:28:28 -0000	1.7
  +++ DomainTest.java	7 Dec 2003 12:47:37 -0000	1.8
  @@ -112,6 +112,7 @@
           assertEquals("VARCHAR", name.getType());
           assertEquals("VARCHAR", name.getDomain().getSqlType());
           assertEquals("40", name.getSize());
  +        assertEquals("name VARCHAR(40)  ", name.getSqlString());
           Column price = table.getColumn("price");
           assertEquals("NUMERIC", price.getTorqueType());
           assertEquals("NUMERIC", price.getType());
  @@ -120,6 +121,7 @@
           assertEquals("2", price.getScale());
           assertEquals("0", price.getDefaultValue());
           assertEquals("(10,2)", price.printSize());
  +        assertEquals("price DECIMAL(10,2) default 0  ", price.getSqlString());
       }
       
       /**
  @@ -136,6 +138,7 @@
           assertEquals("2", price.getScale());
           assertEquals("1000", price.getDefaultValue());
           assertEquals("(12,2)", price.printSize());
  +        assertEquals("price DECIMAL(12,2) default 1000  ", price.getSqlString());
       }
       
       public void testDecimalColumn() throws Exception
  @@ -148,6 +151,7 @@
           assertEquals("10", col.getSize());
           assertEquals("3", col.getScale());
           assertEquals("(10,3)", col.printSize());
  +        assertEquals("decimal_col DECIMAL(10,3)  ", col.getSqlString());
       }
   
       public void testDateColumn() throws Exception
  @@ -158,6 +162,7 @@
           assertEquals("DATE", col.getType());
           assertEquals("DATETIME", col.getDomain().getSqlType());
           assertEquals("", col.printSize());
  +        assertEquals("date_col DATETIME  ", col.getSqlString());
       }
   
       public void testNativeAutoincrement() throws Exception
  @@ -165,6 +170,7 @@
           Table table = db.getTable("native");
           Column col = table.getColumn("native_id");
           assertEquals("AUTO_INCREMENT", col.getAutoIncrementString());
  +        assertEquals("native_id INTEGER NOT NULL AUTO_INCREMENT", col.getSqlString());
           col = table.getColumn("name");
           assertEquals("", col.getAutoIncrementString());
       }    
  @@ -174,6 +180,7 @@
           Table table = db.getTable("article");
           Column col = table.getColumn("article_id");
           assertEquals("", col.getAutoIncrementString());
  +        assertEquals("article_id INTEGER NOT NULL ", col.getSqlString());
           col = table.getColumn("name");
           assertEquals("", col.getAutoIncrementString());
       }    
  @@ -186,6 +193,7 @@
           assertEquals("BOOLEANINT", col.getTorqueType());
           assertEquals("INTEGER", col.getType());
           assertEquals("INTEGER", col.getDomain().getSqlType());
  -       }    
  +        assertEquals("cbooleanint INTEGER  ", col.getSqlString());
  +    }    
       
   }
  
  
  
  1.2       +11 -8     db-torque/src/generator/src/test/org/apache/torque/engine/database/model/PostgresqlDomainTest.java
  
  Index: PostgresqlDomainTest.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/test/org/apache/torque/engine/database/model/PostgresqlDomainTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PostgresqlDomainTest.java	5 Dec 2003 18:35:53 -0000	1.1
  +++ PostgresqlDomainTest.java	7 Dec 2003 12:47:37 -0000	1.2
  @@ -95,17 +95,17 @@
       {
           Table table = db.getTable("product");
           Column name = table.getColumn("name");
  -        assertEquals("VARCHAR", name.getType());
           assertEquals("VARCHAR", name.getDomain().getSqlType());
           assertEquals("40", name.getSize());
  +        assertEquals("name VARCHAR(40)  ", name.getSqlString());
           Column price = table.getColumn("price");
           assertEquals("NUMERIC", price.getTorqueType());
  -        assertEquals("NUMERIC", price.getType());
           assertEquals("NUMERIC", price.getDomain().getSqlType());
           assertEquals("10", price.getSize());
           assertEquals("2", price.getScale());
           assertEquals("0", price.getDefaultValue());
           assertEquals("(10,2)", price.printSize());
  +        assertEquals("price NUMERIC(10,2) default 0  ", price.getSqlString());
       }
       
       /**
  @@ -116,12 +116,12 @@
           Table table = db.getTable("article");
           Column price = table.getColumn("price");
           assertEquals("NUMERIC", price.getTorqueType());
  -        assertEquals("NUMERIC", price.getType());
           assertEquals("NUMERIC", price.getDomain().getSqlType());
           assertEquals("12", price.getSize());
           assertEquals("2", price.getScale());
           assertEquals("1000", price.getDefaultValue());
           assertEquals("(12,2)", price.printSize());
  +        assertEquals("price NUMERIC(12,2) default 1000  ", price.getSqlString());
       }
       
       public void testDecimalColumn() throws Exception
  @@ -129,11 +129,11 @@
           Table table = db.getTable("article");
           Column col = table.getColumn("decimal_col");
           assertEquals("DECIMAL", col.getTorqueType());
  -        assertEquals("DECIMAL", col.getType());
           assertEquals("DECIMAL", col.getDomain().getSqlType());
           assertEquals("10", col.getSize());
           assertEquals("3", col.getScale());
           assertEquals("(10,3)", col.printSize());
  +        assertEquals("decimal_col DECIMAL(10,3)  ", col.getSqlString());
       }
   
       public void testDateColumn() throws Exception
  @@ -141,9 +141,9 @@
           Table table = db.getTable("article");
           Column col = table.getColumn("date_col");
           assertEquals("DATE", col.getTorqueType());
  -        assertEquals("DATE", col.getType());
           assertEquals("DATE", col.getDomain().getSqlType());
           assertEquals("", col.printSize());
  +        assertEquals("date_col DATE  ", col.getSqlString());
       }
   
       public void testNativeAutoincrement() throws Exception
  @@ -151,6 +151,8 @@
           Table table = db.getTable("native");
           Column col = table.getColumn("native_id");
           assertEquals("SERIAL", col.getAutoIncrementString());
  +        // TODO sequence or identity??
  +//        assertEquals("native_id SERIAL", col.getSqlString());
           col = table.getColumn("name");
           assertEquals("", col.getAutoIncrementString());
       }    
  @@ -160,6 +162,7 @@
           Table table = db.getTable("article");
           Column col = table.getColumn("article_id");
           assertEquals("", col.getAutoIncrementString());
  +        assertEquals("article_id INTEGER NOT NULL ", col.getSqlString());
           col = table.getColumn("name");
           assertEquals("", col.getAutoIncrementString());
       }    
  @@ -170,8 +173,8 @@
           Column col = table.getColumn("cbooleanint");
           assertEquals("", col.getAutoIncrementString());
           assertEquals("BOOLEANINT", col.getTorqueType());
  -        assertEquals("INTEGER", col.getType());
           assertEquals("INT2", col.getDomain().getSqlType());
  -       }    
  +        assertEquals("cbooleanint INT2  ", col.getSqlString());
  +    }    
       
   }
  
  
  
  1.2       +10 -8     db-torque/src/generator/src/test/org/apache/torque/engine/database/model/OracleDomainTest.java
  
  Index: OracleDomainTest.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/test/org/apache/torque/engine/database/model/OracleDomainTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- OracleDomainTest.java	5 Dec 2003 18:35:53 -0000	1.1
  +++ OracleDomainTest.java	7 Dec 2003 12:47:37 -0000	1.2
  @@ -95,17 +95,17 @@
       {
           Table table = db.getTable("product");
           Column name = table.getColumn("name");
  -        assertEquals("VARCHAR", name.getType());
           assertEquals("VARCHAR2", name.getDomain().getSqlType());
           assertEquals("40", name.getSize());
  +        assertEquals("name VARCHAR2(40)  ", name.getSqlString());
           Column price = table.getColumn("price");
           assertEquals("NUMERIC", price.getTorqueType());
  -        assertEquals("NUMERIC", price.getType());
           assertEquals("NUMBER", price.getDomain().getSqlType());
           assertEquals("10", price.getSize());
           assertEquals("2", price.getScale());
           assertEquals("0", price.getDefaultValue());
           assertEquals("(10,2)", price.printSize());
  +        assertEquals("price NUMBER(10,2) default 0  ", price.getSqlString());
       }
       
       /**
  @@ -116,12 +116,12 @@
           Table table = db.getTable("article");
           Column price = table.getColumn("price");
           assertEquals("NUMERIC", price.getTorqueType());
  -        assertEquals("NUMERIC", price.getType());
           assertEquals("NUMBER", price.getDomain().getSqlType());
           assertEquals("12", price.getSize());
           assertEquals("2", price.getScale());
           assertEquals("1000", price.getDefaultValue());
           assertEquals("(12,2)", price.printSize());
  +        assertEquals("price NUMBER(12,2) default 1000  ", price.getSqlString());
       }
       
       public void testDecimalColumn() throws Exception
  @@ -129,11 +129,11 @@
           Table table = db.getTable("article");
           Column col = table.getColumn("decimal_col");
           assertEquals("DECIMAL", col.getTorqueType());
  -        assertEquals("DECIMAL", col.getType());
           assertEquals("NUMBER", col.getDomain().getSqlType());
           assertEquals("10", col.getSize());
           assertEquals("3", col.getScale());
           assertEquals("(10,3)", col.printSize());
  +        assertEquals("decimal_col NUMBER(10,3)  ", col.getSqlString());
       }
   
       public void testDateColumn() throws Exception
  @@ -141,9 +141,9 @@
           Table table = db.getTable("article");
           Column col = table.getColumn("date_col");
           assertEquals("DATE", col.getTorqueType());
  -        assertEquals("DATE", col.getType());
           assertEquals("DATE", col.getDomain().getSqlType());
           assertEquals("", col.printSize());
  +        assertEquals("date_col DATE  ", col.getSqlString());
       }
   
       public void testNativeAutoincrement() throws Exception
  @@ -151,6 +151,7 @@
           Table table = db.getTable("native");
           Column col = table.getColumn("native_id");
           assertEquals("", col.getAutoIncrementString());
  +        assertEquals("native_id NUMBER NOT NULL ", col.getSqlString());
           col = table.getColumn("name");
           assertEquals("", col.getAutoIncrementString());
       }    
  @@ -160,6 +161,7 @@
           Table table = db.getTable("article");
           Column col = table.getColumn("article_id");
           assertEquals("", col.getAutoIncrementString());
  +        assertEquals("article_id NUMBER NOT NULL ", col.getSqlString());
           col = table.getColumn("name");
           assertEquals("", col.getAutoIncrementString());
       }    
  @@ -170,8 +172,8 @@
           Column col = table.getColumn("cbooleanint");
           assertEquals("", col.getAutoIncrementString());
           assertEquals("BOOLEANINT", col.getTorqueType());
  -        assertEquals("INTEGER", col.getType());
           assertEquals("NUMBER", col.getDomain().getSqlType());
  -       }    
  +        assertEquals("cbooleanint NUMBER(1,0)  ", col.getSqlString());
  +    }    
       
   }
  
  
  
  1.1                  db-torque/src/generator/src/test/org/apache/torque/engine/database/model/MssqlDomainTest.java
  
  Index: MssqlDomainTest.java
  ===================================================================
  package org.apache.torque.engine.database.model;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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 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 Torque" 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 Torque", 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 junit.framework.TestCase;
  
  import org.apache.torque.engine.database.transform.XmlToAppData;
  
  /**
   * Tests for domain handling (for Oracle).
   *
   * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
   * @version $Id: MssqlDomainTest.java,v 1.1 2003/12/07 12:47:37 mpoeschl Exp $
   */
  public class MssqlDomainTest extends TestCase
  {
      private XmlToAppData xmlToAppData = null;
      private Database db = null;
  
      public MssqlDomainTest(String name)
      {
          super(name);
      }
  
      protected void setUp() throws Exception
      {
          super.setUp();
          xmlToAppData = new XmlToAppData("mssql", "defaultpackage");
          db = xmlToAppData.parseFile(
              "src/test/org/apache/torque/engine/database/model/domaintest-schema.xml");
      }
  
      protected void tearDown() throws Exception
      {
          xmlToAppData = null;
          super.tearDown();
      }
  
      /**
       * test if the tables get the package name from the properties file
       */
      public void testDomainColumn() throws Exception
      {
          Table table = db.getTable("product");
          Column name = table.getColumn("name");
          assertEquals("VARCHAR", name.getDomain().getSqlType());
          assertEquals("40", name.getSize());
          assertEquals("name VARCHAR(40) NULL ", name.getSqlString());
          Column price = table.getColumn("price");
          assertEquals("NUMERIC", price.getTorqueType());
          assertEquals("NUMERIC", price.getDomain().getSqlType());
          assertEquals("10", price.getSize());
          assertEquals("2", price.getScale());
          assertEquals("0", price.getDefaultValue());
          assertEquals("(10,2)", price.printSize());
          assertEquals("price NUMERIC(10,2) default 0 NULL ", price.getSqlString());
      }
      
      /**
       * test if the tables get the package name from the properties file
       */
      public void testExtendedDomainColumn() throws Exception
      {
          Table table = db.getTable("article");
          Column price = table.getColumn("price");
          assertEquals("NUMERIC", price.getTorqueType());
          assertEquals("NUMERIC", price.getDomain().getSqlType());
          assertEquals("12", price.getSize());
          assertEquals("2", price.getScale());
          assertEquals("1000", price.getDefaultValue());
          assertEquals("(12,2)", price.printSize());
          assertEquals("price NUMERIC(12,2) default 1000 NULL ", price.getSqlString());
      }
      
      public void testDecimalColumn() throws Exception
      {
          Table table = db.getTable("article");
          Column col = table.getColumn("decimal_col");
          assertEquals("DECIMAL", col.getTorqueType());
          assertEquals("DECIMAL", col.getDomain().getSqlType());
          assertEquals("10", col.getSize());
          assertEquals("3", col.getScale());
          assertEquals("(10,3)", col.printSize());
          assertEquals("decimal_col DECIMAL(10,3) NULL ", col.getSqlString());
      }
  
      public void testDateColumn() throws Exception
      {
          Table table = db.getTable("article");
          Column col = table.getColumn("date_col");
          assertEquals("DATE", col.getTorqueType());
          assertEquals("DATETIME", col.getDomain().getSqlType());
          assertEquals("", col.printSize());
          assertEquals("date_col DATETIME NULL ", col.getSqlString());
      }
  
      public void testNativeAutoincrement() throws Exception
      {
          Table table = db.getTable("native");
          Column col = table.getColumn("native_id");
          assertEquals("IDENTITY", col.getAutoIncrementString());
          assertEquals("native_id INT NOT NULL IDENTITY", col.getSqlString());
          col = table.getColumn("name");
          assertEquals("", col.getAutoIncrementString());
      }    
  
      public void testIdBrokerAutoincrement() throws Exception
      {
          Table table = db.getTable("article");
          Column col = table.getColumn("article_id");
          assertEquals("", col.getAutoIncrementString());
          assertEquals("article_id INT NOT NULL ", col.getSqlString());
          col = table.getColumn("name");
          assertEquals("", col.getAutoIncrementString());
      }    
      
      public void testBooleanint() throws Exception
      {
          Table table = db.getTable("types");
          Column col = table.getColumn("cbooleanint");
          assertEquals("", col.getAutoIncrementString());
          assertEquals("BOOLEANINT", col.getTorqueType());
          assertEquals("INT", col.getDomain().getSqlType());
          assertEquals("cbooleanint INT NULL ", col.getSqlString());
      }    
      
  }
  
  
  
  1.6       +2 -3      db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Domain.java
  
  Index: Domain.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Domain.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Domain.java	3 Dec 2003 16:41:38 -0000	1.5
  +++ Domain.java	7 Dec 2003 12:47:37 -0000	1.6
  @@ -298,8 +298,7 @@
   
       /**
        * Return a string that will give this column a default value.
  -     * <p>
  -     * TODO: Properly SQL-escape text values.
  +     * @deprecated
        */
       public String getDefaultSetting()
       {
  
  
  
  1.20      +31 -2     db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Column.java
  
  Index: Column.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Column.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- Column.java	5 Dec 2003 14:28:28 -0000	1.19
  +++ Column.java	7 Dec 2003 12:47:37 -0000	1.20
  @@ -742,6 +742,7 @@
   
       /**
        * Return a string that will give this column a default value.
  +     * @deprecated
        */
        public String getDefaultSetting()
        {
  @@ -804,7 +805,7 @@
        * Set the column type from a string property
        * (normally a string from an sql input file)
        */
  -    public void setTypeFromString (String typeName, String size)
  +    public void setTypeFromString(String typeName, String size)
       {
           String tn = typeName.toUpperCase();
           setType(tn);
  @@ -979,5 +980,33 @@
               log.warn("could not load platform implementation");
           }
           return new PlatformDefaultImpl();
  +    }
  +    
  +    public String getSqlString()
  +    {
  +        StringBuffer sb = new StringBuffer();
  +        sb.append(getName());
  +        sb.append(" ");
  +        sb.append(getDomain().getSqlType());
  +        sb.append(getDomain().printSize());
  +        sb.append(" ");
  +        if (getDomain().getDefaultValue() != null)
  +        {
  +            sb.append("default ");
  +            if (TypeMap.isTextType(getDomain().getType()))
  +            {
  +                // TODO: Properly SQL-escape the text.
  +                sb.append('\'').append(getDefaultValue()).append('\'');
  +            }
  +            else
  +            {
  +                sb.append(getDefaultValue());
  +            }
  +            sb.append(" ");
  +        }
  +        sb.append(getNotNullString());
  +        sb.append(" ");
  +        sb.append(getAutoIncrementString());
  +        return sb.toString();
       }
   }
  
  
  

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