From torque-dev-return-9971-apmail-db-torque-dev-archive=db.apache.org@db.apache.org Fri Oct 01 19:00:29 2010 Return-Path: Delivered-To: apmail-db-torque-dev-archive@www.apache.org Received: (qmail 81238 invoked from network); 1 Oct 2010 19:00:29 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 1 Oct 2010 19:00:29 -0000 Received: (qmail 51643 invoked by uid 500); 1 Oct 2010 19:00:29 -0000 Delivered-To: apmail-db-torque-dev-archive@db.apache.org Received: (qmail 51617 invoked by uid 500); 1 Oct 2010 19:00:28 -0000 Mailing-List: contact torque-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Apache Torque Developers List" Reply-To: "Apache Torque Developers List" Delivered-To: mailing list torque-dev@db.apache.org Received: (qmail 51608 invoked by uid 500); 1 Oct 2010 19:00:28 -0000 Received: (qmail 51605 invoked by uid 99); 1 Oct 2010 19:00:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Oct 2010 19:00:28 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Oct 2010 19:00:27 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8285E23889BB; Fri, 1 Oct 2010 19:00:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: torque-commits@db.apache.org From: tfischer@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101001190007.8285E23889BB@eris.apache.org> 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