db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henn...@apache.org
Subject svn commit: r230774 - in /db/torque/trunk/src/generator/src: java/org/apache/torque/engine/database/model/ test/org/apache/torque/engine/database/model/
Date Mon, 08 Aug 2005 08:37:07 GMT
Author: henning
Date: Mon Aug  8 01:36:58 2005
New Revision: 230774

URL: http://svn.apache.org/viewcvs?rev=230774&view=rev
Log:
Fix the "oh, we should not have a trailing space here, there, we need
separation spaces" problems with getSqlString() once and for all.


Modified:
    db/torque/trunk/src/generator/src/java/org/apache/torque/engine/database/model/Column.java
    db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/DomainTest.java
    db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java
    db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/MssqlDomainTest.java
    db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/OracleDomainTest.java
    db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/PostgresqlDomainTest.java

Modified: db/torque/trunk/src/generator/src/java/org/apache/torque/engine/database/model/Column.java
URL: http://svn.apache.org/viewcvs/db/torque/trunk/src/generator/src/java/org/apache/torque/engine/database/model/Column.java?rev=230774&r1=230773&r2=230774&view=diff
==============================================================================
--- db/torque/trunk/src/generator/src/java/org/apache/torque/engine/database/model/Column.java
(original)
+++ db/torque/trunk/src/generator/src/java/org/apache/torque/engine/database/model/Column.java
Mon Aug  8 01:36:58 2005
@@ -1018,33 +1018,45 @@
     
     public String getSqlString()
     {
-        StringBuffer sb = new StringBuffer();
-        sb.append(getName());
-        sb.append(' ');
-        sb.append(getDomain().getSqlType());
+        List resultList = new ArrayList();
+        resultList.add(getName());
+
+        String type = getDomain().getSqlType();
+
         if (getPlatform().hasSize(getDomain().getSqlType()))
         {
-            sb.append(getDomain().printSize());
-            sb.append(' ');
+            type += getDomain().printSize();
         }
-        if (getDomain().getDefaultValue() != null)
+
+        resultList.add(type);
+
+        if (StringUtils.isNotEmpty(getDomain().getDefaultValue()))
         {
-            sb.append("default ");
+            resultList.add("default");
+
             if (TypeMap.isTextType(getDomain().getType()))
             {
                 // TODO: Properly SQL-escape the text.
-                sb.append('\'').append(getDefaultValue()).append('\'');
+                resultList.add(
+                        new StringBuffer()
+                        .append('\'')
+                        .append(getDefaultValue())
+                        .append('\''));
             }
             else
             {
-                sb.append(getDefaultValue());
+                resultList.add(getDefaultValue());
             }
-            sb.append(' ');
         }
-        sb.append(getNotNullString());
-        sb.append(' ');
-        sb.append(getAutoIncrementString());
-        return sb.toString();
+        if (StringUtils.isNotEmpty(getNotNullString()))
+        {
+            resultList.add(getNotNullString());
+        }
+        if (StringUtils.isNotEmpty(getAutoIncrementString()))
+        {
+            resultList.add(getAutoIncrementString());
+        }
+        return StringUtils.join(resultList.iterator(), ' ');
     }
     
     /**

Modified: db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/DomainTest.java
URL: http://svn.apache.org/viewcvs/db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/DomainTest.java?rev=230774&r1=230773&r2=230774&view=diff
==============================================================================
--- db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/DomainTest.java
(original)
+++ db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/DomainTest.java
Mon Aug  8 01:36:58 2005
@@ -73,7 +73,7 @@
         assertEquals("VARCHAR", name.getType());
         assertEquals("VARCHAR", name.getDomain().getSqlType());
         assertEquals("40", name.getSize());
-        assertEquals("name VARCHAR(40)  ", name.getSqlString());
+        assertEquals("name VARCHAR(40)", name.getSqlString());
         Column price = table.getColumn("price");
         assertEquals("NUMERIC", price.getTorqueType());
         assertEquals("NUMERIC", price.getType());
@@ -82,7 +82,7 @@
         assertEquals("2", price.getScale());
         assertEquals("0", price.getDefaultValue());
         assertEquals("(10,2)", price.printSize());
-        assertEquals("price DECIMAL(10,2) default 0  ", price.getSqlString());
+        assertEquals("price DECIMAL(10,2) default 0", price.getSqlString());
     }
     
     /**
@@ -99,7 +99,7 @@
         assertEquals("2", price.getScale());
         assertEquals("1000", price.getDefaultValue());
         assertEquals("(12,2)", price.printSize());
-        assertEquals("price DECIMAL(12,2) default 1000  ", price.getSqlString());
+        assertEquals("price DECIMAL(12,2) default 1000", price.getSqlString());
     }
     
     public void testDecimalColumn() throws Exception
@@ -112,7 +112,7 @@
         assertEquals("10", col.getSize());
         assertEquals("3", col.getScale());
         assertEquals("(10,3)", col.printSize());
-        assertEquals("decimal_col DECIMAL(10,3)  ", col.getSqlString());
+        assertEquals("decimal_col DECIMAL(10,3)", col.getSqlString());
     }
 
     public void testDateColumn() throws Exception
@@ -123,7 +123,7 @@
         assertEquals("DATE", col.getType());
         assertEquals("DATETIME", col.getDomain().getSqlType());
         assertEquals("", col.printSize());
-        assertEquals("date_col DATETIME  ", col.getSqlString());
+        assertEquals("date_col DATETIME", col.getSqlString());
     }
 
     public void testNativeAutoincrement() throws Exception
@@ -141,7 +141,7 @@
         Table table = db.getTable("article");
         Column col = table.getColumn("article_id");
         assertEquals("", col.getAutoIncrementString());
-        assertEquals("article_id MEDIUMINT NOT NULL ", col.getSqlString());
+        assertEquals("article_id MEDIUMINT NOT NULL", col.getSqlString());
         col = table.getColumn("name");
         assertEquals("", col.getAutoIncrementString());
     }    
@@ -154,7 +154,7 @@
         assertEquals("BOOLEANINT", col.getTorqueType());
         assertEquals("INTEGER", col.getType());
         assertEquals("INTEGER", col.getDomain().getSqlType());
-        assertEquals("cbooleanint INTEGER  ", col.getSqlString());
+        assertEquals("cbooleanint INTEGER", col.getSqlString());
     }    
 
     public void testBlob() throws Exception
@@ -164,7 +164,7 @@
         assertEquals("", col.getAutoIncrementString());
         assertEquals("BLOB", col.getTorqueType());
         assertEquals("LONGBLOB", col.getDomain().getSqlType());
-        assertEquals("cblob LONGBLOB ", col.getSqlString());
+        assertEquals("cblob LONGBLOB", col.getSqlString());
     }    
 
 }

Modified: db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java
URL: http://svn.apache.org/viewcvs/db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java?rev=230774&r1=230773&r2=230774&view=diff
==============================================================================
--- db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java
(original)
+++ db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/HypersonicDomainTest.java
Mon Aug  8 01:36:58 2005
@@ -60,7 +60,7 @@
         Column name = table.getColumn("name");
         assertEquals("VARCHAR", name.getDomain().getSqlType());
         assertEquals("40", name.getSize());
-        assertEquals("name VARCHAR(40)  ", name.getSqlString());
+        assertEquals("name VARCHAR(40)", name.getSqlString());
         Column price = table.getColumn("price");
         assertEquals("NUMERIC", price.getTorqueType());
         assertEquals("NUMERIC", price.getDomain().getSqlType());
@@ -68,7 +68,7 @@
         assertEquals("2", price.getScale());
         assertEquals("0", price.getDefaultValue());
         assertEquals("(10,2)", price.printSize());
-        assertEquals("price NUMERIC(10,2) default 0  ", price.getSqlString());
+        assertEquals("price NUMERIC(10,2) default 0", price.getSqlString());
     }
 
     /**
@@ -84,7 +84,7 @@
         assertEquals("2", price.getScale());
         assertEquals("1000", price.getDefaultValue());
         assertEquals("(12,2)", price.printSize());
-        assertEquals("price NUMERIC(12,2) default 1000  ", price.getSqlString());
+        assertEquals("price NUMERIC(12,2) default 1000", price.getSqlString());
     }
 
     public void testDecimalColumn() throws Exception
@@ -96,7 +96,7 @@
         assertEquals("10", col.getSize());
         assertEquals("3", col.getScale());
         assertEquals("(10,3)", col.printSize());
-        assertEquals("decimal_col DECIMAL(10,3)  ", col.getSqlString());
+        assertEquals("decimal_col DECIMAL(10,3)", col.getSqlString());
     }
 
     public void testDateColumn() throws Exception
@@ -106,7 +106,7 @@
         assertEquals("DATE", col.getTorqueType());
         assertEquals("DATE", col.getDomain().getSqlType());
         assertEquals("", col.printSize());
-        assertEquals("date_col DATE  ", col.getSqlString());
+        assertEquals("date_col DATE", col.getSqlString());
     }
 
     public void testNativeAutoincrement() throws Exception
@@ -124,7 +124,7 @@
         Table table = db.getTable("article");
         Column col = table.getColumn("article_id");
         assertEquals("", col.getAutoIncrementString());
-        assertEquals("article_id INTEGER NOT NULL ", col.getSqlString());
+        assertEquals("article_id INTEGER NOT NULL", col.getSqlString());
         col = table.getColumn("name");
         assertEquals("", col.getAutoIncrementString());
     }
@@ -136,7 +136,7 @@
         assertEquals("", col.getAutoIncrementString());
         assertEquals("BOOLEANINT", col.getTorqueType());
         assertEquals("INTEGER", col.getDomain().getSqlType());
-        assertEquals("cbooleanint INTEGER  ", col.getSqlString());
+        assertEquals("cbooleanint INTEGER", col.getSqlString());
     }
 
     public void testBlob() throws Exception
@@ -146,7 +146,7 @@
         assertEquals("", col.getAutoIncrementString());
         assertEquals("BLOB", col.getTorqueType());
         assertEquals("BINARY", col.getDomain().getSqlType());
-        assertEquals("cblob BINARY  ", col.getSqlString());
+        assertEquals("cblob BINARY", col.getSqlString());
     }
 
 }

Modified: db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/MssqlDomainTest.java
URL: http://svn.apache.org/viewcvs/db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/MssqlDomainTest.java?rev=230774&r1=230773&r2=230774&view=diff
==============================================================================
--- db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/MssqlDomainTest.java
(original)
+++ db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/MssqlDomainTest.java
Mon Aug  8 01:36:58 2005
@@ -59,7 +59,7 @@
         Column name = table.getColumn("name");
         assertEquals("VARCHAR", name.getDomain().getSqlType());
         assertEquals("40", name.getSize());
-        assertEquals("name VARCHAR(40) NULL ", name.getSqlString());
+        assertEquals("name VARCHAR(40) NULL", name.getSqlString());
         Column price = table.getColumn("price");
         assertEquals("NUMERIC", price.getTorqueType());
         assertEquals("NUMERIC", price.getDomain().getSqlType());
@@ -67,7 +67,7 @@
         assertEquals("2", price.getScale());
         assertEquals("0", price.getDefaultValue());
         assertEquals("(10,2)", price.printSize());
-        assertEquals("price NUMERIC(10,2) default 0 NULL ", price.getSqlString());
+        assertEquals("price NUMERIC(10,2) default 0 NULL", price.getSqlString());
     }
     
     /**
@@ -83,7 +83,7 @@
         assertEquals("2", price.getScale());
         assertEquals("1000", price.getDefaultValue());
         assertEquals("(12,2)", price.printSize());
-        assertEquals("price NUMERIC(12,2) default 1000 NULL ", price.getSqlString());
+        assertEquals("price NUMERIC(12,2) default 1000 NULL", price.getSqlString());
     }
     
     public void testDecimalColumn() throws Exception
@@ -95,7 +95,7 @@
         assertEquals("10", col.getSize());
         assertEquals("3", col.getScale());
         assertEquals("(10,3)", col.printSize());
-        assertEquals("decimal_col DECIMAL(10,3) NULL ", col.getSqlString());
+        assertEquals("decimal_col DECIMAL(10,3) NULL", col.getSqlString());
     }
 
     public void testDateColumn() throws Exception
@@ -105,7 +105,7 @@
         assertEquals("DATE", col.getTorqueType());
         assertEquals("DATETIME", col.getDomain().getSqlType());
         assertEquals("", col.printSize());
-        assertEquals("date_col DATETIME NULL ", col.getSqlString());
+        assertEquals("date_col DATETIME NULL", col.getSqlString());
     }
 
     public void testNativeAutoincrement() throws Exception
@@ -123,7 +123,7 @@
         Table table = db.getTable("article");
         Column col = table.getColumn("article_id");
         assertEquals("", col.getAutoIncrementString());
-        assertEquals("article_id INT NOT NULL ", col.getSqlString());
+        assertEquals("article_id INT NOT NULL", col.getSqlString());
         col = table.getColumn("name");
         assertEquals("", col.getAutoIncrementString());
     }    
@@ -135,7 +135,7 @@
         assertEquals("", col.getAutoIncrementString());
         assertEquals("BOOLEANINT", col.getTorqueType());
         assertEquals("INT", col.getDomain().getSqlType());
-        assertEquals("cbooleanint INT NULL ", col.getSqlString());
+        assertEquals("cbooleanint INT NULL", col.getSqlString());
     }    
     
 }

Modified: db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/OracleDomainTest.java
URL: http://svn.apache.org/viewcvs/db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/OracleDomainTest.java?rev=230774&r1=230773&r2=230774&view=diff
==============================================================================
--- db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/OracleDomainTest.java
(original)
+++ db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/OracleDomainTest.java
Mon Aug  8 01:36:58 2005
@@ -59,7 +59,7 @@
         Column name = table.getColumn("name");
         assertEquals("VARCHAR2", name.getDomain().getSqlType());
         assertEquals("40", name.getSize());
-        assertEquals("name VARCHAR2(40)  ", name.getSqlString());
+        assertEquals("name VARCHAR2(40)", name.getSqlString());
         Column price = table.getColumn("price");
         assertEquals("NUMERIC", price.getTorqueType());
         assertEquals("NUMBER", price.getDomain().getSqlType());
@@ -67,7 +67,7 @@
         assertEquals("2", price.getScale());
         assertEquals("0", price.getDefaultValue());
         assertEquals("(10,2)", price.printSize());
-        assertEquals("price NUMBER(10,2) default 0  ", price.getSqlString());
+        assertEquals("price NUMBER(10,2) default 0", price.getSqlString());
     }
     
     /**
@@ -83,7 +83,7 @@
         assertEquals("2", price.getScale());
         assertEquals("1000", price.getDefaultValue());
         assertEquals("(12,2)", price.printSize());
-        assertEquals("price NUMBER(12,2) default 1000  ", price.getSqlString());
+        assertEquals("price NUMBER(12,2) default 1000", price.getSqlString());
     }
     
     public void testDecimalColumn() throws Exception
@@ -95,7 +95,7 @@
         assertEquals("10", col.getSize());
         assertEquals("3", col.getScale());
         assertEquals("(10,3)", col.printSize());
-        assertEquals("decimal_col NUMBER(10,3)  ", col.getSqlString());
+        assertEquals("decimal_col NUMBER(10,3)", col.getSqlString());
     }
 
     public void testDateColumn() throws Exception
@@ -105,7 +105,7 @@
         assertEquals("DATE", col.getTorqueType());
         assertEquals("DATE", col.getDomain().getSqlType());
         assertEquals("", col.printSize());
-        assertEquals("date_col DATE  ", col.getSqlString());
+        assertEquals("date_col DATE", col.getSqlString());
     }
 
     public void testNativeAutoincrement() throws Exception
@@ -113,7 +113,7 @@
         Table table = db.getTable("native");
         Column col = table.getColumn("native_id");
         assertEquals("", col.getAutoIncrementString());
-        assertEquals("native_id NUMBER(10,0) NOT NULL ", col.getSqlString());
+        assertEquals("native_id NUMBER(10,0) NOT NULL", col.getSqlString());
         col = table.getColumn("name");
         assertEquals("", col.getAutoIncrementString());
     }    
@@ -123,7 +123,7 @@
         Table table = db.getTable("article");
         Column col = table.getColumn("article_id");
         assertEquals("", col.getAutoIncrementString());
-        assertEquals("article_id NUMBER(10,0) NOT NULL ", col.getSqlString());
+        assertEquals("article_id NUMBER(10,0) NOT NULL", col.getSqlString());
         col = table.getColumn("name");
         assertEquals("", col.getAutoIncrementString());
     }    
@@ -135,7 +135,7 @@
         assertEquals("", col.getAutoIncrementString());
         assertEquals("BOOLEANINT", col.getTorqueType());
         assertEquals("NUMBER", col.getDomain().getSqlType());
-        assertEquals("cbooleanint NUMBER(1,0)  ", col.getSqlString());
+        assertEquals("cbooleanint NUMBER(1,0)", col.getSqlString());
     }    
     
 }

Modified: db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/PostgresqlDomainTest.java
URL: http://svn.apache.org/viewcvs/db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/PostgresqlDomainTest.java?rev=230774&r1=230773&r2=230774&view=diff
==============================================================================
--- db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/PostgresqlDomainTest.java
(original)
+++ db/torque/trunk/src/generator/src/test/org/apache/torque/engine/database/model/PostgresqlDomainTest.java
Mon Aug  8 01:36:58 2005
@@ -59,7 +59,7 @@
         Column name = table.getColumn("name");
         assertEquals("VARCHAR", name.getDomain().getSqlType());
         assertEquals("40", name.getSize());
-        assertEquals("name VARCHAR(40)  ", name.getSqlString());
+        assertEquals("name VARCHAR(40)", name.getSqlString());
         Column price = table.getColumn("price");
         assertEquals("NUMERIC", price.getTorqueType());
         assertEquals("NUMERIC", price.getDomain().getSqlType());
@@ -67,7 +67,7 @@
         assertEquals("2", price.getScale());
         assertEquals("0", price.getDefaultValue());
         assertEquals("(10,2)", price.printSize());
-        assertEquals("price NUMERIC(10,2) default 0  ", price.getSqlString());
+        assertEquals("price NUMERIC(10,2) default 0", price.getSqlString());
     }
     
     /**
@@ -83,7 +83,7 @@
         assertEquals("2", price.getScale());
         assertEquals("1000", price.getDefaultValue());
         assertEquals("(12,2)", price.printSize());
-        assertEquals("price NUMERIC(12,2) default 1000  ", price.getSqlString());
+        assertEquals("price NUMERIC(12,2) default 1000", price.getSqlString());
     }
     
     public void testDecimalColumn() throws Exception
@@ -95,7 +95,7 @@
         assertEquals("10", col.getSize());
         assertEquals("3", col.getScale());
         assertEquals("(10,3)", col.printSize());
-        assertEquals("decimal_col DECIMAL(10,3)  ", col.getSqlString());
+        assertEquals("decimal_col DECIMAL(10,3)", col.getSqlString());
     }
 
     public void testDateColumn() throws Exception
@@ -105,7 +105,7 @@
         assertEquals("DATE", col.getTorqueType());
         assertEquals("DATE", col.getDomain().getSqlType());
         assertEquals("", col.printSize());
-        assertEquals("date_col DATE  ", col.getSqlString());
+        assertEquals("date_col DATE", col.getSqlString());
     }
 
     public void testNativeAutoincrement() throws Exception
@@ -113,7 +113,7 @@
         Table table = db.getTable("native");
         Column col = table.getColumn("native_id");
         assertEquals("", col.getAutoIncrementString());
-        assertEquals("native_id INTEGER NOT NULL ", col.getSqlString());
+        assertEquals("native_id INTEGER NOT NULL", col.getSqlString());
         col = table.getColumn("name");
         assertEquals("", col.getAutoIncrementString());
     }    
@@ -123,7 +123,7 @@
         Table table = db.getTable("article");
         Column col = table.getColumn("article_id");
         assertEquals("", col.getAutoIncrementString());
-        assertEquals("article_id INTEGER NOT NULL ", col.getSqlString());
+        assertEquals("article_id INTEGER NOT NULL", col.getSqlString());
         col = table.getColumn("name");
         assertEquals("", col.getAutoIncrementString());
     }    
@@ -135,7 +135,7 @@
         assertEquals("", col.getAutoIncrementString());
         assertEquals("BOOLEANINT", col.getTorqueType());
         assertEquals("INT2", col.getDomain().getSqlType());
-        assertEquals("cbooleanint INT2  ", col.getSqlString());
+        assertEquals("cbooleanint INT2", col.getSqlString());
     }    
     
 }



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


Mime
View raw message