db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1327898 - in /db/torque/torque4/trunk/torque-templates/src/main: java/org/apache/torque/templates/ java/org/apache/torque/templates/transformer/om/ resources/org/apache/torque/templates/om/templates/peer/impl/base/ resources/org/apache/tor...
Date Thu, 19 Apr 2012 11:15:05 GMT
Author: tfischer
Date: Thu Apr 19 11:15:04 2012
New Revision: 1327898

URL: http://svn.apache.org/viewvc?rev=1327898&view=rev
Log:
TORQUE-190 Create new boolean attribute useDatabaseDefaultValue on column Element in Schema
TORQUE-15 Allow database default values for columns 

Modified:
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.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/resources/org/apache/torque/templates/om/templates/peer/impl/base/buildColumnValues.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-0.xsd

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java?rev=1327898&r1=1327897&r2=1327898&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java
Thu Apr 19 11:15:04 2012
@@ -66,6 +66,8 @@ public enum TorqueSchemaAttributeName im
     PROTECTED("protected"),
     /** attribute default. */
     DEFAULT("default"),
+    /** attribute useDatabaseDefaultValue. */
+    USE_DATABASE_DEFAULT_VALUE("useDatabaseDefaultValue"),
     /** attribute class. */
     CLASS("class"),
     /** attribute baseClass. */

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=1327898&r1=1327897&r2=1327898&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
Thu Apr 19 11:15:04 2012
@@ -105,6 +105,7 @@ public class OMColumnTransformer
         setSetterNameAttribute(columnElement);
         setAccessModifierAttributes(columnElement);
         setDefaultValueAttribute(columnElement, fieldJavaType);
+        setUseDatabaseDefaultValueAttribute(columnElement);
         setResultSetGetterAttribute(columnElement, schemaType);
         setSampleObjectAttribute(columnElement, schemaType);
 
@@ -671,6 +672,26 @@ public class OMColumnTransformer
     }
 
     /**
+     * Sets the useDatabaseDefaultValue attribute of the column element to its
+     * default "false" if it is not already set.
+     *
+     * @param columnElement the column element, not null.
+     */
+    protected void setUseDatabaseDefaultValueAttribute(
+            SourceElement columnElement)
+    {
+        if (columnElement.getAttribute(
+                    TorqueSchemaAttributeName.USE_DATABASE_DEFAULT_VALUE)
+                != null)
+        {
+            return;
+        }
+        columnElement.setAttribute(
+                TorqueSchemaAttributeName.USE_DATABASE_DEFAULT_VALUE,
+                Boolean.toString(false));
+    }
+
+    /**
      * Sets the resultSetGetter attribute of the column element
      * if it is not already set.
      * If the resultSetGetter is a string value, it is converted to

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/buildColumnValues.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/buildColumnValues.vm?rev=1327898&r1=1327897&r2=1327898&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/buildColumnValues.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/buildColumnValues.vm
Thu Apr 19 11:15:04 2012
@@ -31,7 +31,9 @@
      * Returns the contents of the object as ColumnValues object.
      * Primary key columns which are generated on insertion are not
      * added to the returned object if they still have their initial
-     * value.
+     * value. Also, columns which have the useDatabaseDefaultValue
+     * flag set to true are also not added to the returned object
+     * if they still have their initial value.
      *
      * @throws TorqueException if the table map cannot be retrieved
      *         (should not happen).
@@ -49,13 +51,15 @@
   #set ( $columnFieldName = $columnElement.getAttribute("field") )
   #set ( $columnFieldType = $columnElement.getAttribute("fieldType") )
   #set ( $primitive = $columnElement.getAttribute("primitive") )
-  #if ($primaryKey && !$idMethod.equals("none"))
+  #set ( $defaultValue = $columnElement.getAttribute("defaultValue") )
+  #set ( $useDatabaseDefaultValue = $columnElement.getAttribute("useDatabaseDefaultValue")
== "true")
+  #if (($primaryKey && !$idMethod.equals("none")) || $useDatabaseDefaultValue)
     #if ("boolean" == $columnFieldType)
         if (!${field}.isNew())
-    #elseif ("true" == $primitive)
-        if (!${field}.isNew() || ${field}.$getter() != 0)
+    #elseif ("true" == $primitive || $defaultValue == "null")
+        if (!${field}.isNew() || ${field}.$getter() != $defaultValue)
     #else
-        if (!${field}.isNew() || ${field}.$getter() != null)
+        if (!${field}.isNew() || !${defaultValue}.equals(${field}.$getter()))
     #end
         {
     #if ($columnType == "DATE" && $columnFieldType == "java.util.Date")

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-0.xsd
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-0.xsd?rev=1327898&r1=1327897&r2=1327898&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-0.xsd
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/xsd/database-4-0.xsd
Thu Apr 19 11:15:04 2012
@@ -471,6 +471,15 @@ The default column value
         </xs:documentation>
       </xs:annotation>
     </xs:attribute>
+    <xs:attribute name="useDatabaseDefaultValue" type="xs:boolean" use="optional" >
+      <xs:annotation>
+        <xs:documentation xml:lang="en">
+Whether to use the database default value if a new object is saved
+and the attribute value is equal to the java default value. Default is false.
+Has no effect on primitive boolean columns.
+        </xs:documentation>
+      </xs:annotation>
+    </xs:attribute>
     <xs:attribute name="primaryKey" use="optional"
                   type="xs:boolean" default="false" >
       <xs:annotation>



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