db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r467727 - in /db/torque: generator/trunk/ generator/trunk/src/dtd/ generator/trunk/src/java/org/apache/torque/engine/database/model/ generator/trunk/src/java/org/apache/torque/engine/database/transform/ generator/trunk/xdocs/ site/trunk/xdocs/
Date Wed, 25 Oct 2006 18:46:45 GMT
Author: tfischer
Date: Wed Oct 25 11:46:43 2006
New Revision: 467727

URL: http://svn.apache.org/viewvc?view=rev&rev=467727
Log:
Added support for option tag in database.dtd for usage in custom templates.
Thanks to Greg Monroe for submitting the patch.

Added:
    db/torque/generator/trunk/src/dtd/database_3_2.dtd
Modified:
    db/torque/generator/trunk/pom.xml
    db/torque/generator/trunk/project.xml
    db/torque/generator/trunk/src/dtd/database.dtd
    db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java
    db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Database.java
    db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/ForeignKey.java
    db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Index.java
    db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Table.java
    db/torque/generator/trunk/src/java/org/apache/torque/engine/database/transform/DTDResolver.java
    db/torque/generator/trunk/src/java/org/apache/torque/engine/database/transform/XmlToAppData.java
    db/torque/generator/trunk/xdocs/custom-templates.xml
    db/torque/generator/trunk/xdocs/how-templates-work.xml
    db/torque/site/trunk/xdocs/changes.xml

Modified: db/torque/generator/trunk/pom.xml
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/pom.xml?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/generator/trunk/pom.xml (original)
+++ db/torque/generator/trunk/pom.xml Wed Oct 25 11:46:43 2006
@@ -104,7 +104,7 @@
         <filtering>false</filtering>
         <directory>src/dtd</directory>
         <includes>
-          <include>database.dtd</include>
+          <include>database*.dtd</include>
         </includes>
       </resource>
       <resource>

Modified: db/torque/generator/trunk/project.xml
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/project.xml?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/generator/trunk/project.xml (original)
+++ db/torque/generator/trunk/project.xml Wed Oct 25 11:46:43 2006
@@ -159,7 +159,7 @@
                 <filtering>false</filtering>
                 <directory>${basedir}/src/dtd</directory>
                 <includes>
-                    <include>database.dtd</include>
+                    <include>database*.dtd</include>
                 </includes>
             </resource>
             <resource>

Modified: db/torque/generator/trunk/src/dtd/database.dtd
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/src/dtd/database.dtd?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/generator/trunk/src/dtd/database.dtd (original)
+++ db/torque/generator/trunk/src/dtd/database.dtd Wed Oct 25 11:46:43 2006
@@ -51,7 +51,7 @@
               to lowercase.
 -->
 
-<!ELEMENT database (external-schema*, domain*, table+)>
+<!ELEMENT database (option*, external-schema*, domain*, table+)>
 <!ATTLIST database
   name CDATA #REQUIRED
   defaultIdMethod (idbroker|native|none) "none"
@@ -63,6 +63,12 @@
   heavyIndexing (true|false) "false"
 >
 
+<!ELEMENT option EMPTY>
+<!ATTLIST option
+  key CDATA #REQUIRED
+  value CDATA #REQUIRED
+>
+
 <!ELEMENT external-schema EMPTY>
 <!ATTLIST external-schema
   filename CDATA #REQUIRED
@@ -91,7 +97,7 @@
      note: the interface="true", requires that useManagers=true in the
      properties file.
 -->
-<!ELEMENT table (column+,(foreign-key|index|unique|id-method-parameter)*)>
+<!ELEMENT table (option*,column+,(foreign-key|index|unique|id-method-parameter)*)>
 <!ATTLIST table
   name CDATA #REQUIRED
   javaName CDATA #IMPLIED
@@ -113,7 +119,7 @@
   value CDATA #REQUIRED
 >
 
-<!ELEMENT column (inheritance*)>
+<!ELEMENT column (option*, inheritance*)>
 <!ATTLIST column
   name CDATA #REQUIRED
   javaName CDATA #IMPLIED
@@ -148,7 +154,7 @@
   extends CDATA #IMPLIED
 >
 
-<!ELEMENT foreign-key (reference+)>
+<!ELEMENT foreign-key (option*,reference+)>
 <!ATTLIST foreign-key
   foreignTable CDATA #REQUIRED
   name CDATA #IMPLIED
@@ -162,7 +168,7 @@
   foreign CDATA #REQUIRED
 >
 
-<!ELEMENT index (index-column+)>
+<!ELEMENT index (option*,index-column+)>
 <!ATTLIST index
   name CDATA #IMPLIED
 >
@@ -173,7 +179,7 @@
   size CDATA #IMPLIED
 >
 
-<!ELEMENT unique (unique-column+)>
+<!ELEMENT unique (option*,unique-column+)>
 <!ATTLIST unique
   name CDATA #IMPLIED
 >

Added: db/torque/generator/trunk/src/dtd/database_3_2.dtd
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/src/dtd/database_3_2.dtd?view=auto&rev=467727
==============================================================================
--- db/torque/generator/trunk/src/dtd/database_3_2.dtd (added)
+++ db/torque/generator/trunk/src/dtd/database_3_2.dtd Wed Oct 25 11:46:43 2006
@@ -0,0 +1,184 @@
+<!--
+ Copyright 2001-2005 The Apache Software Foundation.
+
+ Licensed under the Apache License, Version 2.0 (the "License")
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!--
+    Torque XML database schema DTD
+    $Id$
+-->
+
+<!--
+For: database.defaultIdMethod and table.idMethod
+
+Do not use autoincrement or sequence. They are deprecated in favor of
+using native which will use the Connection pool to determine
+which database it is talking to (yes, it knows that) and then use
+whatever native database methodology for insert increments that it can.
+Otherwise, you should use idbroker or none. none is good if you have a
+table that is just a join table. idbroker is good if you want a
+centralized repository for brokering out clumps of id's in a database
+agnostic way.
+-->
+
+<!--
+
+defaultJavaNamingMethod determines how a table or column name,
+from the name attribute in the xml database file, is converted to a
+Java class or method name.
+
+     nochange   - indicates not change is performed.
+     underscore - Underscores and dots are removed, first letter is
+              capitalized, first letter after an underscore
+              is capitalized, first letter after a dot is capitalized,
+              the rest of the letters are converted to lowercase.
+     underscoreOmitSchema - The section of the name before and including
+              the last dot in the name is removed. For the remaining part,
+              underscores are removed, first letter is capitalized,
+              first letter after an underscore is capitalized,
+              the rest of the letters are converted to lowercase.
+     javaname   - same as underscore, but no letters are converted
+              to lowercase.
+-->
+
+<!ELEMENT database (external-schema*, domain*, table+)>
+<!ATTLIST database
+  name CDATA #REQUIRED
+  defaultIdMethod (idbroker|native|none) "none"
+  defaultJavaType (object|primitive) "primitive"
+  package CDATA #IMPLIED
+  baseClass CDATA #IMPLIED
+  basePeer CDATA #IMPLIED
+  defaultJavaNamingMethod (nochange|underscore|underscoreOmitSchema|javaname) "underscore"
+  heavyIndexing (true|false) "false"
+>
+
+<!ELEMENT external-schema EMPTY>
+<!ATTLIST external-schema
+  filename CDATA #REQUIRED
+>
+
+<!ELEMENT domain EMPTY>
+<!ATTLIST domain
+  name CDATA #REQUIRED
+  type
+    (
+          BIT  | TINYINT | SMALLINT    | INTEGER    | BIGINT    | FLOAT
+        | REAL | NUMERIC | DECIMAL     | CHAR       | VARCHAR   | LONGVARCHAR
+        | DATE | TIME    | TIMESTAMP   | BINARY     | VARBINARY | LONGVARBINARY
+        | NULL | OTHER   | JAVA_OBJECT | DISTINCT   | STRUCT    | ARRAY
+        | BLOB | CLOB    | REF         | BOOLEANINT | BOOLEANCHAR
+        | DOUBLE
+    ) "VARCHAR"
+  size CDATA #IMPLIED
+  scale CDATA #IMPLIED
+  default CDATA #IMPLIED
+  description CDATA #IMPLIED
+>
+
+
+<!--
+     note: the interface="true", requires that useManagers=true in the
+     properties file.
+-->
+<!ELEMENT table (column+,(foreign-key|index|unique|id-method-parameter)*)>
+<!ATTLIST table
+  name CDATA #REQUIRED
+  javaName CDATA #IMPLIED
+  idMethod (idbroker|native|none|null) "null"
+  skipSql (true|false) "false"
+  abstract (true|false) "false"
+  baseClass CDATA #IMPLIED
+  basePeer CDATA #IMPLIED
+  alias CDATA #IMPLIED
+  interface CDATA #IMPLIED
+  javaNamingMethod (nochange|underscore|underscoreOmitSchema|javaname) #IMPLIED
+  heavyIndexing (true|false) #IMPLIED
+  description CDATA #IMPLIED
+>
+
+<!ELEMENT id-method-parameter EMPTY>
+<!ATTLIST id-method-parameter
+  name CDATA "default"
+  value CDATA #REQUIRED
+>
+
+<!ELEMENT column (inheritance*)>
+<!ATTLIST column
+  name CDATA #REQUIRED
+  javaName CDATA #IMPLIED
+  primaryKey (true|false) "false"
+  required (true|false) "false"
+  protected (true|false) "false"
+  domain CDATA #IMPLIED
+  type
+    (
+          BIT  | TINYINT | SMALLINT    | INTEGER    | BIGINT    | FLOAT
+        | REAL | NUMERIC | DECIMAL     | CHAR       | VARCHAR   | LONGVARCHAR
+        | DATE | TIME    | TIMESTAMP   | BINARY     | VARBINARY | LONGVARBINARY
+        | NULL | OTHER   | JAVA_OBJECT | DISTINCT   | STRUCT    | ARRAY
+        | BLOB | CLOB    | REF         | BOOLEANINT | BOOLEANCHAR
+        | DOUBLE
+    ) #IMPLIED
+  javaType (object|primitive) #IMPLIED
+  size CDATA #IMPLIED
+  scale CDATA #IMPLIED
+  default CDATA #IMPLIED
+  autoIncrement (true|false) #IMPLIED
+  inheritance (single|false) "false"
+  inputValidator CDATA #IMPLIED
+  javaNamingMethod (nochange|underscore|javaname) #IMPLIED
+  description CDATA #IMPLIED
+>
+
+<!ELEMENT inheritance EMPTY>
+<!ATTLIST inheritance
+  key CDATA #REQUIRED
+  class CDATA #REQUIRED
+  extends CDATA #IMPLIED
+>
+
+<!ELEMENT foreign-key (reference+)>
+<!ATTLIST foreign-key
+  foreignTable CDATA #REQUIRED
+  name CDATA #IMPLIED
+  onUpdate (cascade|setnull|restrict|none) "none"
+  onDelete (cascade|setnull|restrict|none) "none"
+>
+
+<!ELEMENT reference EMPTY>
+<!ATTLIST reference
+  local CDATA #REQUIRED
+  foreign CDATA #REQUIRED
+>
+
+<!ELEMENT index (index-column+)>
+<!ATTLIST index
+  name CDATA #IMPLIED
+>
+
+<!ELEMENT index-column EMPTY>
+<!ATTLIST index-column
+  name CDATA #REQUIRED
+  size CDATA #IMPLIED
+>
+
+<!ELEMENT unique (unique-column+)>
+<!ATTLIST unique
+  name CDATA #IMPLIED
+>
+
+<!ELEMENT unique-column EMPTY>
+<!ATTLIST unique-column
+  name CDATA #REQUIRED
+>

Modified: db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java
(original)
+++ db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java
Wed Oct 25 11:46:43 2006
@@ -17,9 +17,12 @@
  */
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.commons.collections.map.ListOrderedMap;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -37,6 +40,7 @@
  * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  * @author <a href="mailto:byron_foster@byron_foster@yahoo.com>Byron Foster</a>
  * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
+ * @author <a href="mailto:monroe@dukece.com>Greg Monroe</a>
  * @version $Id$
  */
 public class Column
@@ -73,6 +77,7 @@
 
     /** class name to do input validation on this column */
     private String inputValidator = null;
+    private Map options;
 
     /**
      * Creates a new instance with a <code>null</code> name.
@@ -90,6 +95,7 @@
     public Column(String name)
     {
         this.name = name;
+        options = Collections.synchronizedMap(new ListOrderedMap());
     }
 
     /**
@@ -744,30 +750,30 @@
      * If size attribute is an integer number, it will be returned.
      * If size attribute is of the format "Precision,Scale", then Precision
      * will be returned.
-     * If size is null or the size value is not an valid integer,
+     * If size is null or the size value is not an valid integer, 
      * null is returned.
      * <p>
      * Note: Unparseable values will be logged as a warning.
-     *
-     * @return The precision portion of the size attribute.
+     * 
+     * @return The precision portion of the size attribute.  
      */
     public String getPrecision()
     {
         String size = getSize();
-        if (size == null)
+        if ( size == null )
         {
             return size;
         }
         int cLoc = size.indexOf(',');
-        if (cLoc > 0)
+        if ( cLoc > 0 )
         {
             size = size.substring(0, cLoc);
         }
-        try
+        try 
         {
             Integer.parseInt(size);
-        }
-        catch (NumberFormatException e)
+        } 
+        catch ( NumberFormatException e  ) 
         {
             log.warn("getPrecision(): Size attribute found ("
                     + getSize()
@@ -778,43 +784,43 @@
     }
 
     /**
-     * Try to determine the scale of the field from the scale and size
+     * Try to determine the scale of the field from the scale and size 
      * attribute.
      * If scale attribute is an integer number, it will be returned.
      * If size attribute is of the format "Precision,Scale", then Scale
      * will be returned.
-     * If scale and size attributes are null or the scale value found
+     * If scale and size attributes are null or the scale value found 
      * is not an valid integer, a null value is returned.
      * <p>
      * Note: Unparseable values will be logged as a warning.
-     *
-     * @return The precision portion of the size attribute.
+     * 
+     * @return The precision portion of the size attribute.  
      */
     public String getScale()
     {
         String scale = domain.getScale();
         // Check for scale on size attribute if no scale attribute
-        if (scale == null)
+        if ( scale == null )
         {
             scale = getSize();
-            if (scale == null)   // No scale or size attribute set.
+            if ( scale == null )   // No scale or size attribute set.
             {
                 return scale;
             }
             int cLoc = scale.indexOf(',');
-            if (cLoc < 0)        // Size did not have "P,S" format
+            if ( cLoc < 0 )        // Size did not have "P,S" format
             {
                 return null;
             }
-            scale = scale.substring(cLoc + 1);
+            scale = scale.substring(cLoc + 1 );
         }
 
         // Validate that scale string found is integer.
-        try
+        try 
         {
             Integer.parseInt(scale);
         }
-        catch (NumberFormatException e)
+        catch ( NumberFormatException e  ) 
         {
             log.warn("getScale(): Scale (or size=\"p,s\") attribute found ("
                     + scale
@@ -1173,11 +1179,49 @@
 
     /**
      * Get the value of the inheritance attribute defined in the schema XML.
-     *
+     * 
      * @return Returns the inheritanceType.
      */
     public String getInheritanceType()
     {
         return inheritanceType;
+    }
+    
+    /**
+     * Add an XML Specified option key/value pair to this element's option set.
+     * 
+     * @param key the key of the option.
+     * @param value the value of the option.
+     */
+    public void addOption(String key, String value)
+    {
+        options.put( key, value );
+    }
+    
+    /**
+     * Get the value that was associated with this key in an XML option 
+     * element.
+     * 
+     * @param key the key of the option.
+     * @return The value for the key or a null.
+     */
+    public String getOption(String key)
+    {
+        return (String) options.get(key);
+    }
+    
+    /**
+     * Gets the full ordered hashtable array of items specified by XML option
+     * statements under this element.<p>
+     * 
+     * Note, this is not thread save but since it's only used for 
+     * generation which is single threaded, there should be minimum 
+     * danger using this in Velocity.
+     * 
+     * @return An Map of all options. Will not be null but may be empty.
+     */
+    public Map getOptions() 
+    {
+        return options;
     }
 }

Modified: db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Database.java
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Database.java?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Database.java
(original)
+++ db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Database.java
Wed Oct 25 11:46:43 2006
@@ -17,12 +17,14 @@
  */
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.collections.map.ListOrderedMap;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.torque.engine.EngineException;
@@ -40,6 +42,7 @@
  * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
  * @author <a href="mailto:dlr@collab.net>Daniel Rall</a>
  * @author <a href="mailto:byron_foster@byron_foster@yahoo.com>Byron Foster</a>
+ * @author <a href="mailto:monroe@dukece.com>Greg Monroe</a>
  * @version $Id$
  */
 public class Database
@@ -63,6 +66,8 @@
     private boolean heavyIndexing;
     /** the name of the definition file */
     private String fileName;
+    private Map options = Collections.synchronizedMap(new ListOrderedMap());
+
 
     /**
      * Creates a new instance for the specified database type.
@@ -560,5 +565,43 @@
 
         result.append("</database>");
         return result.toString();
+    }
+
+    /**
+     * Add an XML Specified option key/value pair to this element's option set.
+     * 
+     * @param key the key of the option.
+     * @param value the value of the option.
+     */
+    public void addOption(String key, String value)
+    {
+        options.put( key, value );
+    }
+    
+    /**
+     * Get the value that was associated with this key in an XML option 
+     * element.
+     * 
+     * @param key the key of the option.
+     * @return The value for the key or a null.
+     */
+    public String getOption( String key )
+    {
+        return (String) options.get(key);
+    }
+
+    /**
+     * Gets the full ordered hashtable array of items specified by XML option
+     * statements under this element.<p>
+     * 
+     * Note, this is not thread save but since it's only used for 
+     * generation which is single threaded, there should be minimum 
+     * danger using this in Velocity.
+     * 
+     * @return An Map of all options. Will not be null but may be empty.
+     */
+    public Map getOptions()
+    {
+        return options;
     }
 }

Modified: db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/ForeignKey.java
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/ForeignKey.java?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/ForeignKey.java
(original)
+++ db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/ForeignKey.java
Wed Oct 25 11:46:43 2006
@@ -17,8 +17,12 @@
  */
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.collections.map.ListOrderedMap;
 import org.xml.sax.Attributes;
 
 /**
@@ -26,6 +30,7 @@
  *
  * @author <a href="mailto:fedor.karpelevitch@home.com">Fedor</a>
  * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
+ * @author <a href="mailto:monroe@dukece.com>Greg Monroe</a>
  * @version $Id$
  */
 public class ForeignKey
@@ -37,6 +42,8 @@
     private Table parentTable;
     private List localColumns = new ArrayList(3);
     private List foreignColumns = new ArrayList(3);
+    private Map options = Collections.synchronizedMap(new ListOrderedMap());
+
 
     // the uppercase equivalent of the onDelete/onUpdate values in the dtd
     private static final String NONE    = "NONE";
@@ -331,4 +338,43 @@
         result.append("    </foreign-key>\n");
         return result.toString();
     }
+    
+    /**
+     * Add an XML Specified option key/value pair to this element's option set.
+     * 
+     * @param key the key of the option.
+     * @param value the value of the option.
+     */
+    public void addOption(String key, String value)
+    {
+        options.put( key, value );
+    }
+    
+    /**
+     * Get the value that was associated with this key in an XML option 
+     * element.
+     * 
+     * @param key the key of the option.
+     * @return The value for the key or a null.
+     */
+    public String getOption( String key )
+    {
+        return (String) options.get(key);
+    }
+
+    /**
+     * Gets the full ordered hashtable array of items specified by XML option
+     * statements under this element.<p>
+     * 
+     * Note, this is not thread save but since it's only used for 
+     * generation which is single threaded, there should be minimum 
+     * danger using this in Velocity.
+     * 
+     * @return An Map of all options. Will not be null but may be empty.
+     */
+    public Map getOptions()
+    {
+        return options;
+    }
+
 }

Modified: db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Index.java
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Index.java?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Index.java
(original)
+++ db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Index.java
Wed Oct 25 11:46:43 2006
@@ -17,9 +17,12 @@
  */
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.commons.collections.map.ListOrderedMap;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -32,6 +35,7 @@
  *
  * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  * @author <a href="mailto:dlr@finemaltcoding.com>Daniel Rall</a>
+ * @author <a href="mailto:monroe@dukece.com>Greg Monroe</a>
  * @version $Id$
  */
 public class Index
@@ -44,6 +48,9 @@
     private Table parentTable;
     /** columns */
     private List indexColumns;
+    /** The XML Options specified for this index */
+    private Map options;
+
 
     /**
      * Creates a new instance with default characteristics (no name or
@@ -52,6 +59,7 @@
     public Index()
     {
         indexColumns = new ArrayList(3);
+        options = Collections.synchronizedMap(new ListOrderedMap());
     }
 
     /**
@@ -230,4 +238,43 @@
         result.append(" </index>\n");
         return result.toString();
     }
+    
+    /**
+     * Add an XML Specified option key/value pair to this element's option set.
+     * 
+     * @param key the key of the option.
+     * @param value the value of the option.
+     */
+    public void addOption(String key, String value)
+    {
+        options.put( key, value );
+    }
+    
+    /**
+     * Get the value that was associated with this key in an XML option 
+     * element.
+     * 
+     * @param key the key of the option.
+     * @return The value for the key or a null.
+     */
+    public String getOption( String key )
+    {
+        return (String) options.get(key);
+    }
+
+    /**
+     * Gets the full ordered hashtable array of items specified by XML option
+     * statements under this element.<p>
+     * 
+     * Note, this is not thread save but since it's only used for 
+     * generation which is single threaded, there should be minimum 
+     * danger using this in Velocity.
+     * 
+     * @return An Map of all options. Will not be null but may be empty.
+     */
+    public Map getOptions()
+    {
+        return options;
+    }
+
 }

Modified: db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Table.java
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Table.java?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Table.java
(original)
+++ db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Table.java
Wed Oct 25 11:46:43 2006
@@ -17,10 +17,12 @@
  */
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
-
+import java.util.Map;
+import org.apache.commons.collections.map.ListOrderedMap;
 import org.apache.commons.lang.StringUtils;
 
 import org.apache.commons.logging.Log;
@@ -39,6 +41,7 @@
  * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
  * @author <a href="mailto:dlr@collab.net>Daniel Rall</a>
  * @author <a href="mailto:byron_foster@byron_foster@yahoo.com>Byron Foster</a>
+ * @author <a href="mailto:monroe@dukece.com>Greg Monroe</a>
  * @version $Id$
  */
 public class Table implements IDMethod
@@ -74,7 +77,7 @@
     private boolean needsTransactionInPostgres;
     private boolean heavyIndexing;
     private boolean forReferenceOnly;
-
+    private Map options;
 
     /**
      * Default Constructor
@@ -98,6 +101,7 @@
         unices = new ArrayList(5);
         columnsByName = new Hashtable();
         columnsByJavaName = new Hashtable();
+        options = Collections.synchronizedMap(new ListOrderedMap());
     }
 
     /**
@@ -262,7 +266,7 @@
      * @return unique name for constraint
      * @throws EngineException
      */
-    private String acquireConstraintName(String nameType, int nbr)
+    private final String acquireConstraintName(String nameType, int nbr)
             throws EngineException
     {
         List inputs = new ArrayList(4);
@@ -1145,10 +1149,48 @@
     public void setCorrectGetters(Boolean value)
     {
         boolean correctGetters = value != null && value.booleanValue();
-        for (Iterator it = columnList.iterator(); it.hasNext();)
+        for (Iterator it = columnList.iterator(); it.hasNext(); )
         {
             Column col = (Column) it.next();
             col.setCorrectGetters(correctGetters);
         }
+    }
+    
+    /**
+     * Add an XML Specified option key/value pair to this element's option set.
+     * 
+     * @param key the key of the option.
+     * @param value the value of the option.
+     */
+    public void addOption(String key, String value)
+    {
+        options.put( key, value );
+    }
+    
+    /**
+     * Get the value that was associated with this key in an XML option 
+     * element.
+     * 
+     * @param key the key of the option.
+     * @return The value for the key or a null.
+     */
+    public String getOption( String key )
+    {
+        return (String) options.get(key);
+    }
+    
+    /**
+     * Gets the full ordered hashtable array of items specified by XML option
+     * statements under this element.<p>
+     * 
+     * Note, this is not thread save but since it's only used for 
+     * generation which is single threaded, there should be minimum 
+     * danger using this in Velocity.
+     * 
+     * @return An Map of all options. Will not be null but may be empty.
+     */
+    public Map getOptions()
+    {
+        return options;
     }
 }

Modified: db/torque/generator/trunk/src/java/org/apache/torque/engine/database/transform/DTDResolver.java
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/src/java/org/apache/torque/engine/database/transform/DTDResolver.java?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/generator/trunk/src/java/org/apache/torque/engine/database/transform/DTDResolver.java
(original)
+++ db/torque/generator/trunk/src/java/org/apache/torque/engine/database/transform/DTDResolver.java
Wed Oct 25 11:46:43 2006
@@ -37,10 +37,11 @@
 {
     /** Where the DTD is located on the web. */
     public static final String WEB_SITE_DTD
-            = "http://db.apache.org/torque/dtd/database_3_2.dtd";
+            = "http://db.apache.org/torque/dtd/database_3_2_1.dtd";
 
-    /** InputSource for <code>database.dtd</code>. */
-    private InputSource databaseDTD = null;
+    /** Where the 3.2 DTD is located on the web. */
+    public static final String WEB_SITE_DTD_3_2
+            = "http://db.apache.org/torque/dtd/database_3_2.dtd";
 
     /** Logging class from commons.logging */
     private static Log log = LogFactory.getLog(DTDResolver.class);
@@ -51,27 +52,6 @@
     public DTDResolver()
             throws SAXException
     {
-        try
-        {
-            InputStream dtdStream
-                    = getClass().getResourceAsStream("database.dtd");
-
-            // getResource was buggy on many systems including Linux,
-            // OSX, and some versions of windows in jdk1.3.
-            // getResourceAsStream works on linux, maybe others?
-            if (dtdStream != null)
-            {
-                databaseDTD = new InputSource(dtdStream);
-            }
-            else
-            {
-                log.warn("Could not locate database.dtd");
-            }
-        }
-        catch (Exception ex)
-        {
-            throw new SAXException("Could not get stream for database.dtd", ex);
-        }
     }
 
     /**
@@ -87,20 +67,61 @@
      * <code>database.dtd</code> file in the generator jar, or null.
      */
     public InputSource resolveEntity(String publicId, String systemId)
-            throws IOException
+            throws IOException, SAXException
     {
-        if (databaseDTD != null && WEB_SITE_DTD.equals(systemId))
+        if (WEB_SITE_DTD.equals(systemId))
         {
-            String pkg = getClass().getName().substring(0,
-                    getClass().getName().lastIndexOf('.'));
-            log.info("Resolver: used database.dtd from '"
-                     + pkg + "' package");
-            return databaseDTD;
+            return readFromClasspath("database.dtd");
+        }
+        else if (WEB_SITE_DTD_3_2.equals(systemId))
+        {
+            return readFromClasspath("database_3_2.dtd");
         }
         else
         {
             log.info("Resolver: used default behaviour");
             return null;
+        }
+    }
+
+    /**
+     * reads the resource with the given name from the classpath.
+     * 
+     * @param resourceName the name of the resource to read
+     * @return an Inputsource witht the content of the resource.
+     * 
+     * @throws SAXException if the resource cannot be read.
+     */
+    private InputSource readFromClasspath(String resourceName)
+        throws SAXException
+    {
+        try
+        {
+            InputStream dtdStream
+                    = getClass().getResourceAsStream(resourceName);
+
+            // getResource was buggy on many systems including Linux,
+            // OSX, and some versions of windows in jdk1.3.
+            // getResourceAsStream works on linux, maybe others?
+            if (dtdStream != null)
+            {
+                String pkg = getClass().getName().substring(0,
+                        getClass().getName().lastIndexOf('.'));
+                log.info("Resolver: used " + resourceName + " from '"
+                         + pkg + "' package");
+                return new InputSource(dtdStream);
+            }
+            else
+            {
+                log.warn("Could not locate database.dtd");
+                return null;
+            }
+        }
+        catch (Exception ex)
+        {
+            throw new SAXException(
+                    "Could not get stream for " + resourceName, 
+                    ex);
         }
     }
 }

Modified: db/torque/generator/trunk/src/java/org/apache/torque/engine/database/transform/XmlToAppData.java
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/src/java/org/apache/torque/engine/database/transform/XmlToAppData.java?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/generator/trunk/src/java/org/apache/torque/engine/database/transform/XmlToAppData.java
(original)
+++ db/torque/generator/trunk/src/java/org/apache/torque/engine/database/transform/XmlToAppData.java
Wed Oct 25 11:46:43 2006
@@ -51,6 +51,7 @@
  * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
  * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
  * @author <a href="mailto:fischer@seitenbau.de">Thomas Fischer</a>
+ * @author <a href="mailto:monroe@dukece.com>Greg Monroe</a>
  * @version $Id$
  */
 public class XmlToAppData extends DefaultHandler
@@ -315,6 +316,10 @@
             {
                 currTable.addIdMethodParameter(attributes);
             }
+            else if ( rawName.equals("option"))
+            {
+                setOption(attributes);
+            }
         }
         catch (Exception e)
         {
@@ -332,11 +337,74 @@
      *         qualified names are not available.
      */
     public void endElement(String uri, String localName, String rawName)
+        throws SAXException
     {
         if (log.isDebugEnabled())
         {
             log.debug("endElement(" + uri + ", " + localName + ", "
                     + rawName + ") called");
+        }
+        try
+        {
+            // Reset working objects to null to allow option to know
+            // which element it is associated with.
+            if (rawName.equals("table"))
+            {
+                currTable = null;
+            }
+            else if (rawName.equals("column"))
+            {
+                currColumn = null;
+            }
+            else if (rawName.equals("foreign-key"))
+            {
+                currFK = null;
+            }
+            else if (rawName.equals("index"))
+            {
+                currIndex = null;
+            }
+            else if (rawName.equals("unique"))
+            {
+                currUnique = null;
+            }
+        }
+        catch (Exception e)
+        {
+            throw new SAXException(e);
+        }
+    }
+
+    public void setOption( Attributes attributes ) 
+    {
+        // Look thru supported model elements in reverse order to 
+        // find one that this option statement applies to.
+        
+        String key = attributes.getValue("key");
+        String value = attributes.getValue("value");
+        if ( currUnique != null )
+        { 
+            currUnique.addOption(key, value);
+        }
+        else if ( currIndex != null )
+        {
+            currIndex.addOption(key, value);
+        }
+        else if ( currFK != null )
+        {
+            currFK.addOption(key, value);
+        }
+        else if ( currColumn != null )
+        {
+            currColumn.addOption(key, value);
+        }
+        else if ( currTable != null )
+        {
+            currTable.addOption(key, value);
+        }
+        else
+        {                            // Must be a db level option.
+            database.addOption(key, value);
         }
     }
 

Modified: db/torque/generator/trunk/xdocs/custom-templates.xml
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/xdocs/custom-templates.xml?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/generator/trunk/xdocs/custom-templates.xml (original)
+++ db/torque/generator/trunk/xdocs/custom-templates.xml Wed Oct 25 11:46:43 2006
@@ -93,8 +93,9 @@
     that is packaged as an add-on.  
     </p>  
     <p>
-    This page shows how to set up and use add-ons, and how to 
-    create own custom templates. 
+    This document shows how to set up your Torque project to use overrides,
+    general information on how to install packaged add-ons, and how to get
+    started in creating custom templates.
     <!-- 
     Provide guidelines on how to package a general add-on for submission to
     the Torque site. -->
@@ -172,7 +173,7 @@
     <p>
     If you want to modify the generated sql files or java classes, 
     first look at the overview 
-    <a href="how-templates-work.html">"how templates work"</a> if you are not
+    <a href="how-templates-work.html">"How Templates Work"</a> if you are not
     familiar with the way Torque uses velocity templates.
     After doing that, proceed as follows:
     </p>

Modified: db/torque/generator/trunk/xdocs/how-templates-work.xml
URL: http://svn.apache.org/viewvc/db/torque/generator/trunk/xdocs/how-templates-work.xml?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/generator/trunk/xdocs/how-templates-work.xml (original)
+++ db/torque/generator/trunk/xdocs/how-templates-work.xml Wed Oct 25 11:46:43 2006
@@ -22,46 +22,121 @@
  </properties>
 
  <body>
+ 
+  <section name="How Templates Work">
+    <p>
+    <b>Table of Contents</b>
+    </p>
+    <p>
+      <ol>
+        <li>
+          <a href="#Introduction">Introduction</a>
+        </li>
+        <li>
+          <a href="#Process Overview">
+            Process Overview
+          </a>
+        </li>
+        <li>
+          <a href="#Template Files">
+            Template Files
+          </a>
+        </li>
+        <li>
+          <a href="#Template Variables">
+            Template Variables
+          </a>
+        </li>
+        <li>
+          <a href="#The XML Custom Option Element">
+            The XML Custom Option Element
+          </a>
+        </li>
+      </ol>
+    </p>
+  </section>
   
-  <section name="How Templates work">
+  <section name="Introduction">
     <p>
       This section explains how the generator works internally.  If you
-      are happy with the generator as it is, you need not read this section.
-    </p>
+      are happy with the generator as it is, you need not read this section.
+      It is not intended to be a tutorial, but rather a overview framework 
+      that points people interested in enhancing or creating custom 
+      templates to the resources needed to work with Torque templates.
+    </p>
+    <p>
+      Once you understand the Template internals, see the 
+      <a href="custom-templates.html">Custom Templates</a> document for
+      information on how to use it. 
+    </p>
+    
   </section>
-  <section name="Location of Templates">
+  
+  <section name="Process Overview">
+    <p>
+      The Torque Generator is designed to do many different tasks. (see
+      the <a href="tasks-reference.html">Tasks Reference</a> documentation).
 
+      These tasks generate text based output like: Java code; SQL 
+      scripts; etc.  Many of these outputs specific to the database type
+      specified in the generation setting.
+    </p>
     <p>
-      Before starting to do any modifications, you should understand the main 
-      "driver" for the Torque generator tasks is the 
-      <a href="http://jakarta.apache.org/velocity">Velocity</a> Java-based 
-      template engine.  All the tasks make use of Velocity template files. You
-      should become familiar with the Velocity template syntax by reviewing the 
+      The Generator tasks are based on a Java based template engine
+      called <a href="http://jakarta.apache.org/velocity">Velocity</a> (in
+      particular, the Texen component).  The Velocity engine uses 
+      a set of task specific template files written in the 
+      Velocity Template Language (VTL), the XML schema info, and 
+      project build properties to produce the required output.
+    </p>
+    <p>
+      To understand how the Torque template files work, you should become 
+      familiar with the VTL syntax by reviewing the 
       <a href="http://jakarta.apache.org/velocity/docs/user-guide.html">Velocity
-        user guide</a>.
+      user guide</a>.
     </p>
+  </section>
+  
+  <section name="Template Files">
     <p>
-      The Torque template files are packaged in the 
-      torque-gen-templates&lt;version&gt;.jar in the lib directory of the binary
-      distribution.  This contains serveral different directories with templates
-      under them.  Each of these directories is related to a Torque Task.
-    </p>
-    <p>
-      To learn which directories apply to which generator task, you need to
-      identify the Control.vm template associated with that task.
-      The Control.vm is the main Velocity controller that calls all of the
-      task related template files as required.  Matching Control.vm file to 
-      a task can be done in various ways.  You can look at the settings of the
-      torque.template.* properties in the default.properties file 
-      (in the root of the binary distribution).  Alternatively, you can look
-      at the Torque task  definitions in the build-torque.xml Ant build file.
+      The Torque template files are plain text VTL files with the extention of 
+      &quot;.vm&quot;.  These files are packaged in the 
+      torque-gen-templates&lt;version&gt;.jar in the lib directory of the 
+      binary distribution. This jar file can be unpacked to access this files.
+      Or alternatively, you can find them under the torque/templates/src 
+      directory in the source distribution or SVN repository.
+    </p>
+    <p>
+      The template files are organized under a main directory called
+      templates which has five or so different directory branches under it. 
+      Each of these branches is roughly related to a Torque Task.
+      To learn which directories and templates apply to which Generator task, 
+      you need to identify the Control.vm template associated 
+      with that task.  The Control.vm files are the main entry points for
+      all tasks.
+    </p>
+    <p>
+      The easiest way to find a task's Control.vm file is to use the 
+      default.properties file (located in the root directory of the binary 
+      distribution). Search thru this file for properties 
+      that start with "torque.templates."  The ending part of the property
+      key is generally the task name and the value is the associated Control.vm
+      file.  E.g. the property, "torque.template.sql = sql/base/Control.vm", 
+      means the sql task Control file is the templates/sql/base/Control.vm file
+      in the template jar.      
+    </p>
+    <p>
+      These Control.vm files can be examined to understand the overall flow
+      of a task's process and to find the main template files that will 
+      be parsed to produce various parts of the output. Note that in some
+      cases, the parsed template files may call other templates.
     </p>
   </section>
   
-  <section name="Template variables">
+  <section name="Template Variables">
     <p>
-      Once you start looking at the code in the templates, you'll wonder where
-      all the Velocity variables are getting set.  Well, there are two places
-      these come from.
+      Once you start looking at the VTL code in the templates, you'll wonder 
+      where all the Velocity variables are getting set.  Well, there are two 
+      places these come from.
     </p>
     <p>
       First, all the torque.* build properties defined in the
@@ -77,6 +152,36 @@
       In Velocity, any object property (e.g. getProp), can be referred to by 
       $objectVar.prop.  In addition, any methods in this object can also be 
       called by referring to them as $objectVar.getSomething( parm, parm ).  
+    </p>
+  </section>
+  
+  <section name="The XML Custom Option Element">
+    <p>
+      With the release of Version 3.2.1, the XML DTD supports an
+      &lt;option key=&quot;key&quot; value=&quot;value&quot;&gt;
element 
+      intended for use by custom templates. Zero or more of these elements 
+      can be nested (as the first item) inside the dataset, table, column, 
+      foreign-key, index, and unique schema elements.  For example:
+    </p>
+    <p>
+      <ul>
+        &lt;table ....&gt;
+           &lt;option key=&quot;mysql-table-type&quot; value=&quot;INNOB&quot;/&gt;
+           ....
+        &lt;/table&gt;
+      </ul>
+    </p>
+    <p>
+      These key/value attributes will then populate the options map in the 
+      associated database model class.  Custom templates can access these
+      values with code like:
+    </p>
+    <p>
+      <ul>
+        #if ( {table.getOption(&quot;mysql-table-type&quot;)})
+          ${table.getOption(&quot;mysql-table-type&quot;)}
+        #end
+      </ul>
     </p>
   </section> 
  </body>

Modified: db/torque/site/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/db/torque/site/trunk/xdocs/changes.xml?view=diff&rev=467727&r1=467726&r2=467727
==============================================================================
--- db/torque/site/trunk/xdocs/changes.xml (original)
+++ db/torque/site/trunk/xdocs/changes.xml Wed Oct 25 11:46:43 2006
@@ -29,6 +29,10 @@
 
   <release version="3.2.1-dev" date="in SVN">
   
+    <action type="add" dev="tfischer" issue="TORQUE-27" due-to="Greg Monroe">
+      Added support for option tags for most elements in the database.xml
+      for usage with custom templates. 
+    </action>
     <action type="fix" dev="tfischer" issue="TORQUE-10">
       Limit and Offset work now correctly if applied to joined
       tables which contain the same column name in oracle.



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