db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1327092 - in /db/torque/torque4/trunk/torque-templates/src: main/java/org/apache/torque/templates/transformer/jdbc2schema/ main/resources/org/apache/torque/templates/jdbc2schema/conf/ test/resources/org/apache/torque/templates/jdbc2schema/
Date Tue, 17 Apr 2012 13:32:46 GMT
Author: tfischer
Date: Tue Apr 17 13:32:45 2012
New Revision: 1327092

URL: http://svn.apache.org/viewvc?rev=1327092&view=rev
Log:
TORQUE-39: The default schema name is now "default" for jdbc2schema.
It can be overridden by setting the torque.database.name option

Added:
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/Jdbc2SchemaOptionName.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/Jdbc2SchemaTransformer.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/package.html
Modified:
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/jdbc2schema/conf/control.xml
    db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/jdbc2schema/expected-schema.xml

Added: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/Jdbc2SchemaOptionName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/Jdbc2SchemaOptionName.java?rev=1327092&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/Jdbc2SchemaOptionName.java
(added)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/Jdbc2SchemaOptionName.java
Tue Apr 17 13:32:45 2012
@@ -0,0 +1,120 @@
+package org.apache.torque.templates.transformer.jdbc2schema;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.option.OptionName;
+import org.apache.torque.generator.source.transform.SourceTransformerException;
+
+/**
+ * The option names which are used in the java code of the jdbc2schema
+ * templates.
+ *
+ * $Id: $
+ */
+public enum Jdbc2SchemaOptionName implements OptionName
+{
+    /** The name of the database to generate.*/
+    DATABASE_NAME("torque.database.name", false);
+
+    /**
+     * The fully qualified name of the option.
+     */
+    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 Jdbc2SchemaOptionName(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 Jdbc2SchemaOptionName(String name, boolean required)
+    {
+        this.name = name;
+        this.required = required;
+    }
+
+    /**
+     * Returns the name of the option.
+     *
+     * @return the fully qualified name of the option, not null.
+     */
+    public String getName()
+    {
+        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()
+    {
+        return name;
+    }
+
+    /**
+     * Checks whether all required options are set.
+     *
+     * @param controllerState the current controller state, not null.
+     *
+     * @throws SourceTransformerException if a required option is not set.
+     */
+    public static void checkRequiredOptions(ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        for (Jdbc2SchemaOptionName templateOption : values())
+        {
+            if (templateOption.isRequired())
+            {
+                Object optionValue
+                    = controllerState.getOption(templateOption.getName());
+                if (optionValue == null)
+                {
+                    throw new SourceTransformerException(
+                            "Option " + templateOption.getName()
+                                    + " must be set");
+                }
+            }
+        }
+    }
+}

Added: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/Jdbc2SchemaTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/Jdbc2SchemaTransformer.java?rev=1327092&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/Jdbc2SchemaTransformer.java
(added)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/Jdbc2SchemaTransformer.java
Tue Apr 17 13:32:45 2012
@@ -0,0 +1,71 @@
+package org.apache.torque.templates.transformer.jdbc2schema;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.transform.SourceTransformer;
+import org.apache.torque.generator.source.transform.SourceTransformerException;
+import org.apache.torque.templates.TorqueSchemaAttributeName;
+
+/**
+ * Performs the transformations which are necessary to apply the jdbc2schema
+ * templates to the source tree.
+ * This transformer performs the following actions:
+ * <ul>
+ *   <li>sets the name attribute to the database element</li>
+ * </ul>
+ * No elements or attributes are deleted.
+ *
+ * $Id: $
+ */
+public class Jdbc2SchemaTransformer implements SourceTransformer
+{
+    /** Default database name if none is set. */
+    private static final String DEFAULT_DATABASE_NAME = "default";
+
+    /**
+     * Transforms the source tree so it can be used by the jdbc2schema
+     * templates.
+     *
+     * @param root the database root element of the source tree, not null.
+     * @param controllerState the controller state, not null.
+     *
+     * @throws SourceTransformerException if the transformation fails.
+     */
+    public SourceElement transform(
+                SourceElement root,
+                ControllerState controllerState)
+            throws SourceTransformerException
+    {
+        if (root.getAttribute(TorqueSchemaAttributeName.NAME) == null)
+        {
+            String name = controllerState.getStringOption(
+                    Jdbc2SchemaOptionName.DATABASE_NAME);
+            if (name == null)
+            {
+                name = DEFAULT_DATABASE_NAME;
+            }
+            root.setAttribute(TorqueSchemaAttributeName.NAME, name);
+        }
+        return root;
+    }
+
+}

Added: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/package.html?rev=1327092&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/package.html
(added)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/package.html
Tue Apr 17 13:32:45 2012
@@ -0,0 +1,25 @@
+<!--
+ Copyright 2001-2006 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License")
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+  <head>
+    <title>Torque jdbc2schema transformers</title>
+  </head>
+  <body>
+    <p>
+      Contains transformers and their helpers for the jdbc2schema templates.
+    </p>
+  </body>
+</html>

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/jdbc2schema/conf/control.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/jdbc2schema/conf/control.xml?rev=1327092&r1=1327091&r2=1327092&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/jdbc2schema/conf/control.xml
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/jdbc2schema/conf/control.xml
Tue Apr 17 13:32:45 2012
@@ -37,6 +37,7 @@
         usernameOption="torque.jdbc2schema.user"
         passwordOption="torque.jdbc2schema.password"
         schemaOption="torque.jdbc2schema.schema">
+      <transformer class="org.apache.torque.templates.transformer.jdbc2schema.Jdbc2SchemaTransformer"/>
     </source>
     <outlet name="torque.jdbc2schema"/>
   </output>

Modified: db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/jdbc2schema/expected-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/jdbc2schema/expected-schema.xml?rev=1327092&r1=1327091&r2=1327092&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/jdbc2schema/expected-schema.xml
(original)
+++ db/torque/torque4/trunk/torque-templates/src/test/resources/org/apache/torque/templates/jdbc2schema/expected-schema.xml
Tue Apr 17 13:32:45 2012
@@ -13,7 +13,7 @@
  See the License for the specific language governing permissions and
  limitations under the License.
 -->
-<database>
+<database name="default">
   <table name="AUTHOR">
     <column default="GENERATED_BY_DEFAULT" primaryKey="true" name="AUTHOR_ID" type="INTEGER"/>
     <column name="NAME" required="true" type="VARCHAR" size="50"/>



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