db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r930828 - in /db/torque/torque4/trunk/torque-templates/src: main/java/org/apache/torque/templates/ main/java/org/apache/torque/templates/transformer/om/ main/resources/org/apache/torque/templates/om/templates/dbObject/base/ main/resources/o...
Date Mon, 05 Apr 2010 08:23:23 GMT
Author: tfischer
Date: Mon Apr  5 08:23:23 2010
New Revision: 930828

URL: http://svn.apache.org/viewvc?rev=930828&view=rev
Log:
Added external schema handling

Added:
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/LoadExternalSchemaTransformer.java
    db/torque/torque4/trunk/torque-templates/src/test/schema/ext-schema.xml
    db/torque/torque4/trunk/torque-templates/src/test/schema/extext-schema.xml
Modified:
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaElementName.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMForeignKeyTransformer.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableAttributeName.java
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/bean/objectBeanMethods.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/copyMethods.vm
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/saveMethods.vm
    db/torque/torque4/trunk/torque-templates/src/test/java/org/apache/torque/templates/TestProcessing.java
    db/torque/torque4/trunk/torque-templates/src/test/schema/schema.xml

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java?rev=930828&r1=930827&r2=930828&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaAttributeName.java
Mon Apr  5 08:23:23 2010
@@ -77,7 +77,9 @@ public enum TorqueSchemaAttributeName im
     /** attribute size. */
     SIZE("size"),
     /** attribute scale. */
-    SCALE("scale");
+    SCALE("scale"),
+    /** attribute filename. */
+    FILENAME("filename");
 
     /** The name of the attribute, not null. */
     private String name;

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaElementName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaElementName.java?rev=930828&r1=930827&r2=930828&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaElementName.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TorqueSchemaElementName.java
Mon Apr  5 08:23:23 2010
@@ -30,6 +30,8 @@ public enum TorqueSchemaElementName impl
 {
     /** element database. */
     DATABASE("database"),
+    /** element external-schema */
+    EXTERNAL_SCHEMA("external-schema"),
     /** element table. */
     TABLE("table"),
     /** element column. */

Added: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/LoadExternalSchemaTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/LoadExternalSchemaTransformer.java?rev=930828&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/LoadExternalSchemaTransformer.java
(added)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/LoadExternalSchemaTransformer.java
Mon Apr  5 08:23:23 2010
@@ -0,0 +1,94 @@
+package org.apache.torque.templates.transformer.om;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.torque.gf.configuration.ConfigurationException;
+import org.apache.torque.gf.control.ControllerState;
+import org.apache.torque.gf.source.FileSource;
+import org.apache.torque.gf.source.SourceElement;
+import org.apache.torque.gf.source.SourceException;
+import org.apache.torque.gf.source.TransformerDefinition;
+import org.apache.torque.gf.source.transform.SourceTransformer;
+import org.apache.torque.gf.source.transform.SourceTransformerException;
+import org.apache.torque.gf.source.xml.XmlSourceType;
+import org.apache.torque.templates.TorqueSchemaAttributeName;
+import org.apache.torque.templates.TorqueSchemaElementName;
+
+public class LoadExternalSchemaTransformer implements SourceTransformer
+{
+    private static Log log 
+            = LogFactory.getLog(LoadExternalSchemaTransformer.class);
+
+    /**
+     * Loads the external schemata tables as children of the external-schema
+     * element into the current graph.
+     *
+     * @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
+    {
+        List<SourceElement> externalSchemaElementList 
+                = root.getChildren(TorqueSchemaElementName.EXTERNAL_SCHEMA);
+        for (SourceElement externalSchemaElement : externalSchemaElementList)
+        {
+            
+            File currentSourceFile = controllerState.getSourceFile();
+            File baseDir = currentSourceFile.getParentFile();
+            String relativePath = externalSchemaElement.getAttribute(
+                    TorqueSchemaAttributeName.FILENAME)
+                .toString();
+            File externalSchemaPath = new File(baseDir, relativePath);
+            try
+            {
+                FileSource fileSource = new FileSource(
+                        new XmlSourceType(),
+                        externalSchemaPath,
+                        null,
+                        null,
+                        new ArrayList<TransformerDefinition>());
+                SourceElement externalSchemaRootElement 
+                        = fileSource.getRootElement();
+                this.transform(externalSchemaRootElement, controllerState);
+                Iterator<SourceElement> childIt 
+                        = externalSchemaRootElement.getChildren().iterator();
+                while (childIt.hasNext())
+                {
+                    SourceElement child = childIt.next();
+                    root.getChildren().add(child);
+                    child.setAttribute(
+                            TableAttributeName.FROM_EXTERNAL_SCHEMA,
+                            relativePath);
+                    // disattach from previous parent so that the 
+                    // new parent is the primary parent. 
+                    childIt.remove();
+                }
+            } 
+            catch (ConfigurationException e)
+            {
+                log.error("Could not load external schema file "
+                        + externalSchemaPath,
+                    e);
+                throw new SourceTransformerException(e);
+            }
+            catch (SourceException e)
+            {
+                log.error("Could not construct source from schema file "
+                        + externalSchemaPath,
+                    e);
+                throw new SourceTransformerException(e);
+            }
+        }
+        return root;
+    }
+}

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMForeignKeyTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMForeignKeyTransformer.java?rev=930828&r1=930827&r2=930828&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMForeignKeyTransformer.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMForeignKeyTransformer.java
Mon Apr  5 08:23:23 2010
@@ -137,6 +137,10 @@ public class OMForeignKeyTransformer
             }
         }
 
+        // create reference only if this table was not loaded from
+        // an external schema
+        if (localTable.getAttribute(TableAttributeName.FROM_EXTERNAL_SCHEMA) 
+                == null)
         {
             // create attributes for a field in the local table referencing
             // the foreign table. This field will store one instance of the
@@ -290,6 +294,10 @@ public class OMForeignKeyTransformer
             }
         }
 
+        // create backreference only if the foreign table was not loaded from
+        // an external schema
+        if (foreignTable.getAttribute(TableAttributeName.FROM_EXTERNAL_SCHEMA) 
+                == null)
         {
             // create attributes for a field in the foreign table referencing
             // the local table. As more than one foreign object can point

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=930828&r1=930827&r2=930828&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java
Mon Apr  5 08:23:23 2010
@@ -69,6 +69,14 @@ public class OMTransformer implements So
      */
     private static final OMTableTransformer tableTransformer;
 
+    /**
+     * The transformer which loads the external schemata.
+     *
+     * @see LoadExternalSchemaTransformer
+     */
+    private static final SourceTransformer loadExternalSchemaTransformer
+            = new LoadExternalSchemaTransformer();
+
     static
     {
         try
@@ -96,6 +104,8 @@ public class OMTransformer implements So
     {
         TemplateOptionName.checkRequiredOptions(controllerState);
 
+        loadExternalSchemaTransformer.transform(root, controllerState);
+        
         for (SourceElement tableElement : root.getChildren(
                 TorqueSchemaElementName.TABLE.getName()))
         {

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableAttributeName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableAttributeName.java?rev=930828&r1=930827&r2=930828&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableAttributeName.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/TableAttributeName.java
Mon Apr  5 08:23:23 2010
@@ -60,7 +60,12 @@ public enum TableAttributeName implement
     /**
      * The package name of the bean class.
      */
-    BEAN_PACKAGE("beanPackage");
+    BEAN_PACKAGE("beanPackage"),
+
+    /**
+     * The file name of the external schema from which this Element stems.
+     */
+    FROM_EXTERNAL_SCHEMA("fromExternalSchema");
 
     /** The name of the source element attribute, not null. */
     private String name;

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/bean/objectBeanMethods.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/bean/objectBeanMethods.vm?rev=930828&r1=930827&r2=930828&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/bean/objectBeanMethods.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/bean/objectBeanMethods.vm
Mon Apr  5 08:23:23 2010
@@ -69,16 +69,19 @@
       #set ( $foreignTableElement = $foreignKeyElement.getParent() )
       #set ( $foreignTableName = $foreignTableElement.getAttribute("name") )
       #if ($foreignTableName != $name)
-        #set ( $foreignClassName = $foreignTableElement.getAttribute("javaName") )
-        #set ( $foreignBeanClassName = $foreignTableElement.getAttribute("beanClassName")
)
         #set ( $fieldElement = $foreignKeyElement.getChild("foreign-field") )
-        #set ( $field = $fieldElement.getAttribute("field") )
-        #set ( $fieldContainedType = $fieldElement.getAttribute("fieldContainedType") )
-        #set ( $beanFieldElement = $foreignKeyElement.getChild("foreign-field-in-bean") )
-        #set ( $beanFieldType = $beanFieldElement.getAttribute("fieldType") )
-        #set ( $beanFieldContainedType = $beanFieldElement.getAttribute("fieldContainedType")
)
-        #set ( $beanFieldInitializerType = $beanFieldElement.getAttribute("initializerType")
)
-        #set ( $beanFieldSetter = $beanFieldElement.getAttribute("setter") )
+        ## if the referencing table is in an external schema, 
+        ## fieldElement is null. In this case,skip the following code.
+        #if ($fieldElement)
+          #set ( $foreignClassName = $foreignTableElement.getAttribute("javaName") )
+          #set ( $foreignBeanClassName = $foreignTableElement.getAttribute("beanClassName")
)
+          #set ( $field = $fieldElement.getAttribute("field") )
+          #set ( $fieldContainedType = $fieldElement.getAttribute("fieldContainedType") )
+          #set ( $beanFieldElement = $foreignKeyElement.getChild("foreign-field-in-bean")
)
+          #set ( $beanFieldType = $beanFieldElement.getAttribute("fieldType") )
+          #set ( $beanFieldContainedType = $beanFieldElement.getAttribute("fieldContainedType")
)
+          #set ( $beanFieldInitializerType = $beanFieldElement.getAttribute("initializerType")
)
+          #set ( $beanFieldSetter = $beanFieldElement.getAttribute("setter") )
         if ($field != null)
         {
             ${beanFieldType} relatedBeans = new ${beanFieldInitializerType}(${field}.size());
@@ -90,6 +93,7 @@
             }
             result.${beanFieldSetter}(relatedBeans);
         }
+        #end
       #end
     #end
   #end
@@ -168,15 +172,18 @@
       #set ( $foreignTableElement = $foreignKeyElement.getParent() )
       #set ( $foreignTableName = $foreignTableElement.getAttribute("name") )
       #if ($foreignTableName != $name)
-        #set ( $foreignClassName = $foreignTableElement.getAttribute("javaName") )
-        #set ( $foreignBeanClassName = $foreignTableElement.getAttribute("beanClassName")
)
         #set ( $fieldElement = $foreignKeyElement.getChild("foreign-field") )
-        #set ( $field = $fieldElement.getAttribute("field") )
-        #set ( $fieldType = $fieldElement.getAttribute("fieldType") )
-        #set ( $fieldContainedType = $fieldElement.getAttribute("fieldContainedType") )
-        #set ( $initializerType = $fieldElement.getAttribute("initializerType") )
-        #set ( $beanGetter = $fieldElement.getAttribute("beanGetter") )
-        #set ( $adder = $fieldElement.getAttribute("adder") )
+        ## if the referencing table is in an external schema, 
+        ## fieldElement is null. In this case,skip the following code.
+        #if ($fieldElement)
+          #set ( $foreignClassName = $foreignTableElement.getAttribute("javaName") )
+          #set ( $foreignBeanClassName = $foreignTableElement.getAttribute("beanClassName")
)
+          #set ( $field = $fieldElement.getAttribute("field") )
+          #set ( $fieldType = $fieldElement.getAttribute("fieldType") )
+          #set ( $fieldContainedType = $fieldElement.getAttribute("fieldContainedType") )
+          #set ( $initializerType = $fieldElement.getAttribute("initializerType") )
+          #set ( $beanGetter = $fieldElement.getAttribute("beanGetter") )
+          #set ( $adder = $fieldElement.getAttribute("adder") )
         {
             List#if($java5 == "true")<$foreignBeanClassName>#end relatedBeans = bean.${beanGetter}();
             if (relatedBeans != null)
@@ -189,6 +196,7 @@
                 }
             }
         }
+        #end
       #end
     #end
   #end
@@ -220,15 +228,18 @@
   ## foreign references to this Object
   #if ($objectIsCaching)
     #foreach ($foreignKeyElement in $referencingForeignKeyElements)
-      #set ( $foreignTableElement = $foreignKeyElement.getParent() )
-      #set ( $foreignTableName = $foreignTableElement.getAttribute("name") )
-      #if ($foreignTableName != $name)
-        #set ( $foreignClassName = $foreignTableElement.getAttribute("javaName") )
-        #set ( $fieldElement = $foreignKeyElement.getChild("foreign-field") )
-        #set ( $field = $fieldElement.getAttribute("field") )
-        #set ( $initializerType = $fieldElement.getAttribute("initializerType") )
-        #set ( $adder = $fieldElement.getAttribute("adder") )
-        #set ( $initializer = $fieldElement.getAttribute("initializer") )
+      #set ( $fieldElement = $foreignKeyElement.getChild("foreign-field") )
+      ## if the referencing table is in an external schema, 
+      ## fieldElement is null. In this case,skip the following code.
+      #if ($fieldElement)
+        #set ( $foreignTableElement = $foreignKeyElement.getParent() )
+        #set ( $foreignTableName = $foreignTableElement.getAttribute("name") )
+        #if ($foreignTableName != $name)
+          #set ( $foreignClassName = $foreignTableElement.getAttribute("javaName") )
+          #set ( $field = $fieldElement.getAttribute("field") )
+          #set ( $initializerType = $fieldElement.getAttribute("initializerType") )
+          #set ( $adder = $fieldElement.getAttribute("adder") )
+          #set ( $initializer = $fieldElement.getAttribute("initializer") )
  
     /**
      * Method called to associate a $foreignClassName object to this object.
@@ -242,6 +253,7 @@
         ${initializer}();
         ${field}.add(toAdd);
     }
+        #end
       #end
     #end
   #end

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/copyMethods.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/copyMethods.vm?rev=930828&r1=930827&r2=930828&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/copyMethods.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/copyMethods.vm
Mon Apr  5 08:23:23 2010
@@ -149,16 +149,19 @@
         if (deepcopy)
         {
   #foreach ($foreignKeyElement in $foreignKeyElements)
-    #set ( $foreignTableElement = $foreignKeyElement.getParent())
-    #set ( $foreignTableName = $foreignTableElement.getAttribute("name"))
     #set ( $foreignFieldElement = $foreignKeyElement.getChild("foreign-field"))
-    #set ( $field = $foreignFieldElement.getAttribute("field"))
-    #set ( $fieldType = $foreignFieldElement.getAttribute("fieldType"))
-    #set ( $fieldContainedType = $foreignFieldElement.getAttribute("fieldContainedType"))
-    #set ( $getter = $foreignFieldElement.getAttribute("getter"))
-    #set ( $adder = $foreignFieldElement.getAttribute("adder"))
-    #if ($foreignTableName != $name)
-      #if ($objectIsCaching)
+    ## if the referencing table is in an external schema, 
+    ## foreignFieldElement is null. In this case,skip the foolowing code.
+    #if ($foreignFieldElement)
+      #set ( $foreignTableElement = $foreignKeyElement.getParent())
+      #set ( $foreignTableName = $foreignTableElement.getAttribute("name"))
+      #set ( $field = $foreignFieldElement.getAttribute("field"))
+      #set ( $fieldType = $foreignFieldElement.getAttribute("fieldType"))
+      #set ( $fieldContainedType = $foreignFieldElement.getAttribute("fieldContainedType"))
+      #set ( $getter = $foreignFieldElement.getAttribute("getter"))
+      #set ( $adder = $foreignFieldElement.getAttribute("adder"))
+      #if ($foreignTableName != $name)
+        #if ($objectIsCaching)
           ## field can be null if the generator property
           ## torque.silentDbFetch is set to false
             if ($field != null)
@@ -173,6 +176,7 @@
             {
                 copyObj.${field} = null;
             }
+        #end
       #end
     #end
   #end
@@ -215,22 +219,26 @@
         if (deepcopy)
         {
   #foreach ($foreignKeyElement in $foreignKeyElements)
-    #set ( $foreignTableElement = $foreignKeyElement.getParent())
-    #set ( $foreignTableName = $foreignTableElement.getAttribute("name"))
     #set ( $foreignFieldElement = $foreignKeyElement.getChild("foreign-field"))
-    #set ( $field = $foreignFieldElement.getAttribute("field"))
-    #set ( $fieldType = $foreignFieldElement.getAttribute("fieldType"))
-    #set ( $fieldContainedType = $foreignFieldElement.getAttribute("fieldContainedType"))
-    #set ( $getter = $foreignFieldElement.getAttribute("getter"))
-    #set ( $adder = $foreignFieldElement.getAttribute("adder"))
-    #if ($foreignTableName != $name)
-      #if ($objectIsCaching)
+    ## if the referencing table is in an external schema, 
+    ## foreignFieldElement is null. In this case,skip the foolowing code.
+    #if ($foreignFieldElement)
+      #set ( $foreignTableElement = $foreignKeyElement.getParent())
+      #set ( $foreignTableName = $foreignTableElement.getAttribute("name"))
+      #set ( $field = $foreignFieldElement.getAttribute("field"))
+      #set ( $fieldType = $foreignFieldElement.getAttribute("fieldType"))
+      #set ( $fieldContainedType = $foreignFieldElement.getAttribute("fieldContainedType"))
+      #set ( $getter = $foreignFieldElement.getAttribute("getter"))
+      #set ( $adder = $foreignFieldElement.getAttribute("adder"))
+      #if ($foreignTableName != $name)
+        #if ($objectIsCaching)
             $getter(con);
             for (int i = 0; i < ${field}.size(); i++)
             {
                 ${fieldContainedType} obj = #if($java5 != "true")($fieldContainedType) #end${field}.get(i);
                 copyObj.${adder}(obj.copy());
             }
+        #end
       #end
     #end
   #end

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/saveMethods.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/saveMethods.vm?rev=930828&r1=930827&r2=930828&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/saveMethods.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/saveMethods.vm
Mon Apr  5 08:23:23 2010
@@ -159,6 +159,9 @@
       #set ( $otherClassName = $otherTable.getAttribute("baseDbObjectClassName") )
       #set ( $relCol = "" )
       #set ( $field = $referencingForeignKeyElement.getChild("foreign-field").getAttribute("field"))
+      ## if the referencing table is in an external schema, field is null.
+      ## In this case,skip the foolowing code
+      #if ($field)
             if ($field != null)
             {
                 for (int i = 0; i < ${field}.size(); i++)
@@ -166,6 +169,7 @@
                     ((${otherClassName}) ${field}.get(i)).save(con);
                 }
             }
+      #end
     #end
   #end
             alreadyInSave = false;

Modified: db/torque/torque4/trunk/torque-templates/src/test/java/org/apache/torque/templates/TestProcessing.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/java/org/apache/torque/templates/TestProcessing.java?rev=930828&r1=930827&r2=930828&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/java/org/apache/torque/templates/TestProcessing.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/test/java/org/apache/torque/templates/TestProcessing.java
Mon Apr  5 08:23:23 2010
@@ -22,8 +22,10 @@ package org.apache.torque.templates;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.torque.gf.configuration.UnitDescriptor;
 import org.apache.torque.gf.configuration.option.MapOptionsConfiguration;
@@ -31,6 +33,7 @@ import org.apache.torque.gf.configuratio
 import org.apache.torque.gf.configuration.paths.DefaultTorqueGfPaths;
 import org.apache.torque.gf.configuration.paths.Maven2DirectoryProjectPaths;
 import org.apache.torque.gf.control.Controller;
+import org.apache.torque.gf.file.Fileset;
 import org.junit.Test;
 
 public class TestProcessing
@@ -54,12 +57,16 @@ public class TestProcessing
                 new File("src/test/schema"));
         projectPaths.setModifiedFileTargetDir(
                 new File("target/generated-sources-2"));
+        Fileset sourceFileset = new Fileset();
+        Set<String> sourceIncludes = new HashSet<String>();
+        sourceIncludes.add("schema.xml");
+        sourceFileset.setIncludes(sourceIncludes);
         unitDescriptors.add(new UnitDescriptor(
                 UnitDescriptor.Packaging.DIRECTORY,
                 projectPaths,
                 new DefaultTorqueGfPaths(),
                 null,
-                null,
+                sourceFileset,
                 new MapOptionsConfiguration(overrideOptions),
                 null));
 

Added: db/torque/torque4/trunk/torque-templates/src/test/schema/ext-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/schema/ext-schema.xml?rev=930828&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/schema/ext-schema.xml (added)
+++ db/torque/torque4/trunk/torque-templates/src/test/schema/ext-schema.xml Mon Apr  5 08:23:23
2010
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
+<!--
+ 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.
+-->
+<!--DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_2.dtd"-->
+
+<database
+  name="@DATABASE_DEFAULT@"
+  defaultIdMethod="@DATABASE_ID_METHOD@"
+  package="org.apache.torque.test.ext">
+
+  <external-schema filename="extext-schema.xml" />
+
+  <table name="ext">
+    <column
+      name="ext_id"
+      required="true"
+      primaryKey="true"
+      type="INTEGER"
+    />
+    <column
+      name="test"
+      required="true"
+      type="VARCHAR"
+      size="15"
+    />
+  </table>
+</database>

Added: db/torque/torque4/trunk/torque-templates/src/test/schema/extext-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/schema/extext-schema.xml?rev=930828&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/schema/extext-schema.xml (added)
+++ db/torque/torque4/trunk/torque-templates/src/test/schema/extext-schema.xml Mon Apr  5
08:23:23 2010
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
+<!--
+ 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.
+-->
+<!--DOCTYPE database SYSTEM "http://db.apache.org/torque/dtd/database_3_2.dtd"-->
+
+<database
+  name="@DATABASE_DEFAULT@"
+  defaultIdMethod="@DATABASE_ID_METHOD@">
+
+  <table name="extext">
+    <column
+      name="extext_id"
+      required="true"
+      primaryKey="true"
+      type="INTEGER"
+    />
+    <column
+      name="test"
+      required="true"
+      type="VARCHAR"
+      size="15"
+    />
+  </table>
+</database>

Modified: db/torque/torque4/trunk/torque-templates/src/test/schema/schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/test/schema/schema.xml?rev=930828&r1=930827&r2=930828&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/test/schema/schema.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/test/schema/schema.xml Mon Apr  5 08:23:23
2010
@@ -23,98 +23,13 @@
   name="bookstore"
   defaultIdMethod="native">
 
-  <!-- =================================================== -->
-  <!-- B O O K  T A B L E                                  -->
-  <!-- =================================================== -->
-
-  <table name="book" description="Book table">
-    <column
-      name="book_id"
-      required="true"
-      primaryKey="true"
-      type="INTEGER"
-      description="Book Id"
-    />
-    <column
-      name="isbn"
-      required="true"
-      type="VARCHAR"
-      size="15"
-      description="ISBN"
-    />
-    <column
-      name="author_id"
-      required="true"
-      type="INTEGER"
-      description="Foreign Key Author"
-    />
-    <column
-      name="title"
-      required="true"
-      type="VARCHAR"
-      size="255"
-      description="Book Title"
-    />
-
-    <foreign-key name="AUTHOR_FK" foreignTable="author" onUpdate="cascade" onDelete="setNull">
-      <reference local="author_id" foreign="author_id"/>
-    </foreign-key>
-
-    <unique>
-      <unique-column name="isbn" />
-    </unique>
-
-    <index name="TITLE_INDEX">
-      <index-column name="title" />
-    </index>
-  </table>
-
-
-  <!-- =================================================== -->
-  <!-- A U T H O R  T A B L E                              -->
-  <!-- =================================================== -->
-
-  <table name="author" description="Author table">
-    <column
-      name="author_id"
-      required="true"
-      primaryKey="true"
-      type="INTEGER"
-    />
-    <column
-      name="name"
-      required="true"
-      type="VARCHAR"
-      size="50"
-    />
-
-  </table>
-
-
-  <!-- =================================================== -->
-  <!-- T E S T   T A B L E                                 -->
-  <!-- =================================================== -->
-
-  <!-- TRQS51 Datadump does not recognize null columns properly -->
-  <table name="NULL_VALUE_TABLE"
-         description="table containing null values to test datadump">
-    <column name="NULL_VALUE_TABLE_ID" primaryKey="true" required="true" type="INTEGER"/>
-    <column name="number1" type="INTEGER"/>
-    <column name="number2" type="INTEGER" default="2"/>
-    <column name="number3" type="INTEGER"/>
-    <column name="text1" type="VARCHAR" size="20"/>
-    <column name="text2" type="VARCHAR" size="20" default="defaultValue"/>
-    <column name="number_obj1" type="INTEGER" javaType="object"/>
-    <column name="number_obj2" type="INTEGER" javaType="object" default="2"/>
-
-  </table>
-
+  <external-schema filename="ext-schema.xml" />
 
   <!-- =================================================== -->
   <!-- A  T A B L E                                        -->
   <!-- =================================================== -->
 
-  <table name="a" description="A table">
+  <!-- table name="a" description="A table">
     <column
       name="a_id"
       required="true"
@@ -128,13 +43,13 @@
       size="50"
     />
 
-  </table>
+  </table-->
 
   <!-- =================================================== -->
   <!-- B  T A B L E                                        -->
   <!-- =================================================== -->
 
-  <table name="b" description="B table">
+  <!-- table name="b" description="B table">
     <column
       name="b_id"
       required="true"
@@ -148,14 +63,14 @@
       size="50"
     />
 
-  </table>
+  </table-->
 
 
   <!-- =================================================== -->
   <!-- AB  T A B L E                                       -->
   <!-- =================================================== -->
 
-  <table name="r_ab" description="r_ab table" idMethod="none">
+  <!-- table name="r_ab" description="r_ab table" idMethod="none">
     <column
       name="a_id"
       required="true"
@@ -183,13 +98,13 @@
       <reference local="b_id" foreign="b_id"/>
     </foreign-key>
 
-  </table>
+  </table-->
 
   <!-- =================================================== -->
   <!-- C  T A B L E                                       -->
   <!-- =================================================== -->
 
-  <table name="c" description="c table contains fk to ar_ab, a and b">
+  <!-- table name="c" description="c table contains fk to ar_ab, a and b">
     <column
       name="c_id"
       required="true"
@@ -242,14 +157,14 @@
         <reference local="a_id" foreign="a_id"/>
         <reference local="b_id" foreign="b_id"/>
     </foreign-key>
-  </table>
+  </table-->
 
 
   <!-- =================================================== -->
   <!-- N O P K  T A B L E                                  -->
   <!-- =================================================== -->
 
-  <table name="nopk" idMethod="none" description="this table has no pk">
+  <!-- table name="nopk" idMethod="none" description="this table has no pk">
     <column
       name="intcol"
       type="INTEGER"
@@ -272,13 +187,13 @@
       <reference foreign="COL1" local="PARENT_COL1"/>
       <reference foreign="COL2" local="PARENT_COL2"/>
     </foreign-key>
-  </table>
+  </table-->
 
   <!-- =================================================== -->
   <!-- T A B L E  W I T H  I N T E R F A C E               -->
   <!-- =================================================== -->
 
-  <table name="ifc_table" idMethod="none"
+  <!-- table name="ifc_table" idMethod="none"
   	interface="org.apache.torque.TestInterface"
   	description="this table implements an interface">
     <column
@@ -306,9 +221,13 @@
       type="VARCHAR"
       size="50"
     />
-  </table>
+  </table-->
   
-  <table name="INHERITANCE_TEST" description="Table to test inheritance">
+  <!-- =================================================== -->
+  <!-- T A B L E  W I T H  I N H E R I T A N C E           -->
+  <!-- =================================================== -->
+
+  <!-- table name="INHERITANCE_TEST" description="Table to test inheritance">
     <column
       name="INHERITANCE_TEST"
       required="true"
@@ -358,6 +277,34 @@
       type="VARCHAR"
       size="100"
     />
+  </table-->
+  
+  <!-- =================================================== -->
+  <!-- E X T E R N A L   S C H E M A                       -->
+  <!-- =================================================== -->
+
+  <table name="ext_schema">
+    <column name="ext_schema_id" required="true" primaryKey="true" type="INTEGER"/>
+    <column name="ext_id" type="INTEGER"/>
+    <column name="test" required="true" type="INTEGER"/>
+
+    <index name="index_ext_id">
+      <index-column name="ext_id"/>
+    </index>
+    <foreign-key foreignTable="ext">
+      <reference local="ext_id" foreign="ext_id"/>
+    </foreign-key>
   </table>
 
+  <table name="extext_schema">
+    <column name="extext_schema_id" required="true" primaryKey="true" type="INTEGER"/>
+    <column name="extext_id" type="INTEGER"/>
+    <column name="test" required="true" type="INTEGER"/>
+
+    <foreign-key foreignTable="extext">
+      <reference local="extext_id" foreign="extext_id"/>
+    </foreign-key>
+  </table>
+  
+
 </database>



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