db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1470235 [6/7] - in /db/torque/torque4/trunk: torque-generator/ torque-generator/src/main/java/org/apache/torque/generator/configuration/ torque-generator/src/main/java/org/apache/torque/generator/configuration/outlet/ torque-generator/src/...
Date Sat, 20 Apr 2013 21:23:42 GMT
Added: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Unique.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Unique.java?rev=1470235&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Unique.java (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/Unique.java Sat Apr 20 21:23:39 2013
@@ -0,0 +1,48 @@
+package org.apache.torque.templates.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/*
+ * 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.
+ */
+
+/**
+ * The model of the unique tag in a Torque schema file.
+ *
+ * @version $Id: $
+ */
+public class Unique
+{
+    // schema properties
+
+    public Table parent;
+
+    public List<Option> optionList = new ArrayList<Option>();
+
+    public List<UniqueColumn> uniqueColumnList = new ArrayList<UniqueColumn>();
+
+    public String name;
+
+    // SQL generation properties
+
+    /** Contains all unique column names in a comma-separated String. */
+    public String uniqueColumnNames;
+
+}

Added: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/UniqueColumn.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/UniqueColumn.java?rev=1470235&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/UniqueColumn.java (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/UniqueColumn.java Sat Apr 20 21:23:39 2013
@@ -0,0 +1,34 @@
+package org.apache.torque.templates.model;
+
+
+
+/*
+ * 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.
+ */
+
+/**
+ * The model of the unique-column tag in a Torque schema file.
+ *
+ * @version $Id: $
+ */
+public class UniqueColumn
+{
+    public Unique parent;
+
+    public String name;
+}

Added: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/View.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/View.java?rev=1470235&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/View.java (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/View.java Sat Apr 20 21:23:39 2013
@@ -0,0 +1,56 @@
+package org.apache.torque.templates.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/*
+ * 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.
+ */
+
+/**
+ * The model of the view tag in a Torque schema file.
+ *
+ * @version $Id: $
+ */
+public class View
+{
+    public Database parent;
+
+    public List<Option> optionList = new ArrayList<Option>();
+
+    public List<ViewColumn> columnList;
+
+    public String name;
+
+    public String baseClass;
+
+    public String basePeer;
+
+    public String _abstract;
+
+    public String javaName;
+
+    public String sqlSuffix;
+
+    public String createSql;
+
+    public String skipSql;
+
+    public String description;
+
+}

Added: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/ViewColumn.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/ViewColumn.java?rev=1470235&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/ViewColumn.java (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/model/ViewColumn.java Sat Apr 20 21:23:39 2013
@@ -0,0 +1,58 @@
+package org.apache.torque.templates.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/*
+ * 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.
+ */
+
+/**
+ * The model of the column tag in a Torque schema file.
+ *
+ * @version $Id: $
+ */
+public class ViewColumn
+{
+    public View parent;
+
+    public List<Option> options = new ArrayList<Option>();
+
+    public List<Inheritance> inheritances = new ArrayList<Inheritance>();
+
+    public String name;
+
+    public String type;
+
+    public String size;
+
+    public String scale;
+
+    public String javaName;
+
+    public String javaType;
+
+    public String domain;
+
+    public String select;
+
+    public String _protected;
+
+    public String description;
+}

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/InterfaceSkipDecider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/InterfaceSkipDecider.java?rev=1470235&r1=1470234&r2=1470235&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/InterfaceSkipDecider.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/InterfaceSkipDecider.java Sat Apr 20 21:23:39 2013
@@ -35,7 +35,8 @@ public class InterfaceSkipDecider implem
 {
     public boolean proceed(ControllerState controllerState)
     {
-        SourceElement sourceElement = controllerState.getSourceElement();
+        SourceElement sourceElement
+                = (SourceElement) controllerState.getModel();
         String interfaceName
                 = (String) sourceElement.getAttribute(
                         TorqueSchemaAttributeName.INTERFACE.getName());

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/ManagerSkipDecider.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/ManagerSkipDecider.java?rev=1470235&r1=1470234&r2=1470235&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/ManagerSkipDecider.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/skipdecider/ManagerSkipDecider.java Sat Apr 20 21:23:39 2013
@@ -43,7 +43,8 @@ public class ManagerSkipDecider implemen
         {
             return false;
         }
-        SourceElement sourceElement = controllerState.getSourceElement();
+        SourceElement sourceElement
+                = (SourceElement) controllerState.getModel();
         if ("false".equals(sourceElement.getAttribute("useManagers")))
         {
             return false;

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/IncludeSchemaTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/IncludeSchemaTransformer.java?rev=1470235&r1=1470234&r2=1470235&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/IncludeSchemaTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/IncludeSchemaTransformer.java Sat Apr 20 21:23:39 2013
@@ -30,10 +30,13 @@ import org.apache.torque.generator.sourc
 import org.apache.torque.generator.source.SourceException;
 import org.apache.torque.generator.source.stream.FileSource;
 import org.apache.torque.generator.source.stream.XmlSourceFormat;
+import org.apache.torque.generator.source.transform.SourceElementToModelTransformer;
 import org.apache.torque.generator.source.transform.SourceTransformer;
 import org.apache.torque.generator.source.transform.SourceTransformerException;
 import org.apache.torque.templates.TorqueSchemaAttributeName;
 import org.apache.torque.templates.TorqueSchemaElementName;
+import org.apache.torque.templates.model.Database;
+import org.apache.torque.templates.model.IncludeSchema;
 
 /**
  * A SourceTransformer which includes other schemata into the current graph.
@@ -53,6 +56,12 @@ public class IncludeSchemaTransformer im
     private File baseDir;
 
     /**
+     * The transformer creating the typed model from the source graph.
+     */
+    private final SourceElementToModelTransformer toModelTransformer
+            = new SourceElementToModelTransformer(Database.class);
+
+    /**
      * Standard constructor.
      */
     public IncludeSchemaTransformer()
@@ -64,58 +73,54 @@ public class IncludeSchemaTransformer im
      *
      * @param baseDir the new base dir.
      */
-    public IncludeSchemaTransformer(File baseDir)
+    public IncludeSchemaTransformer(final File baseDir)
     {
         this.baseDir = baseDir;
     }
 
     /**
-     * Loads the external schemata tables into the current graph.
-     * The external database element is added as child of the
-     * external-schema element.
-     * Also, an all-tables child element is added to the root element,
-     * which is filled with all tables from the external schema plus its own
-     * tables.
+     * Loads the included schema objects into the current source graph.
      *
-     * @param root the database root element of the source tree, not null.
+     * @param modelRoot 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)
+            final Object modelRoot,
+            final ControllerState controllerState)
         throws SourceTransformerException
     {
-        List<SourceElement> includeSchemaList
+        final SourceElement root = (SourceElement) modelRoot;
+        final List<SourceElement> includeSchemaList
                 = root.getChildren(TorqueSchemaElementName.INCLUDE_SCHEMA);
-        List<SourceElement> childrenList = root.getChildren();
+        final List<SourceElement> childrenList = root.getChildren();
 
-        for (SourceElement includeSchemaElement : includeSchemaList)
+        for (final SourceElement includeSchemaElement : includeSchemaList)
         {
             File includeSchemaBaseDir;
             if (this.baseDir == null)
             {
-                File currentSourceFile = controllerState.getSourceFile();
+                final File currentSourceFile = controllerState.getSourceFile();
                 includeSchemaBaseDir = currentSourceFile.getParentFile();
             }
             else
             {
                 includeSchemaBaseDir = baseDir;
             }
-            String relativePath = includeSchemaElement.getAttribute(
+            final String relativePath = includeSchemaElement.getAttribute(
                     TorqueSchemaAttributeName.FILENAME)
                 .toString();
-            File includeSchemaPath
+            final File includeSchemaPath
                 = new File(includeSchemaBaseDir, relativePath);
             log.trace("Trying to read included file " + includeSchemaPath);
             try
             {
-                FileSource fileSource = new FileSource(
+                final FileSource fileSource = new FileSource(
                         new XmlSourceFormat(),
                         includeSchemaPath,
                         controllerState);
-                SourceElement includeSchemaRootElement
+                final SourceElement includeSchemaRootElement
                         = fileSource.getRootElement();
                 log.trace("successfully read included file "
                         + includeSchemaPath);
@@ -124,10 +129,10 @@ public class IncludeSchemaTransformer im
 
                 // disattach children from their current parent
                 // so that the new parent is the primary parent
-                List<SourceElement> toIncludeList
+                final List<SourceElement> toIncludeList
                         = new ArrayList<SourceElement>(
                                 includeSchemaRootElement.getChildren());
-                for (SourceElement childToInclude : toIncludeList)
+                for (final SourceElement childToInclude : toIncludeList)
                 {
                     childToInclude.getParents().clear();
                 }
@@ -137,7 +142,7 @@ public class IncludeSchemaTransformer im
                 log.trace("finished processing included file "
                         + includeSchemaPath);
             }
-            catch (SourceException e)
+            catch (final SourceException e)
             {
                 log.error("Could not construct source from schema file "
                         + includeSchemaPath,
@@ -147,4 +152,77 @@ public class IncludeSchemaTransformer im
         }
         return root;
     }
+
+    /**
+     * Loads the included schema content into the current model.
+     *
+     * @param database the database root element of the source tree, not null.
+     * @param controllerState the controller state, not null.
+     *
+     * @throws SourceTransformerException if the transformation fails.
+     */
+    public Database transform(
+            final Database database,
+            final ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        // copy original list to iterate so we can modify the model list
+        // during iteration
+        final List<IncludeSchema> originalIncludeSchemaList
+                = new ArrayList<IncludeSchema>(database.includeSchemaList);
+        for (final IncludeSchema includeSchema : originalIncludeSchemaList)
+        {
+            File includeSchemaBaseDir;
+            if (this.baseDir == null)
+            {
+                final File currentSourceFile = controllerState.getSourceFile();
+                includeSchemaBaseDir = currentSourceFile.getParentFile();
+            }
+            else
+            {
+                includeSchemaBaseDir = baseDir;
+            }
+            final File includeSchemaPath
+                = new File(includeSchemaBaseDir, includeSchema.filename);
+            log.trace("Trying to read included file " + includeSchemaPath);
+            try
+            {
+                final FileSource fileSource = new FileSource(
+                        new XmlSourceFormat(),
+                        includeSchemaPath,
+                        controllerState);
+                final SourceElement includeSchemaRootElement
+                        = fileSource.getRootElement();
+                log.trace("successfully read included file "
+                        + includeSchemaPath);
+                final Database includedDatabase
+                    = (Database) toModelTransformer.transform(
+                        includeSchemaRootElement,
+                        controllerState);
+
+                this.transform(includedDatabase, controllerState);
+
+                // add child elements from loaded schema
+                database.optionList.addAll(includedDatabase.optionList);
+                database.includeSchemaList.addAll(
+                        includedDatabase.includeSchemaList);
+                database.externalSchemaList.addAll(
+                        includedDatabase.externalSchemaList);
+                database.domainList.addAll(includedDatabase.domainList);
+                database.tableList.addAll(includedDatabase.tableList);
+                database.viewList.addAll(includedDatabase.viewList);
+
+                log.trace("finished processing included file "
+                        + includeSchemaPath);
+            }
+            catch (final SourceException e)
+            {
+                log.error("Could not construct source from schema file "
+                        + includeSchemaPath,
+                    e);
+                throw new SourceTransformerException(e);
+            }
+        }
+        return database;
+    }
 }

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/LoadExternalSchemaTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/LoadExternalSchemaTransformer.java?rev=1470235&r1=1470234&r2=1470235&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/LoadExternalSchemaTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/LoadExternalSchemaTransformer.java Sat Apr 20 21:23:39 2013
@@ -29,10 +29,13 @@ import org.apache.torque.generator.sourc
 import org.apache.torque.generator.source.SourceException;
 import org.apache.torque.generator.source.stream.FileSource;
 import org.apache.torque.generator.source.stream.XmlSourceFormat;
+import org.apache.torque.generator.source.transform.SourceElementToModelTransformer;
 import org.apache.torque.generator.source.transform.SourceTransformer;
 import org.apache.torque.generator.source.transform.SourceTransformerException;
 import org.apache.torque.templates.TorqueSchemaAttributeName;
 import org.apache.torque.templates.TorqueSchemaElementName;
+import org.apache.torque.templates.model.Database;
+import org.apache.torque.templates.model.ExternalSchema;
 import org.apache.torque.templates.transformer.om.DatabaseAttributeName;
 import org.apache.torque.templates.transformer.om.DatabaseChildElementName;
 import org.apache.torque.templates.transformer.om.mapInit.DatabaseMapInitTransformer;
@@ -56,6 +59,12 @@ public class LoadExternalSchemaTransform
     private File baseDir;
 
     /**
+     * The transformer creating the typed model from the source graph.
+     */
+    private final SourceElementToModelTransformer toModelTransformer
+            = new SourceElementToModelTransformer(Database.class);
+
+    /**
      * Standard constructor.
      */
     public LoadExternalSchemaTransformer()
@@ -67,7 +76,7 @@ public class LoadExternalSchemaTransform
      *
      * @param baseDir the new base dir.
      */
-    public LoadExternalSchemaTransformer(File baseDir)
+    public LoadExternalSchemaTransformer(final File baseDir)
     {
         this.baseDir = baseDir;
     }
@@ -80,17 +89,18 @@ public class LoadExternalSchemaTransform
      * which is filled with all tables from the external schema plus its own
      * tables.
      *
-     * @param root the database root element of the source tree, not null.
+     * @param modelRoot 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)
+            final Object modelRoot,
+            final ControllerState controllerState)
         throws SourceTransformerException
     {
-        List<SourceElement> externalSchemaElementList
+        final SourceElement root = (SourceElement) modelRoot;
+        final List<SourceElement> externalSchemaElementList
                 = root.getChildren(TorqueSchemaElementName.EXTERNAL_SCHEMA);
         SourceElement allTables = root.getChild(
                 DatabaseChildElementName.ALL_TABLES);
@@ -107,32 +117,32 @@ public class LoadExternalSchemaTransform
             root.getChildren().add(allViews);
         }
 
-        String rootDatabaseName = (String) root.getAttribute(
+        final String rootDatabaseName = (String) root.getAttribute(
                 DatabaseAttributeName.ROOT_DATABASE_NAME);
-        for (SourceElement externalSchemaElement : externalSchemaElementList)
+        for (final SourceElement externalSchemaElement : externalSchemaElementList)
         {
             File externalSchemaBaseDir;
             if (this.baseDir == null)
             {
-                File currentSourceFile = controllerState.getSourceFile();
+                final File currentSourceFile = controllerState.getSourceFile();
                 externalSchemaBaseDir = currentSourceFile.getParentFile();
             }
             else
             {
                 externalSchemaBaseDir = baseDir;
             }
-            String relativePath = externalSchemaElement.getAttribute(
+            final String relativePath = externalSchemaElement.getAttribute(
                     TorqueSchemaAttributeName.FILENAME)
                 .toString();
-            File externalSchemaPath
+            final File externalSchemaPath
                 = new File(externalSchemaBaseDir, relativePath);
             try
             {
-                FileSource fileSource = new FileSource(
+                final FileSource fileSource = new FileSource(
                         new XmlSourceFormat(),
                         externalSchemaPath,
                         controllerState);
-                SourceElement externalSchemaRootElement
+                final SourceElement externalSchemaRootElement
                         = fileSource.getRootElement();
                 externalSchemaRootElement.setAttribute(
                         DatabaseAttributeName.ROOT_DATABASE_NAME,
@@ -147,26 +157,26 @@ public class LoadExternalSchemaTransform
                 externalSchemaElement.getChildren().add(
                         externalSchemaRootElement);
 
-                SourceElement externalAllTables
+                final SourceElement externalAllTables
                         = externalSchemaRootElement.getChild(
                                 DatabaseChildElementName.ALL_TABLES);
 
                 // fill root's all-tables with all external tables
-                for (SourceElement externalTable
+                for (final SourceElement externalTable
                         : externalAllTables.getChildren(
                             TorqueSchemaElementName.TABLE))
                 {
                     allTables.getChildren().add(externalTable);
                 }
                 // fill root's all-views with all external views
-                for (SourceElement externalView
+                for (final SourceElement externalView
                         : externalAllTables.getChildren(
                             TorqueSchemaElementName.VIEW))
                 {
                     allViews.getChildren().add(externalView);
                 }
             }
-            catch (SourceException e)
+            catch (final SourceException e)
             {
                 log.error("Could not construct source from schema file "
                         + externalSchemaPath,
@@ -175,17 +185,91 @@ public class LoadExternalSchemaTransform
             }
         }
         // add own tables to root's all-tables
-        for (SourceElement table
+        for (final SourceElement table
                 : root.getChildren(TorqueSchemaElementName.TABLE))
         {
             allTables.getChildren().add(table);
         }
         // add own views to root's all-views
-        for (SourceElement view
+        for (final SourceElement view
                 : root.getChildren(TorqueSchemaElementName.VIEW))
         {
             allViews.getChildren().add(view);
         }
         return root;
     }
+
+    /**
+     * Loads the external schemata tables into the current graph.
+     * The external database element is added as child of the
+     * external-schema element.
+     * Also, an all-tables child element is added to the root element,
+     * which is filled with all tables from the external schema plus its own
+     * tables.
+     *
+     * @param database the database root element of the source tree, not null.
+     * @param controllerState the controller state, not null.
+     *
+     * @throws SourceTransformerException if the transformation fails.
+     */
+    public Database transform(
+            final Database database,
+            final ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        for (final ExternalSchema externalSchema : database.externalSchemaList)
+        {
+            File externalSchemaBaseDir;
+            if (this.baseDir == null)
+            {
+                final File currentSourceFile = controllerState.getSourceFile();
+                externalSchemaBaseDir = currentSourceFile.getParentFile();
+            }
+            else
+            {
+                externalSchemaBaseDir = baseDir;
+            }
+            final File externalSchemaPath
+                = new File(externalSchemaBaseDir, externalSchema.filename);
+            try
+            {
+                final FileSource fileSource = new FileSource(
+                        new XmlSourceFormat(),
+                        externalSchemaPath,
+                        controllerState);
+                final SourceElement externalSchemaRootElement
+                        = fileSource.getRootElement();
+                final Database externalDatabase
+                    = (Database) toModelTransformer.transform(
+                        externalSchemaRootElement,
+                        controllerState);
+                externalDatabase.rootDatabaseName = database.rootDatabaseName;
+                // TODO fix static access
+                DatabaseMapInitTransformer.setDatabaseMapInitClassNameAttributes(
+                        externalSchemaRootElement,
+                        database.rootDatabaseName,
+                        controllerState);
+
+                this.transform(externalDatabase, controllerState);
+
+                externalSchema.database = externalDatabase;
+
+                // fill root's all-tables with all external tables
+                database.allTables.addAll(externalDatabase.allTables);
+                database.allViews.addAll(externalDatabase.allViews);
+            }
+            catch (final SourceException e)
+            {
+                log.error("Could not construct source from schema file "
+                        + externalSchemaPath,
+                    e);
+                throw new SourceTransformerException(e);
+            }
+        }
+        // add own tables to root's all-tables
+        database.allTables.addAll(database.tableList);
+        // add own views to root's all-views
+        database.allViews.addAll(database.viewList);
+        return database;
+    }
 }

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/SchemaTypeHelper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/SchemaTypeHelper.java?rev=1470235&r1=1470234&r2=1470235&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/SchemaTypeHelper.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/SchemaTypeHelper.java Sat Apr 20 21:23:39 2013
@@ -28,6 +28,8 @@ import org.apache.torque.generator.sourc
 import org.apache.torque.templates.TemplateOptionName;
 import org.apache.torque.templates.TorqueSchemaAttributeName;
 import org.apache.torque.templates.TorqueSchemaElementName;
+import org.apache.torque.templates.model.Column;
+import org.apache.torque.templates.model.Domain;
 import org.apache.torque.templates.platform.Platform;
 import org.apache.torque.templates.platform.PlatformFactory;
 import org.apache.torque.templates.typemapping.SchemaType;
@@ -60,11 +62,11 @@ public final class SchemaTypeHelper
      *         in the column or if the type refers to an unknown type.
      */
     public static SchemaType getSchemaType(
-            SourceElement columnElement,
-            ControllerState controllerState)
+            final SourceElement columnElement,
+            final ControllerState controllerState)
         throws SourceTransformerException
     {
-        String columnNameFromSchema
+        final String columnNameFromSchema
                 = (String) columnElement.getAttribute(
                         TorqueSchemaAttributeName.NAME);
         if (columnNameFromSchema == null)
@@ -77,14 +79,14 @@ public final class SchemaTypeHelper
         }
 
         SchemaType schemaType = null;
-        SqlType domain = getDomain(columnElement, controllerState);
+        final SqlType domain = getDomain(columnElement, controllerState);
         if (domain != null && domain.getSqlTypeName() != null)
         {
             try
             {
                 schemaType = SchemaType.valueOf(domain.getSqlTypeName());
             }
-            catch (IllegalArgumentException e)
+            catch (final IllegalArgumentException e)
             {
                 throw new SourceTransformerException("Unknown type "
                         + domain.getSqlTypeName()
@@ -93,7 +95,7 @@ public final class SchemaTypeHelper
         }
         else
         {
-            String schemaTypeString = (String) columnElement.getAttribute(
+            final String schemaTypeString = (String) columnElement.getAttribute(
                     TorqueSchemaAttributeName.TYPE.getName());
             if (schemaTypeString == null)
             {
@@ -105,7 +107,7 @@ public final class SchemaTypeHelper
             {
                 schemaType = SchemaType.valueOf(schemaTypeString);
             }
-            catch (IllegalArgumentException e)
+            catch (final IllegalArgumentException e)
             {
                 throw new SourceTransformerException("Unknown type "
                         + schemaTypeString
@@ -117,6 +119,72 @@ public final class SchemaTypeHelper
     }
 
     /**
+     * Determines the schema type of a column.
+     *
+     * @param column the column for which the schema type should be determined;
+     *        not null.
+     * @param controllerState the controller state, not null.
+     *
+     * @return the schema type of the column, not null.
+     *
+     * @throws SourceTransformerException if the name attribute is not set
+     *         in the column or if the type refers to an unknown type.
+     */
+    public static SchemaType getSchemaType(
+            final Column column,
+            final ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        if (column.name == null)
+        {
+            throw new SourceTransformerException("The attribute "
+                    + TorqueSchemaAttributeName.NAME.getName()
+                    + " on element "
+                    + TorqueSchemaElementName.COLUMN
+                    + " is null");
+        }
+
+        SchemaType schemaType = null;
+        final SqlType domain = getDomain(
+                column,
+                controllerState);
+        if (domain != null && domain.getSqlTypeName() != null)
+        {
+            try
+            {
+                schemaType = SchemaType.valueOf(domain.getSqlTypeName());
+            }
+            catch (final IllegalArgumentException e)
+            {
+                throw new SourceTransformerException("Unknown type "
+                        + domain.getSqlTypeName()
+                        + " in Domain definition");
+            }
+        }
+        else
+        {
+            if (column.type == null)
+            {
+                throw new SourceTransformerException("type attribute not set"
+                        + " in Column "
+                        + column.name);
+            }
+            try
+            {
+                schemaType = SchemaType.valueOf(column.type);
+            }
+            catch (final IllegalArgumentException e)
+            {
+                throw new SourceTransformerException("Unknown type "
+                        + column.type
+                        + " in Column "
+                        + column.name);
+            }
+        }
+        return schemaType;
+    }
+
+    /**
      * Returns the SQL type for a schema type and the specified target database.
      *
      * @param schemaType the schema type for which the SQL type should be
@@ -136,16 +204,16 @@ public final class SchemaTypeHelper
      *         exists for the schema type.
      */
     public static SqlType getSqlType(
-            SchemaType schemaType,
-            SqlType domainType,
-            ControllerState controllerState,
+            final SchemaType schemaType,
+            final SqlType domainType,
+            final ControllerState controllerState,
             String size,
             String scale,
             String defaultValue)
     {
-        Platform platform = PlatformFactory.getPlatformFor(
+        final Platform platform = PlatformFactory.getPlatformFor(
                 controllerState.getStringOption(TemplateOptionName.DATABASE));
-        SqlType platformSqlType = platform.getSqlTypeForSchemaType(schemaType);
+        final SqlType platformSqlType = platform.getSqlTypeForSchemaType(schemaType);
         if (domainType != null)
         {
             if (size == null)
@@ -161,7 +229,7 @@ public final class SchemaTypeHelper
                 defaultValue = domainType.getDefaultValue();
             }
         }
-        SqlType result = platformSqlType.getNew(
+        final SqlType result = platformSqlType.getNew(
                 size,
                 scale,
                 defaultValue);
@@ -169,11 +237,11 @@ public final class SchemaTypeHelper
     }
 
     public static SqlType getDomain(
-                SourceElement columnElement,
-                ControllerState controllerState)
+                final SourceElement columnElement,
+                final ControllerState controllerState)
             throws SourceTransformerException
     {
-        String domainNameFromSchema
+        final String domainNameFromSchema
                 = (String) columnElement.getAttribute(
                         TorqueSchemaAttributeName.DOMAIN);
         if (domainNameFromSchema == null)
@@ -183,12 +251,12 @@ public final class SchemaTypeHelper
         }
         SourceElement domainElement = null;
         {
-            SourceElement databaseElement
+            final SourceElement databaseElement
                     = columnElement.getParent().getParent();
-            List<SourceElement> domainElementList
+            final List<SourceElement> domainElementList
                     = databaseElement.getChildren(
                             TorqueSchemaElementName.DOMAIN);
-            for (SourceElement candidate : domainElementList)
+            for (final SourceElement candidate : domainElementList)
             {
                 if (domainNameFromSchema.equals(candidate.getAttribute(
                         TorqueSchemaAttributeName.NAME)))
@@ -209,18 +277,56 @@ public final class SchemaTypeHelper
                     + columnElement.getAttribute(TorqueSchemaAttributeName.NAME)
                     + " was not found in this schema");
         }
-        String sqlType = ObjectUtils.toString(
+        final String sqlType = ObjectUtils.toString(
                 domainElement.getAttribute(TorqueSchemaAttributeName.TYPE),
                 null);
-        String defaultValue = ObjectUtils.toString(
+        final String defaultValue = ObjectUtils.toString(
                 domainElement.getAttribute(TorqueSchemaAttributeName.DEFAULT),
                 null);
-        String size = ObjectUtils.toString(
+        final String size = ObjectUtils.toString(
                 domainElement.getAttribute(TorqueSchemaAttributeName.SIZE),
                 null);
-        String scale = ObjectUtils.toString(
+        final String scale = ObjectUtils.toString(
                 domainElement.getAttribute(TorqueSchemaAttributeName.SCALE),
                 null);
         return new SqlType(sqlType, size, scale, defaultValue);
     }
+
+    public static SqlType getDomain(
+            final Column column,
+            final ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        if (column.domain == null)
+        {
+            // no domain specified
+            return null;
+        }
+        Domain domain = null;
+        {
+            for (final Domain candidate : column.parent.parent.domainList)
+            {
+                if (column.domain.equals(candidate.name))
+                {
+                    domain = candidate;
+                    break;
+                }
+            }
+        }
+        if (domain == null)
+        {
+            throw new SourceTransformerException("The domain named "
+                    + column.domain
+                    + " referenced by the column "
+                    + column.name
+                    + " in the table "
+                    + column.parent.name
+                    + " was not found in this schema");
+        }
+        return new SqlType(
+                domain.type,
+                domain.size,
+                domain.scale,
+                domain._default);
+    }
 }

Modified: 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=1470235&r1=1470234&r2=1470235&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/Jdbc2SchemaTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/jdbc2schema/Jdbc2SchemaTransformer.java Sat Apr 20 21:23:39 2013
@@ -45,16 +45,17 @@ public class Jdbc2SchemaTransformer impl
      * 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 modelRoot 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,
+                Object modelRoot,
                 ControllerState controllerState)
             throws SourceTransformerException
     {
+        SourceElement root = (SourceElement) modelRoot;
         if (root.getAttribute(TorqueSchemaAttributeName.NAME) == null)
         {
             String name = controllerState.getStringOption(

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTableAndViewTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTableAndViewTransformer.java?rev=1470235&r1=1470234&r2=1470235&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTableAndViewTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTableAndViewTransformer.java Sat Apr 20 21:23:39 2013
@@ -99,13 +99,14 @@ public class OMTableAndViewTransformer e
 
     @Override
     public SourceElement transform(
-            SourceElement tableElement,
+            Object tableModel,
             ControllerState controllerState)
         throws SourceTransformerException
     {
+        SourceElement tableElement = (SourceElement) tableModel;
         checkElementName(tableElement);
         setUnqualifiedNameAttribute(tableElement);
-        setJavaNameAttribute(tableElement,controllerState);
+        setJavaNameAttribute(tableElement, controllerState);
         setFieldNameAttribute(tableElement);
         setIdMethodAttribute(tableElement);
         setSequenceAttributeIfNecessary(tableElement);

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=1470235&r1=1470234&r2=1470235&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 Sat Apr 20 21:23:39 2013
@@ -29,6 +29,7 @@ import org.apache.torque.generator.sourc
 import org.apache.torque.templates.TemplateOptionName;
 import org.apache.torque.templates.TorqueSchemaAttributeName;
 import org.apache.torque.templates.TorqueSchemaElementName;
+import org.apache.torque.templates.model.Database;
 import org.apache.torque.templates.transformer.IncludeSchemaTransformer;
 import org.apache.torque.templates.transformer.LoadExternalSchemaTransformer;
 import org.apache.torque.templates.transformer.om.mapInit.DatabaseMapInitTransformer;
@@ -104,7 +105,7 @@ public class OMTransformer implements So
         {
             tableOrViewTransformer = new OMTableAndViewTransformer();
         }
-        catch (SourceTransformerException e)
+        catch (final SourceTransformerException e)
         {
             throw new RuntimeException(e);
         }
@@ -113,16 +114,17 @@ public class OMTransformer implements So
     /**
      * Transforms the source tree so it can be used by the om templates.
      *
-     * @param root the database root element of the source tree, not null.
+     * @param modelRoot 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)
+            final Object modelRoot,
+            final ControllerState controllerState)
         throws SourceTransformerException
     {
+        final SourceElement root = (SourceElement) modelRoot;
         TemplateOptionName.checkRequiredOptions(
                 controllerState,
                 TemplateOptionName.OM_PACKAGE);
@@ -137,7 +139,7 @@ public class OMTransformer implements So
         // load referenced external schemata
         loadExternalSchemaTransformer.transform(root, controllerState);
 
-        List<SourceElement> allTablesAndViews = new ArrayList<SourceElement>();
+        final List<SourceElement> allTablesAndViews = new ArrayList<SourceElement>();
         allTablesAndViews.addAll(
                 root.getChild(DatabaseChildElementName.ALL_TABLES)
                     .getChildren(TorqueSchemaElementName.TABLE));
@@ -145,23 +147,23 @@ public class OMTransformer implements So
                 root.getChild(DatabaseChildElementName.ALL_VIEWS)
                     .getChildren(TorqueSchemaElementName.VIEW));
 
-        for (SourceElement tableOrViewElement : allTablesAndViews)
+        for (final SourceElement tableOrViewElement : allTablesAndViews)
         {
             tableOrViewTransformer.transform(
                     tableOrViewElement,
                     controllerState);
         }
 
-        for (SourceElement tableOrViewElement : allTablesAndViews)
+        for (final SourceElement tableOrViewElement : allTablesAndViews)
         {
-            for (SourceElement columnElement : tableOrViewElement.getChildren(
+            for (final SourceElement columnElement : tableOrViewElement.getChildren(
                     TorqueSchemaElementName.COLUMN))
             {
                 foreignKeyColumnTransformer.transform(
                         columnElement,
                         controllerState);
             }
-            for (SourceElement foreignKeyElement
+            for (final SourceElement foreignKeyElement
                     : tableOrViewElement.getChildren(
                         TorqueSchemaElementName.FOREIGN_KEY))
             {
@@ -171,9 +173,9 @@ public class OMTransformer implements So
             }
         }
 
-        for (SourceElement tableOrViewElement : allTablesAndViews)
+        for (final SourceElement tableOrViewElement : allTablesAndViews)
         {
-            for (SourceElement foreignKeyElement
+            for (final SourceElement foreignKeyElement
                     : tableOrViewElement.getChildren(
                         TorqueSchemaElementName.FOREIGN_KEY))
             {
@@ -192,12 +194,23 @@ public class OMTransformer implements So
      *
      * @param databaseElement the database element, not null.
      */
-    public static void setRootDatabaseNameAttribute(SourceElement databaseElement)
+    public static void setRootDatabaseNameAttribute(final SourceElement databaseElement)
     {
-        String databaseName = (String) databaseElement.getAttribute(
+        final String databaseName = (String) databaseElement.getAttribute(
                 TorqueSchemaAttributeName.NAME);
         databaseElement.setAttribute(
                 DatabaseAttributeName.ROOT_DATABASE_NAME,
                 databaseName);
     }
+
+    /**
+     * Sets the rootDatabaseName attribute of the database element
+     * to the database's name.
+     *
+     * @param databaseElement the database element, not null.
+     */
+    public static void setRootDatabaseName(final Database database)
+    {
+        database.rootDatabaseName = database.name;
+    }
 }

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTableTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTableTransformer.java?rev=1470235&r1=1470234&r2=1470235&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTableTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTableTransformer.java Sat Apr 20 21:23:39 2013
@@ -71,10 +71,11 @@ public class DatabaseMapInitTableTransfo
 
     @Override
     public SourceElement transform(
-            SourceElement tableElement,
+            Object tableModel,
             ControllerState controllerState)
         throws SourceTransformerException
     {
+        SourceElement tableElement = (SourceElement) tableModel;
         if (!TorqueSchemaElementName.TABLE.getName().equals(
                 tableElement.getName()))
         {

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTransformer.java?rev=1470235&r1=1470234&r2=1470235&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTransformer.java Sat Apr 20 21:23:39 2013
@@ -104,10 +104,11 @@ public class DatabaseMapInitTransformer 
 
     @Override
     public SourceElement transform(
-            SourceElement rootElement,
+            Object modelRoot,
             ControllerState controllerState)
         throws SourceTransformerException
     {
+        SourceElement rootElement = (SourceElement) modelRoot;
         if (!CombinedFileSource.ROOT_ELEMENT_NAME.equals(
                 rootElement.getName()))
         {

Added: 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=1470235&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java Sat Apr 20 21:23:39 2013
@@ -0,0 +1,807 @@
+package org.apache.torque.templates.transformer.sql;
+
+/*
+ * 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 java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.SourcePath;
+import org.apache.torque.generator.source.transform.SourceTransformer;
+import org.apache.torque.generator.source.transform.SourceTransformerException;
+import org.apache.torque.templates.TemplateOptionName;
+import org.apache.torque.templates.TorqueSchemaAttributeName;
+import org.apache.torque.templates.TorqueSchemaElementName;
+import org.apache.torque.templates.TorqueSchemaIdMethod;
+import org.apache.torque.templates.model.Column;
+import org.apache.torque.templates.model.Database;
+import org.apache.torque.templates.model.ForeignKey;
+import org.apache.torque.templates.model.Index;
+import org.apache.torque.templates.model.IndexColumn;
+import org.apache.torque.templates.model.Reference;
+import org.apache.torque.templates.model.Table;
+import org.apache.torque.templates.model.Unique;
+import org.apache.torque.templates.model.UniqueColumn;
+import org.apache.torque.templates.platform.Platform;
+import org.apache.torque.templates.platform.PlatformFactory;
+import org.apache.torque.templates.transformer.CollectAttributeSetTrueTransformer;
+import org.apache.torque.templates.transformer.IncludeSchemaTransformer;
+import org.apache.torque.templates.transformer.LoadExternalSchemaTransformer;
+import org.apache.torque.templates.transformer.SchemaTypeHelper;
+import org.apache.torque.templates.transformer.om.OMColumnTransformer;
+import org.apache.torque.templates.transformer.om.OMTransformer;
+import org.apache.torque.templates.transformer.om.TableChildElementName;
+import org.apache.torque.templates.typemapping.SchemaType;
+import org.apache.torque.templates.typemapping.SqlType;
+import org.apache.torque.templates.typemapping.TypeMap;
+
+/**
+ * Transforms the tables in the OM model for sql generation.
+ */
+public class SQLModelTransformer implements SourceTransformer
+{
+    /** A CollectAttributeSetTrueTransformer instance. */
+    private static final CollectAttributeSetTrueTransformer collectAttributeSetTrueTransformer
+            = new CollectAttributeSetTrueTransformer();
+
+    /**
+     * The transformer which loads the external schemata.
+     *
+     * @see LoadExternalSchemaTransformer
+     */
+    private static final LoadExternalSchemaTransformer loadExternalSchemaTransformer
+            = new LoadExternalSchemaTransformer();
+
+    /**
+     * The transformer which includes the included schemata.
+     *
+     * @see LoadExternalSchemaTransformer
+     */
+    private static final IncludeSchemaTransformer includeSchemaTransformer
+            = new IncludeSchemaTransformer();
+
+   public Database transform(
+            final Object databaseModel,
+            final ControllerState controllerState)
+        throws SourceTransformerException
+    {
+       final Database database = (Database) databaseModel;
+       OMTransformer.setRootDatabaseName(database);
+       // include included schemata
+       includeSchemaTransformer.transform(database, controllerState);
+       // load referenced external schemata
+       loadExternalSchemaTransformer.transform(database, controllerState);
+
+       TemplateOptionName.checkRequiredOptions(
+                controllerState,
+                TemplateOptionName.DATABASE);
+
+        for (final Table table : database.allTables)
+        {
+            transformTable(table, database, controllerState);
+        }
+        addDatabaseSchemaElements(database, controllerState);
+        return database;
+    }
+
+    public void transformTable(
+            final SourceElement tableElement,
+            final ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        final String tableName = (String) tableElement.getAttribute(
+                TorqueSchemaAttributeName.NAME);
+        String unqualifiedTableName = tableName;
+        if (StringUtils.contains(tableName, "."))
+        {
+            unqualifiedTableName = tableName.substring(tableName.indexOf(".") + 1);
+        }
+        tableElement.setAttribute(
+                SqlAttributeName.UNQUALIFIED_NAME,
+                unqualifiedTableName);
+
+        final Object idMethod = tableElement.getAttribute(
+                TorqueSchemaAttributeName.ID_METHOD.getName());
+        if (idMethod == null)
+        {
+            final Object defaultIdMethod = tableElement.getParent().getAttribute(
+                    TorqueSchemaAttributeName.DEFAULT_ID_METHOD.getName());
+            if (defaultIdMethod == null)
+            {
+                throw new SourceTransformerException("id Method is not set"
+                        + " on table "
+                        + tableElement.getAttribute(
+                                TorqueSchemaAttributeName.NAME.getName())
+                        + " and defaultIdMethod is not set on database");
+            }
+            tableElement.setAttribute(
+                    TorqueSchemaAttributeName.ID_METHOD.getName(),
+                    defaultIdMethod);
+        }
+        if (tableElement.getAttribute(
+                SqlAttributeName.PRIMARY_KEY_CONSTRAINT_NAME)
+            == null)
+        {
+            final String primaryKeyConstraintName = unqualifiedTableName + "_PK";
+            tableElement.setAttribute(
+                    SqlAttributeName.PRIMARY_KEY_CONSTRAINT_NAME,
+                    primaryKeyConstraintName);
+        }
+        if (tableElement.getAttribute(SqlAttributeName.SEQUENCE_NAME)
+                == null)
+        {
+            String sequenceName = null;
+            final SourceElement idMethodParameterElement = tableElement.getChild(
+                    TorqueSchemaElementName.ID_METHOD_PARAMETER);
+            if (idMethodParameterElement != null)
+            {
+                sequenceName = (String) idMethodParameterElement.getAttribute(
+                        TorqueSchemaAttributeName.VALUE);
+            }
+            if (StringUtils.isBlank(sequenceName))
+            {
+                sequenceName = tableName + "_SEQ";
+            }
+            tableElement.setAttribute(
+                    SqlAttributeName.SEQUENCE_NAME,
+                    sequenceName);
+        }
+
+        // primary keys
+        collectAttributeSetTrueTransformer.transform(
+                tableElement,
+                controllerState,
+                TorqueSchemaElementName.COLUMN,
+                TorqueSchemaAttributeName.PRIMARY_KEY,
+                TableChildElementName.PRIMARY_KEYS);
+
+        final StringBuilder primaryKeyColumnNames = new StringBuilder();
+        final SourceElement primaryKeysElement = tableElement.getChild(
+                TableChildElementName.PRIMARY_KEYS);
+        boolean firstPk = true;
+        for (final SourceElement primaryKeyColumn : primaryKeysElement.getChildren())
+        {
+            if (!firstPk)
+            {
+                primaryKeyColumnNames.append(", ");
+            }
+            primaryKeyColumnNames.append(primaryKeyColumn.getAttribute(
+                            TorqueSchemaAttributeName.NAME.getName()));
+            firstPk = false;
+        }
+        tableElement.setAttribute(
+                SqlAttributeName.PRIMARY_KEY_COLUMN_NAMES,
+                primaryKeyColumnNames.toString());
+
+        // unique
+        int uniqueIndex = 1;
+        for (final SourceElement uniqueElement : tableElement.getChildren(
+                TorqueSchemaElementName.UNIQUE.getName()))
+        {
+            if (uniqueElement.getAttribute(
+                        TorqueSchemaAttributeName.NAME.getName())
+                    == null)
+            {
+                uniqueElement.setAttribute(
+                        TorqueSchemaAttributeName.NAME.getName(),
+                        uniqueElement.getParent().getAttribute(
+                               TorqueSchemaAttributeName.NAME.getName())
+                            + "_UQ_" + uniqueIndex);
+            }
+            final String uniqueColumnNames = collectAttributes(
+                    uniqueElement,
+                    TorqueSchemaElementName.UNIQUE_COLUMN.getName(),
+                    TorqueSchemaAttributeName.NAME.getName());
+            uniqueElement.setAttribute(
+                    SqlAttributeName.UNIQUE_COLUMN_NAMES,
+                    uniqueColumnNames);
+            ++uniqueIndex;
+        }
+
+        // index
+        int indexIndex = 1;
+        for (final SourceElement indexElement : tableElement.getChildren(
+                TorqueSchemaElementName.INDEX.getName()))
+        {
+            if (indexElement.getAttribute(
+                    TorqueSchemaAttributeName.NAME.getName())
+                    == null)
+            {
+                indexElement.setAttribute(
+                        TorqueSchemaAttributeName.NAME.getName(),
+                        indexElement.getParent().getAttribute(
+                               TorqueSchemaAttributeName.NAME.getName())
+                            + "_IDX_" + indexIndex);
+            }
+            final String indexColumnNames = collectAttributes(
+                    indexElement,
+                    TorqueSchemaElementName.INDEX_COLUMN.getName(),
+                    TorqueSchemaAttributeName.NAME.getName());
+            indexElement.setAttribute(
+                    SqlAttributeName.INDEX_COLUMN_NAMES,
+                    indexColumnNames);
+            indexIndex++;
+        }
+
+        final List<SourceElement> columnElements = tableElement.getChildren(
+                TorqueSchemaElementName.COLUMN.getName());
+        for (final SourceElement columnElement : columnElements)
+        {
+            transformColumn(columnElement, controllerState);
+        }
+        final List<SourceElement> foreignKeyElements = tableElement.getChildren(
+                TorqueSchemaElementName.FOREIGN_KEY.getName());
+
+        int fkIndex = 1;
+        for (final SourceElement foreignKeyElemenElement : foreignKeyElements)
+        {
+            transformForeignKey(
+                    foreignKeyElemenElement,
+                    controllerState,
+                    fkIndex);
+            ++fkIndex;
+        }
+    }
+
+    public void transformTable(
+            final Table table,
+            final Database database,
+            final ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        table.unqualifiedName = table.name;
+        if (StringUtils.contains(table.name, "."))
+        {
+            table.unqualifiedName
+                = table.name.substring(table.name.indexOf(".") + 1);
+        }
+
+        if (table.idMethod == null)
+        {
+            if (database.defaultIdMethod == null)
+            {
+                throw new SourceTransformerException("idMethod is not set"
+                        + " on table "
+                        + table.name
+                        + " and defaultIdMethod is not set on database");
+            }
+            table.idMethod = database.defaultIdMethod;
+        }
+        if (table.primaryKeyConstraintName == null)
+        {
+            table.primaryKeyConstraintName = table.unqualifiedName + "_PK";
+        }
+        if (table.sequenceName == null)
+        {
+            if (!table.idMethodParameterList.isEmpty())
+            {
+                table.sequenceName = table.idMethodParameterList.get(0).value;
+            }
+            if (StringUtils.isBlank(table.sequenceName))
+            {
+                table.sequenceName = table.name + "_SEQ";
+            }
+        }
+
+        // primary keys
+        for (final Column column : table.columnList)
+        {
+            if (Boolean.TRUE == column.primaryKey)
+            {
+                table.primaryKeyList.add(column);
+            }
+        }
+
+        final StringBuilder primaryKeyColumnNames = new StringBuilder();
+        for (final Column primaryKeyColumn : table.primaryKeyList)
+        {
+            if (primaryKeyColumnNames.length() != 0)
+            {
+                primaryKeyColumnNames.append(", ");
+            }
+            primaryKeyColumnNames.append(primaryKeyColumn.name);
+        }
+        table.primaryKeyColumnNames = primaryKeyColumnNames.toString();
+
+        // unique
+        int uniqueIndex = 1;
+        for (final Unique unique : table.uniqueList)
+        {
+            if (unique.name == null)
+            {
+                unique.name = table.name + "_UQ_" + uniqueIndex;
+            }
+            final StringBuilder uniqueColumnNames = new StringBuilder();
+            for (final UniqueColumn uniqueColumn : unique.uniqueColumnList)
+            {
+                if (uniqueColumnNames.length() != 0)
+                {
+                    uniqueColumnNames.append(", ");
+                }
+                uniqueColumnNames.append(uniqueColumn.name);
+            }
+            unique.uniqueColumnNames = uniqueColumnNames.toString();
+            ++uniqueIndex;
+        }
+
+        // index
+        int indexIndex = 1;
+        for (final Index index : table.indexList)
+        {
+            if (index.name == null)
+            {
+                index.name = table.name + "_IDX_" + indexIndex;
+            }
+            final StringBuilder indexColumnNames = new StringBuilder();
+            for (final IndexColumn indexColumn : index.indexColumnList)
+            {
+                if (indexColumnNames.length() != 0)
+                {
+                    indexColumnNames.append(", ");
+                }
+                indexColumnNames.append(indexColumn.name);
+            }
+            index.indexColumnNames = indexColumnNames.toString();
+            indexIndex++;
+        }
+
+        for (final Column column : table.columnList)
+        {
+            if (column.ddlSql == null)
+            {
+                column.ddlSql = getDdlSql(
+                        column,
+                        controllerState);
+            }
+        }
+
+        int fkIndex = 1;
+        for (final ForeignKey foreignKey : table.foreignKeyList)
+        {
+            transformForeignKey(
+                    foreignKey,
+                    controllerState,
+                    fkIndex);
+            ++fkIndex;
+        }
+    }
+
+    /**
+     * Enriches the column elements with additional attributes
+     * needed for SQL generation.
+     *
+     * @param columnElement the element to enrich, not null.
+     * @param controllerState the current controller state, not null.
+     *
+     * @throws SourceTransformerException if the name or type attributes
+     *         are not set or if the type is unknown.
+     */
+    private void transformColumn(
+            final SourceElement columnElement,
+            final ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        String sql = (String) columnElement.getAttribute(
+                SqlAttributeName.DDL_SQL);
+        if (sql == null)
+        {
+            sql = getDdlSql(columnElement, controllerState);
+            columnElement.setAttribute(SqlAttributeName.DDL_SQL, sql);
+        }
+    }
+
+    /**
+     * Creates the SQL for defining a column.
+     *
+     * @param columnElement the column element for which the SQL
+     *        should be created, not null.
+     * @param controllerState the current controller state, not null.
+     *
+     * @return the SQL for defining the column, not null.
+     *
+     * @throws SourceTransformerException
+     */
+    private String getDdlSql(
+            final SourceElement columnElement,
+            final ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        final SchemaType schemaType = SchemaTypeHelper.getSchemaType(
+                columnElement,
+                controllerState);
+        final SqlType domainType = SchemaTypeHelper.getDomain(
+                columnElement,
+                controllerState);
+        final Object size = columnElement.getAttribute(
+                TorqueSchemaAttributeName.SIZE);
+        final Object scale = columnElement.getAttribute(
+                TorqueSchemaAttributeName.SCALE);
+        final Object defaultValue = columnElement.getAttribute(
+                TorqueSchemaAttributeName.DEFAULT);
+        final SqlType sqlType = SchemaTypeHelper.getSqlType(
+                schemaType,
+                domainType,
+                controllerState,
+                ObjectUtils.toString(size, null),
+                ObjectUtils.toString(scale, null),
+                ObjectUtils.toString(defaultValue, null));
+        final Platform platform = getPlatform(controllerState);
+
+        final List<String> resultList = new ArrayList<String>();
+
+        String sqlTypeName = sqlType.getSqlTypeName();
+
+        if (platform.hasSize(sqlTypeName))
+        {
+            sqlTypeName += sqlType.printSize(
+                    platform.getSizeSuffix(sqlTypeName));
+        }
+
+        resultList.add(sqlTypeName);
+
+        if (StringUtils.isNotEmpty(sqlType.getDefaultValue()))
+        {
+            resultList.add("default");
+
+            if ((SchemaType.DATE == schemaType
+                    || SchemaType.TIME == schemaType
+                    || SchemaType.TIMESTAMP == schemaType))
+            {
+                if (sqlType.getDefaultValue().startsWith("CURRENT_"))
+                {
+                    resultList.add(sqlType.getDefaultValue());
+                }
+                else
+                {
+                    final Date defaultDate
+                            = OMColumnTransformer.getDefaultValueAsDate(
+                                    sqlType.getDefaultValue());
+                    if (SchemaType.DATE == schemaType)
+                    {
+                        resultList.add(platform.getDateString(defaultDate));
+                    }
+                    else if (SchemaType.TIME == schemaType)
+                    {
+                        resultList.add(platform.getTimeString(defaultDate));
+                    }
+                    else
+                    {
+                        resultList.add(platform.getTimestampString(
+                                defaultDate));
+                    }
+                }
+            }
+            else if (TypeMap.isTextType(schemaType))
+            {
+                resultList.add(platform.quoteAndEscape(
+                        sqlType.getDefaultValue()));
+            }
+            else
+            {
+                resultList.add(sqlType.getDefaultValue());
+            }
+        }
+
+        boolean primaryKey;
+        {
+            final String primaryKeyString = (String) columnElement.getAttribute(
+                    TorqueSchemaAttributeName.PRIMARY_KEY);
+            primaryKey = Boolean.parseBoolean(primaryKeyString);
+        }
+        boolean required;
+        {
+            final String requiredString = (String) columnElement.getAttribute(
+                    TorqueSchemaAttributeName.REQUIRED);
+            required = Boolean.parseBoolean(requiredString);
+        }
+        final boolean isNotNull = primaryKey || required;
+        final String isNotNullString = platform.getNullString(isNotNull);
+
+        if (platform.createNotNullBeforeAutoincrement()
+            && StringUtils.isNotEmpty(isNotNullString))
+        {
+            resultList.add(isNotNullString);
+        }
+        // if idMethod was not set explicitly by the user,
+        // the transformTable() method sets the attribute from the
+        // defaultIdMethod of the database, so this always returns
+        // the id method
+        final Object idMethod = columnElement.getParent().getAttribute(
+                TorqueSchemaAttributeName.ID_METHOD);
+        if (primaryKey
+                && TorqueSchemaIdMethod.NATIVE.getName().equals(idMethod))
+        {
+            final String autoIncrement = platform.getAutoIncrement();
+            if (StringUtils.isNotEmpty(autoIncrement))
+            {
+                resultList.add(autoIncrement);
+            }
+        }
+        if (!platform.createNotNullBeforeAutoincrement()
+                && StringUtils.isNotEmpty(isNotNullString))
+        {
+            resultList.add(isNotNullString);
+        }
+        return StringUtils.join(resultList.iterator(), ' ');
+    }
+    /**
+     * Creates the SQL for defining a column.
+     *
+     * @param column the column element for which the SQL
+     *        should be created, not null.
+     * @param controllerState the current controller state, not null.
+     *
+     * @return the SQL for defining the column, not null.
+     *
+     * @throws SourceTransformerException
+     */
+    private String getDdlSql(
+            final Column column,
+            final ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        final SchemaType schemaType = SchemaTypeHelper.getSchemaType(
+                column,
+                controllerState);
+        final SqlType domainType = SchemaTypeHelper.getDomain(
+                column,
+                controllerState);
+        final SqlType sqlType = SchemaTypeHelper.getSqlType(
+                schemaType,
+                domainType,
+                controllerState,
+                column.size,
+                column.scale,
+                column._default);
+        final Platform platform = getPlatform(controllerState);
+
+        final List<String> resultList = new ArrayList<String>();
+
+        String sqlTypeName = sqlType.getSqlTypeName();
+
+        if (platform.hasSize(sqlTypeName))
+        {
+            sqlTypeName += sqlType.printSize(
+                    platform.getSizeSuffix(sqlTypeName));
+        }
+
+        resultList.add(sqlTypeName);
+
+        if (StringUtils.isNotEmpty(sqlType.getDefaultValue()))
+        {
+            resultList.add("default");
+
+            if ((SchemaType.DATE == schemaType
+                    || SchemaType.TIME == schemaType
+                    || SchemaType.TIMESTAMP == schemaType))
+            {
+                if (sqlType.getDefaultValue().startsWith("CURRENT_"))
+                {
+                    resultList.add(sqlType.getDefaultValue());
+                }
+                else
+                {
+                    final Date defaultDate
+                            = OMColumnTransformer.getDefaultValueAsDate(
+                                    sqlType.getDefaultValue());
+                    if (SchemaType.DATE == schemaType)
+                    {
+                        resultList.add(platform.getDateString(defaultDate));
+                    }
+                    else if (SchemaType.TIME == schemaType)
+                    {
+                        resultList.add(platform.getTimeString(defaultDate));
+                    }
+                    else
+                    {
+                        resultList.add(platform.getTimestampString(
+                                defaultDate));
+                    }
+                }
+            }
+            else if (TypeMap.isTextType(schemaType))
+            {
+                resultList.add(platform.quoteAndEscape(
+                        sqlType.getDefaultValue()));
+            }
+            else
+            {
+                resultList.add(sqlType.getDefaultValue());
+            }
+        }
+
+        final boolean primaryKey = Boolean.TRUE.equals(column.primaryKey);
+        final boolean isNotNull = primaryKey
+                || Boolean.TRUE.equals(column.required);
+        final String isNotNullString = platform.getNullString(isNotNull);
+
+        if (platform.createNotNullBeforeAutoincrement()
+            && StringUtils.isNotEmpty(isNotNullString))
+        {
+            resultList.add(isNotNullString);
+        }
+        // if idMethod was not set explicitly by the user,
+        // the transformTable() method sets the attribute from the
+        // defaultIdMethod of the database, so this always returns
+        // the id method
+        if (primaryKey
+                && TorqueSchemaIdMethod.NATIVE.getName().equals(
+                        column.parent.idMethod))
+        {
+            final String autoIncrement = platform.getAutoIncrement();
+            if (StringUtils.isNotEmpty(autoIncrement))
+            {
+                resultList.add(autoIncrement);
+            }
+        }
+        if (!platform.createNotNullBeforeAutoincrement()
+                && StringUtils.isNotEmpty(isNotNullString))
+        {
+            resultList.add(isNotNullString);
+        }
+        return StringUtils.join(resultList.iterator(), ' ');
+    }
+
+    private Platform getPlatform(final ControllerState controllerState)
+    {
+        final Platform platform = PlatformFactory.getPlatformFor(
+                controllerState.getStringOption(
+                        TemplateOptionName.DATABASE));
+        return platform;
+    }
+
+    /**
+     * Sets additional attributes on foreign key elements.
+     *
+     * @param foreignKeyElement the foreign key element to enrich, not null.
+     * @param controllerState the current controller state, not null.
+     * @param fkIndex the number of the foreign-key element in the table.
+     */
+    private void transformForeignKey(
+            final SourceElement foreignKeyElement,
+            final ControllerState controllerState,
+            final int fkIndex)
+    {
+        if (foreignKeyElement.getAttribute(
+                    TorqueSchemaAttributeName.NAME.getName())
+                == null)
+        {
+            foreignKeyElement.setAttribute(
+                    TorqueSchemaAttributeName.NAME.getName(),
+                    foreignKeyElement.getParent().getAttribute(
+                           TorqueSchemaAttributeName.NAME.getName())
+                        + "_FK_" + fkIndex);
+        }
+        final String localColumnsNames = collectAttributes(
+                foreignKeyElement,
+                TorqueSchemaElementName.REFERENCE.getName(),
+                TorqueSchemaAttributeName.LOCAL.getName());
+        foreignKeyElement.setAttribute(
+                SqlAttributeName.LOCAL_COLUMN_NAMES,
+                localColumnsNames);
+        final String foreignColumnsNames = collectAttributes(
+                foreignKeyElement,
+                TorqueSchemaElementName.REFERENCE.getName(),
+                TorqueSchemaAttributeName.FOREIGN.getName());
+        foreignKeyElement.setAttribute(
+                SqlAttributeName.FOREIGN_COLUMN_NAMES,
+                foreignColumnsNames);
+    }
+
+    /**
+     * Sets additional attributes on foreign key elements.
+     *
+     * @param foreignKeyElement the foreign key element to enrich, not null.
+     * @param controllerState the current controller state, not null.
+     * @param fkIndex the number of the foreign-key element in the table.
+     */
+    private void transformForeignKey(
+            final ForeignKey foreignKey,
+            final ControllerState controllerState,
+            final int fkIndex)
+    {
+        if (foreignKey.name == null)
+        {
+            foreignKey.name = foreignKey.parent.name + "_FK_" + fkIndex;
+        }
+        final StringBuilder localColumnNames = new StringBuilder();
+        final StringBuilder foreignColumnNames = new StringBuilder();
+        for (final Reference reference : foreignKey.referenceList)
+        {
+            if (localColumnNames.length() != 0)
+            {
+                localColumnNames.append(", ");
+            }
+            localColumnNames.append(reference.local);
+            if (foreignColumnNames.length() != 0)
+            {
+                foreignColumnNames.append(", ");
+            }
+            foreignColumnNames.append(reference.foreign);
+        }
+        foreignKey.localColumnNames = localColumnNames.toString();
+        foreignKey.foreignColumnNames = foreignColumnNames.toString();
+    }
+
+    private void addDatabaseSchemaElements(
+            final Database database,
+            final ControllerState controllerState)
+    {
+        final Platform platform = getPlatform(controllerState);
+        if (!platform.usesStandaloneSchema())
+        {
+            return;
+        }
+        for (final Table table : database.allTables)
+        {
+            if (StringUtils.contains(table.name, '.'))
+            {
+                final String databaseSchema
+                        = table.name.substring(0, table.name.indexOf('.'));
+                if (!database.schemaNameList.contains(databaseSchema))
+                {
+                    database.schemaNameList.add(databaseSchema);
+                }
+            }
+        }
+    }
+
+    /**
+     * Collects attribute values in a comma-separated string.
+     * The elements on which the attribute values are read can be reached
+     * from <code>rootElement</code> via the path <code>sourcePath</code>;
+     * and on these elements, the attributes with name
+     * <code>attributeName</code> are collected.
+     *
+     * @param rootElement the base element from where to start, not null.
+     * @param sourcePath the path from <code>rootElement</code> to the elements
+     *        on which to collect the attributes.
+     * @param attributeName the name of the attributes to collect.
+     *
+     * @return a comma-separated (", ") String containing all the matching
+     *         attribute values.
+     */
+    private String collectAttributes(
+            final SourceElement rootElement,
+            final String sourcePath,
+            final String attributeName)
+    {
+        final StringBuilder result = new StringBuilder();
+        final List<SourceElement> toCollectFrom = SourcePath.getElements(
+                rootElement, sourcePath);
+        for (final SourceElement sourceElement : toCollectFrom)
+        {
+            final Object attributeValue = sourceElement.getAttribute(attributeName);
+            if (attributeValue != null)
+            {
+                if (result.length() > 0)
+                {
+                    result.append(", ");
+                }
+                result.append(sourceElement.getAttribute(attributeName));
+            }
+        }
+        return result.toString();
+    }
+}

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=1470235&r1=1470234&r2=1470235&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 Sat Apr 20 21:23:39 2013
@@ -74,10 +74,11 @@ public class SQLTransformer implements S
             = new IncludeSchemaTransformer();
 
    public SourceElement transform(
-            SourceElement databaseElement,
+            Object databaseModel,
             ControllerState controllerState)
         throws SourceTransformerException
     {
+       SourceElement databaseElement = (SourceElement) databaseModel;
        OMTransformer.setRootDatabaseNameAttribute(databaseElement);
        // include included schemata
        includeSchemaTransformer.transform(databaseElement, controllerState);

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/doc/html/conf/control.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/doc/html/conf/control.xml?rev=1470235&r1=1470234&r2=1470235&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/doc/html/conf/control.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/doc/html/conf/control.xml Sat Apr 20 21:23:39 2013
@@ -34,7 +34,7 @@
 
   <!-- Documentation css -->
   <output name="torque.doc.html.css" file="datamodel.css">
-    <source xsi:type="fileSource" elements="database">
+    <source xsi:type="fileSource">
       <include>*schema.xml</include>
     </source>
     <outlet name="torque.doc.html.css"/>
@@ -48,7 +48,7 @@
       <discardFrom>.</discardFrom>
       <suffix>.html</suffix>
     </filenameOutlet>
-    <source xsi:type="fileSource" elements="database">
+    <source xsi:type="fileSource">
       <transformer class="org.apache.torque.templates.transformer.om.OMTransformer"/>
       <include>*schema.xml</include>
     </source>

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/doc/xdoc/conf/control.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/doc/xdoc/conf/control.xml?rev=1470235&r1=1470234&r2=1470235&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/doc/xdoc/conf/control.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/doc/xdoc/conf/control.xml Sat Apr 20 21:23:39 2013
@@ -34,7 +34,7 @@
 
   <!-- Documentation xdoc -->
   <output name="torque.doc.xdoc.xdoc"  file="datamodel.xml">
-    <source xsi:type="fileSource" elements="database">
+    <source xsi:type="fileSource">
       <transformer class="org.apache.torque.templates.transformer.om.OMTransformer"/>
       <include>*schema.xml</include>
     </source>



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