db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1003615 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/map/ torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/ torque-test/src/test/java/org/apache/torque/map/
Date Fri, 01 Oct 2010 19:00:07 GMT
Author: tfischer
Date: Fri Oct  1 19:00:06 2010
New Revision: 1003615

URL: http://svn.apache.org/viewvc?rev=1003615&view=rev
Log:
TORQUE-146: made options available in map builder

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/doBuild.vm
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/map/DatabaseMapTest.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java?rev=1003615&r1=1003614&r2=1003615&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java
Fri Oct  1 19:00:06 2010
@@ -118,6 +118,10 @@ public class ColumnMap implements java.i
     /** Column position in the table (one based). */
     private int position = -1;
 
+    /** Associated of inheritance maps. */
+    private Map optionsMap = Collections
+            .synchronizedMap(new ListOrderedMap());
+
     /**
      * Constructor.
      *
@@ -689,4 +693,37 @@ public class ColumnMap implements java.i
     {
         this.javaType = javaType;
     }
+
+    /**
+     * Returns an unmodifiable map of all options.
+     *
+     * @return A map containing all options, not null.
+     */
+    public Map getOptions()
+    {
+        return Collections.unmodifiableMap(optionsMap);
+    }
+
+    /**
+     * Sets an option.
+     *
+     * @param key the key of the option
+     * @param value the value of the option.
+     */
+    public void setOption(String key, String value)
+    {
+        optionsMap.put(key, value);
+    }
+
+    /**
+     * Returns the value of an option.
+     *
+     * @param key the key of the option.
+     *
+     * @return the value of the option, or null if not set.
+     */
+    public String getOption(String key)
+    {
+        return (String) optionsMap.get(key);
+    }
 }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java?rev=1003615&r1=1003614&r2=1003615&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java
Fri Oct  1 19:00:06 2010
@@ -106,6 +106,10 @@ public class DatabaseMap implements java
     /** Flag indicating that all tables have been loaded via initialize() */
     private boolean isInitialized = false;
 
+    /** Associated of inheritance maps. */
+    private Map optionsMap = Collections
+            .synchronizedMap(new ListOrderedMap());
+
     /**
      * Constructs a new DatabaseMap.
      */
@@ -303,6 +307,40 @@ public class DatabaseMap implements java
         setIdTable(tmap);
     }
 
+
+    /**
+     * Returns an unmodifiable map of all options.
+     *
+     * @return A map containing all options, not null.
+     */
+    public Map getOptions()
+    {
+        return Collections.unmodifiableMap(optionsMap);
+    }
+
+    /**
+     * Sets an option.
+     *
+     * @param key the key of the option
+     * @param value the value of the option.
+     */
+    public void setOption(String key, String value)
+    {
+        optionsMap.put(key, value);
+    }
+
+    /**
+     * Returns the value of an option.
+     *
+     * @param key the key of the option.
+     *
+     * @return the value of the option, or null if not set.
+     */
+    public String getOption(String key)
+    {
+        return (String) optionsMap.get(key);
+    }
+
     /**
      * Add a type of id generator for access by a TableMap.
      *

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java?rev=1003615&r1=1003614&r2=1003615&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java
Fri Oct  1 19:00:06 2010
@@ -90,6 +90,10 @@ public class TableMap implements IDMetho
      */
     private Object pkInfo = null;
 
+    /** Associated of inheritance maps. */
+    private Map optionsMap = Collections
+            .synchronizedMap(new ListOrderedMap());
+
     /**
      * Required by proxy. Not used.
      */
@@ -779,4 +783,37 @@ public class TableMap implements IDMetho
     {
         this.managerClass = managerClass;
     }
+
+    /**
+     * Returns an unmodifiable map of all options.
+     *
+     * @return A map containing all options, not null.
+     */
+    public Map getOptions()
+    {
+        return Collections.unmodifiableMap(optionsMap);
+    }
+
+    /**
+     * Sets an option.
+     *
+     * @param key the key of the option
+     * @param value the value of the option.
+     */
+    public void setOption(String key, String value)
+    {
+        optionsMap.put(key, value);
+    }
+
+    /**
+     * Returns the value of an option.
+     *
+     * @param key the key of the option.
+     *
+     * @return the value of the option, or null if not set.
+     */
+    public String getOption(String key)
+    {
+        return (String) optionsMap.get(key);
+    }
 }

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/doBuild.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/doBuild.vm?rev=1003615&r1=1003614&r2=1003615&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/doBuild.vm
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/doBuild.vm
Fri Oct  1 19:00:06 2010
@@ -28,7 +28,9 @@
 ## as velocity variables.  
 ##
 #set ( $tableElement = $torqueGen.getSourceElement() )
-#set ( $databaseName = $tableElement.getParent().getAttribute("name") )
+#set ( $databaseElement = $tableElement.getParent() )
+#set ( $databaseName = $databaseElement.getAttribute("name") )
+#set ( $databaseOptionElements = $databaseElement.getChildren("option") )
     /**
      * The doBuild() method builds the DatabaseMap
      *
@@ -41,7 +43,13 @@
             return;
         }
         dbMap = Torque.getDatabaseMap("$databaseName");
-
+## TODO the following needs not be executed for every table
+## but it causes no harm
+#foreach($databaseOptionElement in $databaseOptionElements)
+  #set ( $key = $databaseOptionElement.getAttribute("key") )
+  #set ( $value = $databaseOptionElement.getAttribute("value") )
+        dbMap.setOption("$key", "$value");
+#end
         dbMap.addTable("$name");
         TableMap tMap = dbMap.getTable("$name");
         tMap.setJavaName("$javaName");
@@ -82,6 +90,12 @@
         tMap.setUseManager(true);
         tMap.setManagerClass(${managerPackage}.${managerClassName}.class);
 #end
+#set ( $tableOptionElements = $tableElement.getChildren("option") )
+#foreach ( $optionElement in $tableOptionElements )
+  #set ( $key = $optionElement.getAttribute("key") )
+  #set ( $value = $optionElement.getAttribute("value") )
+        tMap.setOption("$key", "$value");
+#end
 
         ColumnMap cMap = null;
 
@@ -139,6 +153,12 @@
             "$referencedColumnElement.getParent().getAttribute("name")",
             "$referencedColumnElement.getAttribute("name")");
   #end
+  #set ( $columnOptionElements = $columnElement.getChildren("option") )
+  #foreach ( $optionElement in $columnOptionElements )
+    #set ( $key = $optionElement.getAttribute("key") )
+    #set ( $value = $optionElement.getAttribute("value") )
+        cMap.setOption("$key", "$value");
+  #end
   #if ($inheritance != "false")
     #set ( $tableUseInheritance = "true" );
         cMap.setUseInheritance(true);

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/map/DatabaseMapTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/map/DatabaseMapTest.java?rev=1003615&r1=1003614&r2=1003615&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/map/DatabaseMapTest.java
(original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/map/DatabaseMapTest.java
Fri Oct  1 19:00:06 2010
@@ -301,6 +301,40 @@ public class DatabaseMapTest extends Bas
     }
 
     /**
+     * Tests whether all options are present
+     */
+    public void testOptions() throws TorqueException
+    {
+        DatabaseMap databaseMap = Torque.getDatabaseMap(DATABASE_NAME);
+        databaseMap.initialize();
+        assertEquals(2, databaseMap.getOptions().size());
+        assertEquals(
+                "databaseOptionValue1",
+                databaseMap.getOption("databaseOptionKey1"));
+        assertEquals(
+                "databaseOptionValue2",
+                databaseMap.getOption("databaseOptionKey2"));
+
+        TableMap tableMap = databaseMap.getTable("OPTION");
+        assertEquals(2, tableMap.getOptions().size());
+        assertEquals(
+                "tableOptionValue1",
+                tableMap.getOption("tableOptionKey1"));
+        assertEquals(
+                "tableOptionValue2",
+                tableMap.getOption("tableOptionKey2"));
+
+        ColumnMap columnMap = tableMap.getColumn("ID");
+        assertEquals(2, columnMap.getOptions().size());
+        assertEquals(
+                "columnOptionValue1",
+                columnMap.getOption("columnOptionKey1"));
+        assertEquals(
+                "columnOptionValue2",
+                columnMap.getOption("columnOptionKey2"));
+    }
+
+    /**
      * Validate that the attribute value matches
      * @param name
      */



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