db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1098759 - in /db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates: platform/ transformer/sql/ typemapping/
Date Mon, 02 May 2011 19:30:43 GMT
Author: tfischer
Date: Mon May  2 19:30:42 2011
New Revision: 1098759

URL: http://svn.apache.org/viewvc?rev=1098759&view=rev
Log:
TORQUE-155: use "${size} CHAR" as size for varchar2 columns in oracle

Modified:
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/Platform.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformDefaultImpl.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformOracleImpl.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLTransformer.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SqlType.java

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/Platform.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/Platform.java?rev=1098759&r1=1098758&r2=1098759&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/Platform.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/Platform.java
Mon May  2 19:30:42 2011
@@ -87,6 +87,17 @@ public interface Platform
     boolean hasScale(String sqlType);
 
     /**
+     * Returns a possible SQL suffix for column definitions of certain
+     *  SQL Types, e.g. for Oracle VARCHAR2 columns, it typically 
+     *  makes sense to use 'XXX CHAR' instead of 'XXX' as size.
+     *  
+     * @param sqlType the SQL type to determine the suffix for.
+     * 
+     * @return the size suffix, not null, may be empty.
+     */
+    public String getSizeSuffix(String sqlType);
+
+    /**
      * Returns whether the "not null part" of the definition of a column
      * should be generated before the "autoincrement part" in a "create table"
      * statement.

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformDefaultImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformDefaultImpl.java?rev=1098759&r1=1098758&r2=1098759&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformDefaultImpl.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformDefaultImpl.java
Mon May  2 19:30:42 2011
@@ -23,6 +23,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.torque.templates.typemapping.SchemaType;
 import org.apache.torque.templates.typemapping.SqlType;
 
@@ -152,6 +153,22 @@ public class PlatformDefaultImpl impleme
     }
 
     /**
+     * Returns a possible SQL suffix for column definitions of certain
+     *  SQL Types, e.g. for Oracle VARCHAR2 columns, it typically 
+     *  makes sense to use 'XXX CHAR' instead of 'XXX' as size.
+     *  
+     * @param sqlType the SQL type to determine the suffix for.
+     * 
+     * @return The size suffix, not null.
+     *         This implementation always returns the empty string.
+     *
+     */
+    public String getSizeSuffix(String sqlType)
+    {
+        return StringUtils.EMPTY;
+    }
+
+   /**
      * @see Platform#createNotNullBeforeAutoincrement()
      */
     public boolean createNotNullBeforeAutoincrement()

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformOracleImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformOracleImpl.java?rev=1098759&r1=1098758&r2=1098759&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformOracleImpl.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformOracleImpl.java
Mon May  2 19:30:42 2011
@@ -19,6 +19,7 @@ package org.apache.torque.templates.plat
  * under the License.
  */
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.torque.templates.typemapping.SchemaType;
 import org.apache.torque.templates.typemapping.SqlType;
 
@@ -119,4 +120,24 @@ public class PlatformOracleImpl extends 
     {
         return true;
     }
+
+    /**
+     * Returns a possible SQL suffix for column definitions of certain
+     *  SQL Types, e.g. for Oracle VARCHAR2 columns, it typically 
+     *  makes sense to use 'XXX CHAR' instead of 'XXX' as size.
+     *  
+     * @param sqlType the SQL type to determine the suffix for.
+     * 
+     * @return The size suffix, not null.
+     *         This implementation always returns the empty string.
+     *
+     */
+    public String getSizeSuffix(String sqlType)
+    {
+        if ("VARCHAR2".equals(sqlType))
+        {
+            return " CHAR";
+        }
+        return StringUtils.EMPTY;
+    }
 }

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLTransformer.java?rev=1098759&r1=1098758&r2=1098759&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLTransformer.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLTransformer.java
Mon May  2 19:30:42 2011
@@ -279,9 +279,10 @@ public class SQLTransformer implements S
 
         String sqlTypeName = sqlType.getSqlTypeName();
 
-        if (platform.hasSize(sqlType.getSqlTypeName()))
+        if (platform.hasSize(sqlTypeName))
         {
-            sqlTypeName += sqlType.printSize();
+            sqlTypeName += sqlType.printSize(
+                    platform.getSizeSuffix(sqlTypeName));
         }
 
         resultList.add(sqlTypeName);

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SqlType.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SqlType.java?rev=1098759&r1=1098758&r2=1098759&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SqlType.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SqlType.java
Mon May  2 19:30:42 2011
@@ -237,15 +237,15 @@ public class SqlType
      * @return size and scale or an empty String if there are no values
      *         available.
      */
-    public String printSize()
+    public String printSize(String sizeSuffix)
     {
         if (StringUtils.isNotBlank(size) && StringUtils.isNotBlank(scale))
         {
-            return '(' + size + ',' + scale + ')';
+            return '(' + size + sizeSuffix + ',' + scale + ')';
         }
         else if (StringUtils.isNotBlank(size))
         {
-            return '(' + size + ')';
+            return '(' + size + sizeSuffix + ')';
         }
         else
         {



---------------------------------------------------------------------
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