db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1138163 - /db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java
Date Tue, 21 Jun 2011 20:15:41 GMT
Author: tfischer
Date: Tue Jun 21 20:15:40 2011
New Revision: 1138163

URL: http://svn.apache.org/viewvc?rev=1138163&view=rev
Log:
Use the value of the idMethod attribute of the table to calculate the default value of the
autoincrement attribute for columns

Modified:
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMColumnTransformer.java

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=1138163&r1=1138162&r2=1138163&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
Tue Jun 21 20:15:40 2011
@@ -41,6 +41,8 @@ import org.apache.torque.templates.typem
 
 /**
  * Sets the class names and packages for the OM model.
+ * The id method attribute must already be set on the parent table element
+ * when this transformer is called.
  */
 public class OMColumnTransformer
 {
@@ -150,18 +152,29 @@ public class OMColumnTransformer
     private void setAttributeDefaultValues(SourceElement columnElement)
     {
         // set autoincrement attribute
-        // TODO: remove once the autoincrement attribute is removed
-        // from the Torque schema.
-        if (columnElement.getAttribute(
-                    TorqueSchemaAttributeName.AUTO_INCREMENT)
+        if (columnElement.getAttribute(TorqueSchemaAttributeName.AUTO_INCREMENT)
                 == null)
         {
-            columnElement.setAttribute(
-                TorqueSchemaAttributeName.AUTO_INCREMENT,
-                Boolean.FALSE.toString());
+            String idMethod
+                = (String) columnElement.getParent().getAttribute(
+                        TorqueSchemaAttributeName.ID_METHOD);
+            // idMethod can not be null because it is already set by the
+            // table transformer
+            if (!"none".equals(idMethod))
+            {
+                columnElement.setAttribute(
+                        TorqueSchemaAttributeName.AUTO_INCREMENT,
+                        Boolean.TRUE.toString());
+            }
+            else
+            {
+                columnElement.setAttribute(
+                    TorqueSchemaAttributeName.AUTO_INCREMENT,
+                    Boolean.FALSE.toString());
+            }
         }
 
-        // set autoincrement attribute
+        // set protected attribute
         if (columnElement.getAttribute(
                     TorqueSchemaAttributeName.PROTECTED)
                 == null)
@@ -181,6 +194,7 @@ public class OMColumnTransformer
                 Boolean.FALSE.toString());
         }
 
+        // set required attribute
         Object required = columnElement.getAttribute(
                 TorqueSchemaAttributeName.REQUIRED);
         if (required == null)
@@ -190,6 +204,7 @@ public class OMColumnTransformer
                     Boolean.FALSE.toString());
         }
 
+        // set primaryKey attribute
         Object primaryKey = columnElement.getAttribute(
                 TorqueSchemaAttributeName.PRIMARY_KEY);
         if (primaryKey == null)



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