db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1698254 - in /db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates: platform/ transformer/om/ transformer/sql/
Date Fri, 28 Aug 2015 03:45:21 GMT
Author: tfischer
Date: Fri Aug 28 03:45:21 2015
New Revision: 1698254

URL: http://svn.apache.org/r1698254
Log:
Remove default values CURRENT_DATE, CURRENT_TIME and CURRENT_TIMESTAMP in SQL generation
if these functions are not supported for the database the SQL is generated for (which is the
case for MSSQL and MYSQL)
This enables the test project to be run for these databases without the onSqlError=continue
option

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/PlatformMssqlImpl.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMysqlImpl.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.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=1698254&r1=1698253&r2=1698254&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
Fri Aug 28 03:45:21 2015
@@ -40,13 +40,13 @@ public interface Platform
      * @return the db specific SQL type, or null if no SQL type is defined
      *         for the given Torque type.
      */
-    SqlType getSqlTypeForSchemaType(SchemaType schemaType);
+    SqlType getSqlTypeForSchemaType(final SchemaType schemaType);
 
     /**
      * @return The RDBMS-specific SQL fragment for <code>NULL</code>
      * or <code>NOT NULL</code>.
      */
-    String getNullString(boolean notNull);
+    String getNullString(final boolean notNull);
 
     /**
      * @return The RDBMS-specific SQL fragment for autoincrement.
@@ -59,7 +59,7 @@ public interface Platform
      * @param sqlType the SQL type
      * @return true if the type has a size attribute
      */
-    boolean hasSize(String sqlType);
+    boolean hasSize(final String sqlType);
 
     /**
      * Returns if the RDBMS-specific SQL type has a scale attribute.
@@ -67,7 +67,7 @@ public interface Platform
      * @param sqlType the SQL type
      * @return true if the type has a scale attribute
      */
-    boolean hasScale(String sqlType);
+    boolean hasScale(final String sqlType);
 
     /**
      * Returns a possible SQL suffix for column definitions of certain
@@ -78,7 +78,7 @@ public interface Platform
      *
      * @return the size suffix, not null, may be empty.
      */
-    String getSizeSuffix(String sqlType);
+    String getSizeSuffix(final String sqlType);
 
     /**
      * Returns whether the "not null part" of the definition of a column
@@ -99,7 +99,7 @@ public interface Platform
      *
      * @return the escaped String, not null.
      */
-    String quoteAndEscape(String value);
+    String quoteAndEscape(final String value);
 
     /**
      * Formats the given date as date string which is parseable by the database.
@@ -108,7 +108,7 @@ public interface Platform
      *
      * @return the date string, inclusive string escaping.
      */
-    String getDateString(Date date);
+    String getDateString(final Date date);
 
     /**
      * Formats the given date as time string which is parseable by the database.
@@ -117,7 +117,7 @@ public interface Platform
      *
      * @return the time string, inclusive string escaping.
      */
-    String getTimeString(Date date);
+    String getTimeString(final Date date);
 
     /**
      * Formats the given date as timestamp string which is parseable
@@ -127,7 +127,7 @@ public interface Platform
      *
      * @return the timestamp string, inclusive string escaping.
      */
-    String getTimestampString(Date date);
+    String getTimestampString(final Date date);
 
     /**
      * Returns whether the database has schema support where a schema
@@ -137,4 +137,12 @@ public interface Platform
      * @return true if separate schema creation is possible, false if not.
      */
     boolean usesStandaloneSchema();
+
+    /**
+     * Returns whether the database supports the functions CURRENT_DATE, CURRENT_TIME and
CURRENT_TIMESTAMP
+     * as default values for columns.
+     *
+     * @return true if the three methods are supported as default values, false if not.
+     */
+    boolean supportsCurrentDateFunctionsAsColumnDefaultValue();
 }

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=1698254&r1=1698253&r2=1698254&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
Fri Aug 28 03:45:21 2015
@@ -82,8 +82,8 @@ public class PlatformDefaultImpl impleme
      * @param sqlType the sql type for the torque schema type, not null.
      */
     protected void setSchemaTypeToSqlTypeMapping(
-            SchemaType schemaType,
-            SqlType sqlType)
+            final SchemaType schemaType,
+            final SqlType sqlType)
     {
         if (schemaType == null)
         {
@@ -99,7 +99,7 @@ public class PlatformDefaultImpl impleme
     /**
      * @see Platform#getSqlTypeForSchemaType(SchemaType)
      */
-    public SqlType getSqlTypeForSchemaType(SchemaType schemaType)
+    public SqlType getSqlTypeForSchemaType(final SchemaType schemaType)
     {
         return schemaTypeToSqlTypeMap.get(schemaType);
     }
@@ -109,7 +109,7 @@ public class PlatformDefaultImpl impleme
      * disallowed.
      * @see Platform#getNullString(boolean)
      */
-    public String getNullString(boolean notNull)
+    public String getNullString(final boolean notNull)
     {
         return (notNull ? "NOT NULL" : "");
     }
@@ -126,7 +126,7 @@ public class PlatformDefaultImpl impleme
      * @see Platform#hasScale(String)
      * TODO collect info for all platforms
      */
-    public boolean hasScale(String sqlType)
+    public boolean hasScale(final String sqlType)
     {
         return true;
     }
@@ -135,7 +135,7 @@ public class PlatformDefaultImpl impleme
      * @see Platform#hasSize(String)
      * TODO collect info for all platforms
      */
-    public boolean hasSize(String sqlType)
+    public boolean hasSize(final String sqlType)
     {
         return true;
     }
@@ -150,7 +150,7 @@ public class PlatformDefaultImpl impleme
      * @return The size suffix, not null.
      *         This implementation always returns the empty string.
      */
-    public String getSizeSuffix(String sqlType)
+    public String getSizeSuffix(final String sqlType)
     {
         return StringUtils.EMPTY;
     }
@@ -166,7 +166,7 @@ public class PlatformDefaultImpl impleme
     /**
      * @see Platform#quoteAndEscape(String)
      */
-    public String quoteAndEscape(String text)
+    public String quoteAndEscape(final String text)
     {
         String result = text.replace("'", "''");
         if (escapeBackslashes())
@@ -189,7 +189,7 @@ public class PlatformDefaultImpl impleme
     /**
      * {@inheritDoc}
      */
-    public String getDateString(Date date)
+    public String getDateString(final Date date)
     {
         return getTimestampString(date);
     }
@@ -197,7 +197,7 @@ public class PlatformDefaultImpl impleme
     /**
      * {@inheritDoc}
      */
-    public String getTimeString(Date date)
+    public String getTimeString(final Date date)
     {
         return getTimestampString(date);
     }
@@ -205,7 +205,7 @@ public class PlatformDefaultImpl impleme
     /**
      * {@inheritDoc}
      */
-    public String getTimestampString(Date date)
+    public String getTimestampString(final Date date)
     {
         SimpleDateFormat dateFormat = new SimpleDateFormat(TIMESTAMP_FORMAT);
         dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
@@ -223,4 +223,12 @@ public class PlatformDefaultImpl impleme
     {
         return false;
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean supportsCurrentDateFunctionsAsColumnDefaultValue()
+    {
+        return true;
+    }
 }

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMssqlImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMssqlImpl.java?rev=1698254&r1=1698253&r2=1698254&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMssqlImpl.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMssqlImpl.java
Fri Aug 28 03:45:21 2015
@@ -90,7 +90,7 @@ public class PlatformMssqlImpl extends P
      * @see Platform#getNullString(boolean)
      */
     @Override
-    public String getNullString(boolean notNull)
+    public String getNullString(final boolean notNull)
     {
         return (notNull ? "NOT NULL" : "NULL");
     }
@@ -104,7 +104,8 @@ public class PlatformMssqlImpl extends P
     /**
      * {@inheritDoc}
      */
-    public String getTimestampString(Date date)
+    @Override
+    public String getTimestampString(final Date date)
     {
         SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
         dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
@@ -118,6 +119,7 @@ public class PlatformMssqlImpl extends P
      *
      * @return this implementation returns true.
      */
+    @Override
     public boolean usesStandaloneSchema()
     {
         return true;
@@ -127,8 +129,17 @@ public class PlatformMssqlImpl extends P
      * @see Platform#hasSize(String)
      */
     @Override
-    public boolean hasSize(String sqlType)
+    public boolean hasSize(final String sqlType)
     {
         return !("IMAGE".equals(sqlType) || "TEXT".equals(sqlType));
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean supportsCurrentDateFunctionsAsColumnDefaultValue()
+    {
+        return false;
+    }
 }

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMysqlImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMysqlImpl.java?rev=1698254&r1=1698253&r2=1698254&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMysqlImpl.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/platform/PlatformMysqlImpl.java
Fri Aug 28 03:45:21 2015
@@ -90,7 +90,7 @@ public class PlatformMysqlImpl extends P
      * @see Platform#hasSize(String)
      */
     @Override
-    public boolean hasSize(String sqlType)
+    public boolean hasSize(final String sqlType)
     {
         return !("MEDIUMTEXT".equals(sqlType) || "LONGTEXT".equals(sqlType)
                 || "BLOB".equals(sqlType) || "MEDIUMBLOB".equals(sqlType)
@@ -107,10 +107,19 @@ public class PlatformMysqlImpl extends P
      * {@inheritDoc}
      */
     @Override
-    public String getDateString(Date date)
+    public String getDateString(final Date date)
     {
         SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
         dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
         return dateFormat.format(date);
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean supportsCurrentDateFunctionsAsColumnDefaultValue()
+    {
+        return false;
+    }
 }

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java?rev=1698254&r1=1698253&r2=1698254&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java
Fri Aug 28 03:45:21 2015
@@ -70,13 +70,13 @@ public class OMColumnTransformer
     private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.S";
 
     /** Constant for the CURRENT_DATE default value for Dates. */
-    static final String CURRENT_DATE = "CURRENT_DATE";
+    public static final String CURRENT_DATE = "CURRENT_DATE";
 
     /** Constant for the CURRENT_TIME default value for Dates. */
-    static final String CURRENT_TIME = "CURRENT_TIME";
+    public static final String CURRENT_TIME = "CURRENT_TIME";
 
     /** Constant for the CURRENT_TIMESTAMP default value for Dates. */
-    static final String CURRENT_TIMESTAMP = "CURRENT_TIMESTAMP";
+    public static final String CURRENT_TIMESTAMP = "CURRENT_TIMESTAMP";
 
     /** Constant for the getDefaultDate method name. */
     static final String GET_DEFAULT_DATE_METHOD_NAME = "getCurrentDate";

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java?rev=1698254&r1=1698253&r2=1698254&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java
Fri Aug 28 03:45:21 2015
@@ -25,6 +25,8 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.torque.generator.control.ControllerState;
 import org.apache.torque.generator.source.transform.SourceTransformer;
 import org.apache.torque.generator.source.transform.SourceTransformerException;
@@ -72,7 +74,10 @@ public class SQLModelTransformer impleme
     private static final IncludeSchemaTransformer includeSchemaTransformer
             = new IncludeSchemaTransformer();
 
-   public Database transform(
+    /** The logger. */
+    private static Log log = LogFactory.getLog(SourceTransformer.class);
+
+    public Database transform(
             final Object databaseModel,
             final ControllerState controllerState)
         throws SourceTransformerException
@@ -200,6 +205,18 @@ public class SQLModelTransformer impleme
 
         for (final Column column : table.columnList)
         {
+            // do not generate illegal SQL for databases which do not support CURRENT_DATE
+            if ((OMColumnTransformer.CURRENT_DATE.equalsIgnoreCase(column._default)
+                    || OMColumnTransformer.CURRENT_TIME.equalsIgnoreCase(column._default)
+                    || OMColumnTransformer.CURRENT_TIMESTAMP.equalsIgnoreCase(column._default))
+                && (SchemaType.DATE.toString().equalsIgnoreCase(column.type)
+                    || SchemaType.TIME.toString().equalsIgnoreCase(column.type)
+                    || SchemaType.TIMESTAMP.toString().equalsIgnoreCase(column.type))
+                && !getPlatform(controllerState).supportsCurrentDateFunctionsAsColumnDefaultValue())
+            {
+                column._default = null;
+                log.warn("Removed default value of " + column._default + "");
+            }
             if (column.ddlSql == null)
             {
                 column.ddlSql = getDdlSql(



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