db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1345952 - in /db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates: TemplateOptionName.java transformer/om/OMTransformer.java transformer/sql/SQLTransformer.java
Date Mon, 04 Jun 2012 13:18:13 GMT
Author: tfischer
Date: Mon Jun  4 13:18:12 2012
New Revision: 1345952

URL: http://svn.apache.org/viewvc?rev=1345952&view=rev
Log:
make option torque.database not required for om templates

Modified:
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLTransformer.java

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java?rev=1345952&r1=1345951&r2=1345952&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java
Mon Jun  4 13:18:12 2012
@@ -33,10 +33,10 @@ import org.apache.torque.generator.sourc
 public enum TemplateOptionName implements OptionName
 {
     /** The database vendor. See the schema for possible values.*/
-    DATABASE("torque.database", true),
+    DATABASE("torque.database"),
 
     /** The base package of the OM classes.*/
-    OM_PACKAGE("torque.om.package", true),
+    OM_PACKAGE("torque.om.package"),
 
     /**
      * Whether getters for boolean fields should use "is" instead of "get"
@@ -205,30 +205,13 @@ public enum TemplateOptionName implement
     private String name;
 
     /**
-     * Whether this option must be set or not.
-     */
-    private boolean required;
-
-    /**
-     * Constructor for an option which is not required..
-     *
-     * @param name the fully qualified name of the option, not null.
-     */
-    private TemplateOptionName(String name)
-    {
-        this(name, false);
-    }
-
-    /**
      * Constructor.
      *
      * @param name the fully qualified name of the option, not null.
-     * @param required whether the option is required.
      */
-    private TemplateOptionName(String name, boolean required)
+    private TemplateOptionName(String name)
     {
         this.name = name;
-        this.required = required;
     }
 
     /**
@@ -241,16 +224,6 @@ public enum TemplateOptionName implement
         return name;
     }
 
-    /**
-     * Returns whether this option must be set.
-     *
-     * @return true if the option must be set, false if it may be set.
-     */
-    public boolean isRequired()
-    {
-        return required;
-    }
-
     @Override
     public String toString()
     {
@@ -261,24 +234,23 @@ public enum TemplateOptionName implement
      * Checks whether all required options are set.
      *
      * @param controllerState the current controller state, not null.
+     * @param requiredOptions the required options to check, not null.
      *
      * @throws SourceTransformerException if a required option is not set.
      */
-    public static void checkRequiredOptions(ControllerState controllerState)
+    public static void checkRequiredOptions(ControllerState controllerState,
+            TemplateOptionName... requiredOptions)
         throws SourceTransformerException
     {
-        for (TemplateOptionName templateOption : values())
+        for (TemplateOptionName templateOption : requiredOptions)
         {
-            if (templateOption.isRequired())
+            Object optionValue
+                = controllerState.getOption(templateOption.getName());
+            if (optionValue == null)
             {
-                Object optionValue
-                    = controllerState.getOption(templateOption.getName());
-                if (optionValue == null)
-                {
-                    throw new SourceTransformerException(
-                            "Option " + templateOption.getName()
-                                    + " must be set");
-                }
+                throw new SourceTransformerException(
+                        "Option " + templateOption.getName()
+                                + " must be set");
             }
         }
     }

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java?rev=1345952&r1=1345951&r2=1345952&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java
Mon Jun  4 13:18:12 2012
@@ -121,7 +121,9 @@ public class OMTransformer implements So
             ControllerState controllerState)
         throws SourceTransformerException
     {
-        TemplateOptionName.checkRequiredOptions(controllerState);
+        TemplateOptionName.checkRequiredOptions(
+                controllerState,
+                TemplateOptionName.OM_PACKAGE);
 
         setRootDatabaseNameAttribute(root);
         DatabaseMapInitTransformer.setDatabaseMapInitClassNameAttributes(

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=1345952&r1=1345951&r2=1345952&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 Jun  4 13:18:12 2012
@@ -47,7 +47,7 @@ import org.apache.torque.templates.typem
  */
 public class SQLTransformer implements SourceTransformer
 {
-    private CollectAttributeSetTrueTransformer collectAttributeSetTrueTransformer
+    private final CollectAttributeSetTrueTransformer collectAttributeSetTrueTransformer
             = new CollectAttributeSetTrueTransformer();
 
     public SourceElement transform(
@@ -55,13 +55,9 @@ public class SQLTransformer implements S
             ControllerState controllerState)
         throws SourceTransformerException
     {
-        // TODO: move check to better place
-        Object databaseOption = controllerState.getOption("torque.database");
-        if (databaseOption == null)
-        {
-            throw new SourceTransformerException(
-                    "Option torque.database must be set");
-        }
+        TemplateOptionName.checkRequiredOptions(
+                controllerState,
+                TemplateOptionName.DATABASE);
 
         List<SourceElement> tableElements = databaseElement.getChildren(
                 TorqueSchemaElementName.TABLE.getName());



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