db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1206426 [5/7] - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/ torque-runtime/src/main/java/org/apache/torque/avalon/ torque-runtime/src/main/java/org/apache/torque/dsfactory/ torque-runtime/src/main/java/org/...
Date Sat, 26 Nov 2011 10:59:52 GMT
Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/CriteriaTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/CriteriaTest.java?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/CriteriaTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/util/CriteriaTest.java Sat Nov 26 10:59:15 2011
@@ -27,11 +27,13 @@ import java.util.Map;
 
 import org.apache.commons.lang.SerializationUtils;
 import org.apache.torque.BaseTestCase;
+import org.apache.torque.ColumnImpl;
 import org.apache.torque.Torque;
 import org.apache.torque.TorqueException;
 import org.apache.torque.map.ColumnMap;
 import org.apache.torque.map.DatabaseMap;
 import org.apache.torque.map.TableMap;
+import org.apache.torque.sql.OrderBy;
 import org.apache.torque.sql.Query;
 import org.apache.torque.sql.SqlBuilder;
 import org.apache.torque.util.Criteria.Criterion;
@@ -52,48 +54,40 @@ public class CriteriaTest extends BaseTe
     private Criteria c;
 
     /**
-     * Creates a new instance.
-     *
-     * @param name the name of the test to run
-     */
-    public CriteriaTest(String name)
-    {
-        super(name);
-    }
-
-    /**
      * Initializes the criteria.
      */
-    public void setUp() throws TorqueException
+    public void setUp() throws Exception
     {
         super.setUp();
         c = new Criteria();
         DatabaseMap databaseMap = Torque.getDatabaseMap("postgresql");
-        TableMap tableMap = new TableMap("TABLE", 4, databaseMap);
-        databaseMap.addTable(tableMap);
-        {
-            ColumnMap columnMap1 = new ColumnMap("COLUMN1", tableMap);
-            columnMap1.setType(new String(""));
-            columnMap1.setJavaType("String");
-            tableMap.addColumn(columnMap1);
-        }
-        {
-            ColumnMap columnMap2 = new ColumnMap("COLUMN2", tableMap);
-            columnMap2.setType(new String(""));
-            columnMap2.setJavaType("String");
-            tableMap.addColumn(columnMap2);
-        }
-        {
-            ColumnMap columnMap3 = new ColumnMap("COLUMN3", tableMap);
-            columnMap3.setType(new String(""));
-            columnMap3.setJavaType("String");
-            tableMap.addColumn(columnMap3);
-        }
+        if (!databaseMap.containsTable("TABLE"))
         {
-            ColumnMap columnMap4 = new ColumnMap("COLUMN4", tableMap);
-            columnMap4.setType(new Integer(0));
-            columnMap4.setJavaType("Integer");
-            tableMap.addColumn(columnMap4);
+            TableMap tableMap = databaseMap.addTable("TABLE");
+            {
+                ColumnMap columnMap1 = new ColumnMap("COLUMN1", tableMap);
+                columnMap1.setType(new String(""));
+                columnMap1.setJavaType("String");
+                tableMap.addColumn(columnMap1);
+            }
+            {
+                ColumnMap columnMap2 = new ColumnMap("COLUMN2", tableMap);
+                columnMap2.setType(new String(""));
+                columnMap2.setJavaType("String");
+                tableMap.addColumn(columnMap2);
+            }
+            {
+                ColumnMap columnMap3 = new ColumnMap("COLUMN3", tableMap);
+                columnMap3.setType(new String(""));
+                columnMap3.setJavaType("String");
+                tableMap.addColumn(columnMap3);
+            }
+            {
+                ColumnMap columnMap4 = new ColumnMap("COLUMN4", tableMap);
+                columnMap4.setType(new Integer(0));
+                columnMap4.setJavaType("Integer");
+                tableMap.addColumn(columnMap4);
+            }
         }
     }
 
@@ -107,7 +101,7 @@ public class CriteriaTest extends BaseTe
         final String value = "myValue";
 
         // Add the string
-        c.add(table, column, (Object) value);
+        c.add(table, column, value);
 
         // Verify that the key exists
         assertTrue(c.containsKey(table, column));
@@ -138,17 +132,17 @@ public class CriteriaTest extends BaseTe
         final String value5 = "myValue5";
 
         Criteria.Criterion crit2 =
-            c.getNewCriterion(table2, column2, (Object) value2, Criteria.EQUAL);
+            c.getNewCriterion(table2, column2, value2, Criteria.EQUAL);
         Criteria.Criterion crit3 =
-            c.getNewCriterion(table3, column3, (Object) value3, Criteria.EQUAL);
+            c.getNewCriterion(table3, column3, value3, Criteria.EQUAL);
         Criteria.Criterion crit4 =
-            c.getNewCriterion(table4, column4, (Object) value4, Criteria.EQUAL);
+            c.getNewCriterion(table4, column4, value4, Criteria.EQUAL);
         Criteria.Criterion crit5 =
-            c.getNewCriterion(table5, column5, (Object) value5, Criteria.EQUAL);
+            c.getNewCriterion(table5, column5, value5, Criteria.EQUAL);
 
         crit2.and(crit3).or(crit4.and(crit5));
         c.add(crit2);
-        c.addSelectColumn("*");
+        c.addSelectColumn(new ColumnImpl(null, "myTable2", null, "*"));
 
         String expect =
             "SELECT * FROM myTable2, myTable3, myTable4, myTable5 WHERE "
@@ -170,27 +164,27 @@ public class CriteriaTest extends BaseTe
         Criteria.Criterion crit6 = c.getNewCriterion(
                 table2,
                 column2,
-                (Object) value2,
+                value2,
                 Criteria.LESS_THAN);
         Criteria.Criterion crit7 = c.getNewCriterion(
                 table3,
                 column3,
-                (Object) value3,
+                value3,
                 Criteria.LESS_EQUAL);
         Criteria.Criterion crit8 = c.getNewCriterion(
                 table4,
                 column4,
-                (Object) value4,
+                value4,
                 Criteria.GREATER_THAN);
         Criteria.Criterion crit9 = c.getNewCriterion(
                 table5,
                 column5,
-                (Object) value5,
+                value5,
                 Criteria.GREATER_EQUAL);
 
         crit6.and(crit7).or(crit8).and(crit9);
         c.add(crit6);
-        c.addSelectColumn("*");
+        c.addSelectColumn(new ColumnImpl(null, "myTable2", null, "*"));
         expect =
             "SELECT * FROM myTable2, myTable3, myTable4, myTable5 WHERE "
                 + "(((myTable2.myColumn2<? "
@@ -211,7 +205,7 @@ public class CriteriaTest extends BaseTe
         Criteria.Criterion compareToCriterion = c.getNewCriterion(
                 table5,
                 column5,
-                (Object) value5,
+                value5,
                 Criteria.GREATER_EQUAL);
         assertEquals(compareToCriterion.hashCode(),crit9.hashCode());
         assertEquals("myTable5.myColumn5>=myValue5", crit9.toString());
@@ -224,12 +218,12 @@ public class CriteriaTest extends BaseTe
     {
         Criteria.Criterion cn1 =
             c.getNewCriterion(
-                "INVOICE.COST",
+                new ColumnImpl("INVOICE", "COST"),
                 1000,
                 Criteria.GREATER_EQUAL);
         Criteria.Criterion cn2 =
             c.getNewCriterion(
-                "INVOICE.COST",
+                new ColumnImpl("INVOICE", "COST"),
                 5000,
                 Criteria.LESS_EQUAL);
         c.add(cn1.and(cn2));
@@ -246,24 +240,22 @@ public class CriteriaTest extends BaseTe
 
     /**
      * Test Criterion.setIgnoreCase().
-     * As the output is db specific the test just prints the result to
-     * System.out
      */
     public void testCriterionIgnoreCase() throws TorqueException
     {
         Criteria.Criterion criterion1 = c.getNewCriterion(
-                "TABLE.COLUMN1", (Object) "FoObAr1", Criteria.LIKE);
+                new ColumnImpl("TABLE", "COLUMN1"), "FoObAr1", Criteria.LIKE);
         criterion1.setIgnoreCase(true);
         Criteria.Criterion criterion2 = c.getNewCriterion(
-                "TABLE.COLUMN2", (Object) "FoObAr2", Criteria.EQUAL);
+                new ColumnImpl("TABLE", "COLUMN2"), "FoObAr2", Criteria.EQUAL);
         criterion2.setIgnoreCase(true);
         Criteria.Criterion criterion3 = c.getNewCriterion(
-                "TABLE.COLUMN3", (Object) "FoObAr3", Criteria.EQUAL);
+                new ColumnImpl("TABLE", "COLUMN3"), "FoObAr3", Criteria.EQUAL);
         Criteria.Criterion criterion4 = c.getNewCriterion(
-                "TABLE.COLUMN4", (Object) new Integer(1), Criteria.EQUAL);
+                new ColumnImpl("TABLE", "COLUMN4"), new Integer(1), Criteria.EQUAL);
         criterion4.setIgnoreCase(true);
         c.add(criterion1.and(criterion2).and(criterion3).and(criterion4));
-        c.addSelectColumn("*");
+        c.addSelectColumn(new ColumnImpl(null, "TABLE", null, "*"));
         c.setDbName("postgresql");
         Query result = SqlBuilder.buildQuery(c);
 
@@ -285,7 +277,7 @@ public class CriteriaTest extends BaseTe
      */
     public void testBoolean() throws TorqueException
     {
-        c.add("TABLE.COLUMN", true);
+        c.add(new ColumnImpl("TABLE", "COLUMN"), true);
 
         Query result = SqlBuilder.buildQuery(c);
 
@@ -299,7 +291,7 @@ public class CriteriaTest extends BaseTe
 
         // test the postgresql variation
         c = new Criteria();
-        c.add("TABLE.COLUMN", true);
+        c.add(new ColumnImpl("TABLE", "COLUMN"), true);
         c.setDbName("postgresql");
 
         result = SqlBuilder.buildQuery(c);
@@ -318,7 +310,7 @@ public class CriteriaTest extends BaseTe
      */
     public void testAddDate() throws TorqueException
     {
-         c.addDate("TABLE.DATE_COLUMN", 2003, 0, 22);
+         c.addDate(new ColumnImpl("TABLE", "DATE_COLUMN"), 2003, 0, 22);
 
         Query result = SqlBuilder.buildQuery(c);
 
@@ -339,8 +331,8 @@ public class CriteriaTest extends BaseTe
      */
     public void testAndDate() throws TorqueException
     {
-        c.addDate("TABLE.DATE_COLUMN", 2003, 0, 22, Criteria.GREATER_THAN);
-        c.andDate("TABLE.DATE_COLUMN", 2004, 2, 24, Criteria.LESS_THAN);
+        c.addDate(new ColumnImpl("TABLE", "DATE_COLUMN"), 2003, 0, 22, Criteria.GREATER_THAN);
+        c.andDate(new ColumnImpl("TABLE", "DATE_COLUMN"), 2004, 2, 24, Criteria.LESS_THAN);
 
         Query result = SqlBuilder.buildQuery(c);
         assertEquals(
@@ -365,7 +357,7 @@ public class CriteriaTest extends BaseTe
     {
         Calendar cal = new GregorianCalendar(2003, 0, 22);
         Date date = cal.getTime();
-        c.add("TABLE.DATE_COLUMN", date);
+        c.add(new ColumnImpl("TABLE", "DATE_COLUMN"), date);
 
         Query result = SqlBuilder.buildQuery(c);
         assertEquals(
@@ -383,15 +375,29 @@ public class CriteriaTest extends BaseTe
 
     public void testCurrentDate() throws TorqueException
     {
-        c.add("TABLE.DATE_COLUMN", Criteria.CURRENT_DATE)
-                .add("TABLE.TIME_COLUMN", Criteria.CURRENT_TIME);
-        c.addSelectColumn("COUNT(*)");
+        c.add(new ColumnImpl("TABLE", "DATE_COLUMN"), Criteria.CURRENT_DATE);
+        c.addSelectColumn(new ColumnImpl(null, "TABLE", null, "COUNT(*)"));
+
+        Query result = SqlBuilder.buildQuery(c);
+        assertEquals(
+                "SELECT COUNT(*) FROM TABLE WHERE "
+                    + "TABLE.DATE_COLUMN=CURRENT_DATE",
+                result.toString());
+
+        List<Object> preparedStatementReplacements
+                = result.getPreparedStatementReplacements();
+        assertEquals(0, preparedStatementReplacements.size());
+    }
+
+    public void testCurrentTime() throws TorqueException
+    {
+        c.add(new ColumnImpl("TABLE", "TIME_COLUMN"), Criteria.CURRENT_TIME);
+        c.addSelectColumn(new ColumnImpl(null, "TABLE", null, "COUNT(*)"));
 
         Query result = SqlBuilder.buildQuery(c);
         assertEquals(
                 "SELECT COUNT(*) FROM TABLE WHERE "
-                    + "TABLE.TIME_COLUMN=CURRENT_TIME "
-                    + "AND TABLE.DATE_COLUMN=CURRENT_DATE",
+                    + "TABLE.TIME_COLUMN=CURRENT_TIME",
                 result.toString());
 
         List<Object> preparedStatementReplacements
@@ -401,9 +407,9 @@ public class CriteriaTest extends BaseTe
 
     public void testCriteriaOffsetLimit() throws TorqueException
     {
-        c.addDate("TABLE.DATE_COLUMN", 2003, 0, 22);
+        c.addDate(new ColumnImpl("TABLE", "DATE_COLUMN"), 2003, 0, 22);
         c.setOffset(3).setLimit(5);
-        c.addSelectColumn("COUNT(*)");
+        c.addSelectColumn(new ColumnImpl(null, "TABLE", null, "COUNT(*)"));
 
         Query result = SqlBuilder.buildQuery(c);
         String expect
@@ -412,14 +418,29 @@ public class CriteriaTest extends BaseTe
         assertEquals(expect, result.toString());
     }
 
+    public void testCriteriaWithOffsetNoLimitPostgresql()
+            throws TorqueException
+    {
+        c.addDate(new ColumnImpl("TABLE", "DATE_COLUMN"), 2003, 0, 22);
+        c.setOffset(3);
+        c.addSelectColumn(new ColumnImpl(null, "TABLE", null, "COUNT(*)"));
+
+        Query result = SqlBuilder.buildQuery(c);
+        String expect
+            = "SELECT COUNT(*) FROM TABLE WHERE TABLE.DATE_COLUMN=?"
+                + " OFFSET 3";
+        assertEquals(expect, result.toString());
+    }
+
     /**
      * TORQUE-87
      */
-    public void testCriteriaWithOffsetNoLimit() throws TorqueException
+    public void testCriteriaWithOffsetNoLimitMysql() throws TorqueException
     {
-        c.addDate("TABLE.DATE_COLUMN", 2003, 0, 22);
+        c.addDate(new ColumnImpl("TABLE", "DATE_COLUMN"), 2003, 0, 22);
         c.setOffset(3);
-        c.addSelectColumn("COUNT(*)");
+        c.addSelectColumn(new ColumnImpl(null, "TABLE", null, "COUNT(*)"));
+        c.setDbName("mysql");
 
         Query result = SqlBuilder.buildQuery(c);
         String expect
@@ -430,9 +451,9 @@ public class CriteriaTest extends BaseTe
 
     public void testCriteriaToStringLimit() throws TorqueException
     {
-        c.addDate("TABLE.DATE_COLUMN", 2003, 0, 22);
+        c.addDate(new ColumnImpl("TABLE", "DATE_COLUMN"), 2003, 0, 22);
         c.setLimit(5);
-        c.addSelectColumn("COUNT(*)");
+        c.addSelectColumn(new ColumnImpl(null, "TABLE", null, "COUNT(*)"));
 
         Query result = SqlBuilder.buildQuery(c);
         String expect
@@ -448,7 +469,7 @@ public class CriteriaTest extends BaseTe
      */
     public void testLikeWithoutWildcards() throws TorqueException
     {
-        c.add("TABLE.COLUMN", (Object) "no wildcards", Criteria.LIKE);
+        c.add(new ColumnImpl("TABLE", "COLUMN"), "no wildcards", Criteria.LIKE);
 
         Query result = SqlBuilder.buildQuery(c);
         assertEquals(
@@ -471,7 +492,7 @@ public class CriteriaTest extends BaseTe
      */
     public void testNotLikeWithoutWildcards()
     {
-        c.add("TABLE.COLUMN", (Object) "no wildcards", Criteria.NOT_LIKE);
+        c.add(new ColumnImpl("TABLE", "COLUMN"), "no wildcards", Criteria.NOT_LIKE);
 
         String firstExpect = "SELECT  FROM TABLE WHERE TABLE.COLUMN!=?";
         String secondExpect = "SELECT  FROM TABLE WHERE TABLE.COLUMN<>?";
@@ -507,17 +528,17 @@ public class CriteriaTest extends BaseTe
         c.setDbName("myDB");
         c.setAll();
         c.setDistinct();
-        c.addSelectColumn("Author.NAME");
-        c.addSelectColumn("Author.AUTHOR_ID");
-        c.addDescendingOrderByColumn("Author.NAME");
-        c.addAscendingOrderByColumn("Author.AUTHOR_ID");
+        c.addSelectColumn(new ColumnImpl("Author", "NAME"));
+        c.addSelectColumn(new ColumnImpl("Author", "AUTHOR_ID"));
+        c.addDescendingOrderByColumn(new ColumnImpl("Author", "NAME"));
+        c.addAscendingOrderByColumn(new ColumnImpl("Author", "AUTHOR_ID"));
         c.addAlias("Writer", "Author");
-        c.addAsColumn("AUTHOR_NAME", "Author.NAME");
-        c.addJoin("Author.AUTHOR_ID", "Book.AUTHOR_ID", Criteria.INNER_JOIN);
-        c.add("Author.NAME", (Object) "author%", Criteria.LIKE);
+        c.addAsColumn("AUTHOR_NAME", new ColumnImpl("Author", "NAME"));
+        c.addJoin(new ColumnImpl("Author", "AUTHOR_ID"), new ColumnImpl("Book", "AUTHOR_ID"), Criteria.INNER_JOIN);
+        c.add(new ColumnImpl("Author", "NAME"), "author%", Criteria.LIKE);
 
         // Some direct Criterion checks
-        Criterion cn = c.getCriterion("Author.NAME");
+        Criterion cn = c.getCriterion(new ColumnImpl("Author", "NAME"));
         cn.setIgnoreCase(true);
         assertEquals("author%", cn.getValue());
         assertEquals(Criteria.LIKE, cn.getComparison());
@@ -544,12 +565,12 @@ public class CriteriaTest extends BaseTe
         assertTrue(selectModifiersClone.contains(Criteria.DISTINCT.toString()));
         assertEquals(c.getSelectModifiers(), cClone.getSelectModifiers());
         List selectColumnsClone = cClone.getSelectColumns();
-        assertTrue(selectColumnsClone.contains("Author.NAME"));
-        assertTrue(selectColumnsClone.contains("Author.AUTHOR_ID"));
+        assertTrue(selectColumnsClone.contains(new ColumnImpl("Author", "NAME")));
+        assertTrue(selectColumnsClone.contains(new ColumnImpl("Author", "AUTHOR_ID")));
         assertEquals(c.getSelectColumns(), cClone.getSelectColumns());
         List orderByColumnsClone = cClone.getOrderByColumns();
-        assertTrue(orderByColumnsClone.contains("Author.NAME DESC"));
-        assertTrue(orderByColumnsClone.contains("Author.AUTHOR_ID ASC"));
+        assertTrue(orderByColumnsClone.contains(new OrderBy(new ColumnImpl("Author.NAME"), SqlEnum.DESC, false)));
+        assertTrue(orderByColumnsClone.contains(new OrderBy(new ColumnImpl("Author.AUTHOR_ID"), SqlEnum.ASC, false)));
         assertEquals(c.getOrderByColumns(), cClone.getOrderByColumns());
         Map aliasesClone = cClone.getAliases();
         assertTrue(aliasesClone.containsKey("Writer"));
@@ -557,19 +578,19 @@ public class CriteriaTest extends BaseTe
         assertEquals(c.getAliases(), cClone.getAliases());
         Map asColumnsClone = cClone.getAsColumns();
         assertTrue(asColumnsClone.containsKey("AUTHOR_NAME"));
-        assertEquals("Author.NAME", asColumnsClone.get("AUTHOR_NAME"));
+        assertEquals(new ColumnImpl("Author", "NAME"), asColumnsClone.get("AUTHOR_NAME"));
         assertEquals(c.getAsColumns(), cClone.getAsColumns());
 
         // Check Joins
         List joinsClone = cClone.getJoins();
         Join joinClone = (Join) joinsClone.get(0);
-        assertEquals("Author.AUTHOR_ID", joinClone.getLeftColumn());
-        assertEquals("Book.AUTHOR_ID", joinClone.getRightColumn());
+        assertEquals(new ColumnImpl("Author", "AUTHOR_ID"), joinClone.getLeftColumn());
+        assertEquals(new ColumnImpl("Book", "AUTHOR_ID"), joinClone.getRightColumn());
         assertEquals(Criteria.INNER_JOIN, joinClone.getJoinType());
         assertEquals(c.getJoins(), cClone.getJoins());
 
         // Some Criterion checks
-        Criterion cnClone = cClone.getCriterion("Author.NAME");
+        Criterion cnClone = cClone.getCriterion(new ColumnImpl("Author", "NAME"));
         assertEquals("author%", cnClone.getValue());
         assertEquals(Criteria.LIKE, cnClone.getComparison());
         assertEquals(cn.isIgnoreCase(), cnClone.isIgnoreCase());
@@ -588,9 +609,9 @@ public class CriteriaTest extends BaseTe
      */
     public void testEquals() throws TorqueException
     {
-        c.addSelectColumn("Author.NAME");
-        c.addSelectColumn("Author.AUTHOR_ID");
-        c.add("Author.NAME", "foobar");
+        c.addSelectColumn(new ColumnImpl("Author", "NAME"));
+        c.addSelectColumn(new ColumnImpl("Author", "AUTHOR_ID"));
+        c.add(new ColumnImpl("Author", "NAME"), "foobar");
         Criteria cClone = (Criteria) SerializationUtils.clone(c);
         assertTrue(c.equals(cClone));
     }
@@ -603,8 +624,7 @@ public class CriteriaTest extends BaseTe
         // we need a rudimentary databaseMap for this test case to work
         DatabaseMap dbMap = Torque.getDatabaseMap(Torque.getDefaultDB());
 
-        TableMap tableMap = new TableMap("AUTHOR", dbMap);
-        dbMap.addTable(tableMap);
+        TableMap tableMap = dbMap.addTable("AUTHOR");
 
         ColumnMap columnMap = new ColumnMap("NAME", tableMap);
         columnMap.setType("");
@@ -616,13 +636,12 @@ public class CriteriaTest extends BaseTe
 
         // check that alias'ed tables are referenced by their alias
         // name when added to the select clause.
-        c.addSelectColumn("AUTHOR.NAME");
+        c.addSelectColumn(new ColumnImpl("AUTHOR", "NAME"));
         c.addAlias("a", "AUTHOR");
-        c.addJoin(
-                "AUTHOR.AUTHOR_ID",
-                "a." + "AUTHOR_ID");
+        c.addJoin(new ColumnImpl("AUTHOR", "AUTHOR_ID"),
+                new ColumnImpl("a", "AUTHOR_ID"));
         c.addAscendingOrderByColumn(
-                "a.NAME");
+                new ColumnImpl("a", "NAME"));
 
         Query result = SqlBuilder.buildQuery(c);
         assertEquals("SELECT AUTHOR.NAME, a.NAME "

Modified: db/torque/torque4/trunk/torque-runtime/src/test/resources/Torque.properties
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/resources/Torque.properties?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/resources/Torque.properties (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/resources/Torque.properties Sat Nov 26 10:59:15 2011
@@ -16,7 +16,7 @@
 # under the License.
 
 
-torque.database.default = mysql
+torque.database.default = postgresql
 torque.database.mysql.adapter=mysql
 torque.dsfactory.mysql.factory= org.apache.torque.dsfactory.SharedPoolDataSourceFactory
 torque.database.postgresql.adapter=postgresql

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/TemplateOptionName.java Sat Nov 26 10:59:15 2011
@@ -63,14 +63,16 @@ public enum TemplateOptionName implement
     OM_DB_OBJECT_DEFAULT_BASE_CLASS("torque.om.dbObjectDefaultBaseClass"),
 
     /** The prefix of the name of the mapInit class. */
-    OM_MAP_INIT_CLASS_NAME_PREFIX("torque.om.mapInit.mapInitClassNamePrefix"),
+    OM_DATABASE_MAP_INIT_CLASS_NAME_PREFIX(
+            "torque.om.mapInit.databaseMapInitClassNamePrefix"),
 
     /** The suffix of the name of the mapInit class. */
-    OM_MAP_INIT_CLASS_NAME_SUFFIX("torque.om.mapInit.mapInitClassNameSuffix"),
+    OM_DATABASE_MAP_INIT_CLASS_NAME_SUFFIX(
+            "torque.om.mapInit.databaseMapInitClassNameSuffix"),
 
     /** The additional prefix of the name of the baseMapInit class. */
-    OM_BASE_MAP_INIT_CLASS_NAME_PREFIX(
-            "torque.om.mapInit.baseMapInitClassNamePrefix"),
+    OM_BASE_DATABASE_MAP_INIT_CLASS_NAME_PREFIX(
+            "torque.om.mapInit.baseDatabaseMapInitClassNamePrefix"),
 
     /** The prefix of the name of the manager class. */
     OM_MANAGER_CLASS_NAME_PREFIX("torque.om.className.managerClassNamePrefix"),

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/DatabaseAttributeName.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/DatabaseAttributeName.java?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/DatabaseAttributeName.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/DatabaseAttributeName.java Sat Nov 26 10:59:15 2011
@@ -27,11 +27,15 @@ import org.apache.torque.generator.sourc
  */
 public enum DatabaseAttributeName implements SourceAttributeName
 {
+    /** The name of the root database in case of an external schema,
+     * otherwise just the name of the database itself.. */
+    ROOT_DATABASE_NAME("rootDatabaseName"),
+
     /** The name of the mapInit class to generate. */
-    MAP_INIT_CLASS_NAME("mapInitClassName"),
+    DATABASE_MAP_INIT_CLASS_NAME("databaseMapInitClassName"),
 
     /** The name of the mapInit class to generate. */
-    BASE_MAP_INIT_CLASS_NAME("baseMapInitClassName");
+    BASE_DATABASE_MAP_INIT_CLASS_NAME("baseDatabaseMapInitClassName");
 
     /** The name of the source element attribute, not null. */
     private String name;

Modified: 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=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/LoadExternalSchemaTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/LoadExternalSchemaTransformer.java Sat Nov 26 10:59:15 2011
@@ -20,7 +20,6 @@ package org.apache.torque.templates.tran
  */
 
 import java.io.File;
-import java.util.Iterator;
 import java.util.List;
 
 import org.apache.commons.logging.Log;
@@ -34,6 +33,7 @@ import org.apache.torque.generator.sourc
 import org.apache.torque.generator.source.transform.SourceTransformerException;
 import org.apache.torque.templates.TorqueSchemaAttributeName;
 import org.apache.torque.templates.TorqueSchemaElementName;
+import org.apache.torque.templates.transformer.om.mapInit.DatabaseMapInitTransformer;
 
 /**
  * A SourceTransformer which loads the external schemata tables
@@ -48,6 +48,29 @@ public class LoadExternalSchemaTransform
             = LogFactory.getLog(LoadExternalSchemaTransformer.class);
 
     /**
+     * The base dir for the external schema,
+     * or null to compute from the current source file.
+     */
+    private File baseDir;
+
+    /**
+     * Standard constructor.
+     */
+    public LoadExternalSchemaTransformer()
+    {
+    }
+
+    /**
+     * Constructor to override base dir.
+     *
+     * @param baseDir the new base dir.
+     */
+    public LoadExternalSchemaTransformer(File baseDir)
+    {
+        this.baseDir = baseDir;
+    }
+
+    /**
      * Loads the external schemata tables into the current graph.
      * The external database element is added as child of the
      * external-schema element.
@@ -75,14 +98,25 @@ public class LoadExternalSchemaTransform
             root.getChildren().add(allTables);
         }
 
+        String rootDatabaseName = (String) root.getAttribute(
+                DatabaseAttributeName.ROOT_DATABASE_NAME);
         for (SourceElement externalSchemaElement : externalSchemaElementList)
         {
-            File currentSourceFile = controllerState.getSourceFile();
-            File baseDir = currentSourceFile.getParentFile();
+            File externalSchemaBaseDir;
+            if (this.baseDir == null)
+            {
+                File currentSourceFile = controllerState.getSourceFile();
+                externalSchemaBaseDir = currentSourceFile.getParentFile();
+            }
+            else
+            {
+                externalSchemaBaseDir = baseDir;
+            }
             String relativePath = externalSchemaElement.getAttribute(
                     TorqueSchemaAttributeName.FILENAME)
                 .toString();
-            File externalSchemaPath = new File(baseDir, relativePath);
+            File externalSchemaPath
+                = new File(externalSchemaBaseDir, relativePath);
             try
             {
                 FileSource fileSource = new FileSource(
@@ -91,18 +125,25 @@ public class LoadExternalSchemaTransform
                         controllerState);
                 SourceElement externalSchemaRootElement
                         = fileSource.getRootElement();
+                externalSchemaRootElement.setAttribute(
+                        DatabaseAttributeName.ROOT_DATABASE_NAME,
+                        rootDatabaseName);
+                DatabaseMapInitTransformer.setDatabaseMapInitClassNameAttributes(
+                        externalSchemaRootElement,
+                        rootDatabaseName,
+                        controllerState);
 
                 this.transform(externalSchemaRootElement, controllerState);
 
                 externalSchemaElement.getChildren().add(
                         externalSchemaRootElement);
 
-                SourceElement externalAllTables 
+                SourceElement externalAllTables
                         = externalSchemaRootElement.getChild(
                                 DatabaseChildElementName.ALL_TABLES);
 
                 // fill root's all-tables with all external tables
-                for (SourceElement externalTable 
+                for (SourceElement externalTable
                         : externalAllTables.getChildren(
                             TorqueSchemaElementName.TABLE))
                 {
@@ -117,8 +158,8 @@ public class LoadExternalSchemaTransform
                 throw new SourceTransformerException(e);
             }
         }
-        // add own tablkes to root's all-tables
-        for (SourceElement table 
+        // add own tables to root's all-tables
+        for (SourceElement table
                 : root.getChildren(TorqueSchemaElementName.TABLE))
         {
             allTables.getChildren().add(table);

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTableTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTableTransformer.java?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTableTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTableTransformer.java Sat Nov 26 10:59:15 2011
@@ -139,7 +139,7 @@ public class OMTableTransformer extends 
      * @throws SourceTransformerException if both attributes javaName and name
      *         are not set on the tableElement.
      */
-    protected void setJavaNameAttribute(SourceElement tableElement)
+    public static void setJavaNameAttribute(SourceElement tableElement)
             throws SourceTransformerException
     {
         // set javaName attribute

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=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/OMTransformer.java Sat Nov 26 10:59:15 2011
@@ -24,7 +24,9 @@ import org.apache.torque.generator.sourc
 import org.apache.torque.generator.source.transform.SourceTransformer;
 import org.apache.torque.generator.source.transform.SourceTransformerException;
 import org.apache.torque.templates.TemplateOptionName;
+import org.apache.torque.templates.TorqueSchemaAttributeName;
 import org.apache.torque.templates.TorqueSchemaElementName;
+import org.apache.torque.templates.transformer.om.mapInit.DatabaseMapInitTransformer;
 
 /**
  * Performs the transformations which are necessary to apply the templates
@@ -104,6 +106,11 @@ public class OMTransformer implements So
     {
         TemplateOptionName.checkRequiredOptions(controllerState);
 
+        setRootDatabaseNameAttribute(root);
+        DatabaseMapInitTransformer.setDatabaseMapInitClassNameAttributes(
+                root,
+                (String) root.getAttribute(TorqueSchemaAttributeName.NAME),
+                controllerState);
         // load referenced external schemata
         loadExternalSchemaTransformer.transform(root, controllerState);
 
@@ -150,4 +157,19 @@ public class OMTransformer implements So
 
         return root;
     }
+
+    /**
+     * Sets the rootDatabaseName attribute of the database element
+     * to the database's name.
+     *
+     * @param databaseElement the database element, not null.
+     */
+    public static void setRootDatabaseNameAttribute(SourceElement databaseElement)
+    {
+        String databaseName = (String) databaseElement.getAttribute(
+                TorqueSchemaAttributeName.NAME);
+        databaseElement.setAttribute(
+                DatabaseAttributeName.ROOT_DATABASE_NAME,
+                databaseName);
+    }
 }

Added: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTableTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTableTransformer.java?rev=1206426&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTableTransformer.java (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTableTransformer.java Sat Nov 26 10:59:15 2011
@@ -0,0 +1,67 @@
+package org.apache.torque.templates.transformer.om.mapInit;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.InputStreamReader;
+
+import org.apache.torque.generator.control.ControllerState;
+import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.transform.AttributeTransformer;
+import org.apache.torque.generator.source.transform.SourceTransformerException;
+import org.apache.torque.templates.TorqueSchemaElementName;
+import org.apache.torque.templates.transformer.om.OMTableTransformer;
+
+/**
+ * A transformer which sets attributes for the table elements
+ * for generating the map init classes.
+ *
+ * @version $Id: $
+ */
+public class DatabaseMapInitTableTransformer extends AttributeTransformer
+{
+    /**
+     * Constructor.
+     *
+     * @throws SourceTransformerException if the attribute map is malformed.
+     */
+    public DatabaseMapInitTableTransformer() throws SourceTransformerException
+    {
+        super(new InputStreamReader(
+                DatabaseMapInitTableTransformer.class
+                   .getResourceAsStream(
+                        "DatabaseMapInitTableTransformer.properties")));
+    }
+
+    public SourceElement transform(
+            SourceElement rootElement,
+            ControllerState controllerState)
+        throws SourceTransformerException
+    {
+        if (!TorqueSchemaElementName.TABLE.getName().equals(
+                rootElement.getName()))
+        {
+            throw new IllegalArgumentException("Illegal element Name "
+                    + rootElement.getName());
+        }
+        OMTableTransformer.setJavaNameAttribute(rootElement);
+        super.transform(rootElement, controllerState);
+        return rootElement;
+    }
+ }

Copied: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTransformer.java (from r1145732, db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/MapInitDatabaseTransformer.java)
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTransformer.java?p2=db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTransformer.java&p1=db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/MapInitDatabaseTransformer.java&r1=1145732&r2=1206426&rev=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/MapInitDatabaseTransformer.java (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/om/mapInit/DatabaseMapInitTransformer.java Sat Nov 26 10:59:15 2011
@@ -19,80 +19,203 @@ package org.apache.torque.templates.tran
  * under the License.
  */
 
+import java.io.File;
 import java.io.InputStreamReader;
 
 import org.apache.torque.generator.control.ControllerState;
 import org.apache.torque.generator.processor.string.Camelbacker;
 import org.apache.torque.generator.source.SourceElement;
+import org.apache.torque.generator.source.stream.CombinedFileSource;
 import org.apache.torque.generator.source.transform.AttributeTransformer;
+import org.apache.torque.generator.source.transform.SourceTransformer;
 import org.apache.torque.generator.source.transform.SourceTransformerException;
 import org.apache.torque.templates.TemplateOptionName;
 import org.apache.torque.templates.TorqueSchemaAttributeName;
 import org.apache.torque.templates.TorqueSchemaElementName;
 import org.apache.torque.templates.transformer.om.DatabaseAttributeName;
+import org.apache.torque.templates.transformer.om.DatabaseChildElementName;
+import org.apache.torque.templates.transformer.om.LoadExternalSchemaTransformer;
+import org.apache.torque.templates.transformer.om.OMTransformer;
 
 /**
- * A transformer providing extra attributes for the genreration of the
- * mapInit classes.
+ * A transformer providing extra attributes for the generation of the
+ * mapInit classes. It collects all tables for a database with the same name
+ * and also sets attributes needed for java generation.
  *
  * @version $Id: $
  */
-public class MapInitDatabaseTransformer  extends AttributeTransformer
+public class DatabaseMapInitTransformer extends AttributeTransformer
 {
     /** The camelbacker for creating the MapInit class name. */
     private static Camelbacker camelbacker = new Camelbacker();
 
+    static
+    {
+        camelbacker.setDefaultLowerCase(false);
+    }
+
+    /**
+     * The element under which all databases with same names are collected.
+     */
+    private static final String DATABASE_SETS_ELEMENT = "databaseSets";
+
+    /**
+     * The element under which the tables of all databases with the same name
+     * are collected.
+     */
+    private static final String DATABASE_SET_ELEMENT = "databaseSet";
+
+    /** The transformer for table elements. */
+    private DatabaseMapInitTableTransformer tableTransformer
+            = new DatabaseMapInitTableTransformer();
+
     /**
      * Constructor.
      *
      * @throws SourceTransformerException if the attribute map is malformed.
      */
-    public MapInitDatabaseTransformer() throws SourceTransformerException
+    public DatabaseMapInitTransformer() throws SourceTransformerException
     {
         super(new InputStreamReader(
-                MapInitDatabaseTransformer.class
+                DatabaseMapInitTransformer.class
                    .getResourceAsStream(
-                        "MapInitDatabaseTransformer.properties")));
+                        "DatabaseMapInitTransformer.properties")));
     }
 
     public SourceElement transform(
-            SourceElement databaseElement,
+            SourceElement rootElement,
             ControllerState controllerState)
         throws SourceTransformerException
     {
-        if (!TorqueSchemaElementName.DATABASE.getName().equals(
-                databaseElement.getName()))
+        if (!CombinedFileSource.ROOT_ELEMENT_NAME.equals(
+                rootElement.getName()))
         {
             throw new IllegalArgumentException("Illegal element Name "
-                    + databaseElement.getName());
+                    + rootElement.getName());
+        }
+        SourceElement databaseSetsElement
+                = new SourceElement(DATABASE_SETS_ELEMENT);
+        rootElement.getChildren().add(databaseSetsElement);
+
+        for (SourceElement fileElement
+                : rootElement.getChildren(CombinedFileSource.FILE_ELEMENT_NAME))
+        {
+            SourceElement databaseElement
+                    = fileElement.getChild(TorqueSchemaElementName.DATABASE);
+            if (databaseElement == null)
+            {
+                throw new IllegalArgumentException("The root element of file "
+                        + fileElement.getAttribute(
+                                CombinedFileSource.PATH_ATTRIBUTE_NAME)
+                        + " is unknown, should be "
+                        + TorqueSchemaElementName.DATABASE.getName());
+            }
+            String name = (String) databaseElement.getAttribute(
+                    TorqueSchemaAttributeName.NAME.getName());
+            if (name == null)
+            {
+                throw new SourceTransformerException("The attribute "
+                        + TorqueSchemaAttributeName.NAME.getName()
+                        + " on element "
+                        + databaseElement.getName()
+                        + " is null");
+            }
+            OMTransformer.setRootDatabaseNameAttribute(databaseElement);
+            // load referenced external schemata
+            String path = (String) fileElement.getAttribute(
+                    CombinedFileSource.PATH_ATTRIBUTE_NAME);
+            File pathFile = new File(path);
+            SourceTransformer loadExternalSchemaTransformer
+                   = new LoadExternalSchemaTransformer(
+                           pathFile.getParentFile());
+            loadExternalSchemaTransformer.transform(
+                    databaseElement,
+                    controllerState);
+
+            SourceElement allTablesRoot
+                = databaseElement.getChild(DatabaseChildElementName.ALL_TABLES);
+
+            SourceElement databaseSetElement = getDatabaseSetWithDatabaseName(
+                    databaseSetsElement,
+                    name);
+            if (databaseSetElement == null)
+            {
+                databaseSetElement = new SourceElement(DATABASE_SET_ELEMENT);
+                databaseSetElement.setAttribute(
+                        TorqueSchemaAttributeName.NAME,
+                        name);
+                databaseSetsElement.getChildren().add(databaseSetElement);
+            }
+            for (SourceElement tableElement : allTablesRoot.getChildren(
+                    TorqueSchemaElementName.TABLE))
+            {
+                databaseSetElement.getChildren().add(tableElement);
+            }
         }
-        String name = (String) databaseElement.getAttribute(
-                TorqueSchemaAttributeName.NAME.getName());
-        if (name == null)
+
+        for (SourceElement databaseSetElement
+                : databaseSetsElement.getChildren(DATABASE_SET_ELEMENT))
         {
-            throw new SourceTransformerException("The attribute "
-                    + TorqueSchemaAttributeName.NAME.getName()
-                    + " on element "
-                    + databaseElement.getName()
-                    + " is null");
+            String name = (String) databaseSetElement.getAttribute(
+                    TorqueSchemaAttributeName.NAME);
+            setDatabaseMapInitClassNameAttributes(
+                    databaseSetElement,
+                    name,
+                    controllerState);
+            super.transform(databaseSetElement, controllerState);
+            for (SourceElement tableElement
+                : databaseSetElement.getChildren(TorqueSchemaElementName.TABLE))
+            {
+                tableTransformer.transform(tableElement, controllerState);
+            }
         }
-        String mapInitClassName
+        return rootElement;
+    }
+
+    /**
+     * Sets the databaseMapInitClassName and baseDatabaseMapInitClassName
+     * attributes on a source element.
+     *
+     * @param sourceElement the element where the attribute should be set,
+     *        not null.
+     * @param databaseName the name of the database element, not null.
+     * @param controllerState the controller state, not null.
+     */
+    public static void setDatabaseMapInitClassNameAttributes(
+            SourceElement sourceElement,
+            String databaseName,
+            ControllerState controllerState)
+    {
+        String databaseMapInitClassName
                 = controllerState.getOption(
-                        TemplateOptionName.OM_MAP_INIT_CLASS_NAME_PREFIX)
-                    + camelbacker.process(name)
+                        TemplateOptionName.OM_DATABASE_MAP_INIT_CLASS_NAME_PREFIX)
+                    + camelbacker.process(databaseName)
                     + controllerState.getOption(
-                        TemplateOptionName.OM_MAP_INIT_CLASS_NAME_SUFFIX);
-        databaseElement.setAttribute(
-                DatabaseAttributeName.MAP_INIT_CLASS_NAME,
-                mapInitClassName);
+                        TemplateOptionName.OM_DATABASE_MAP_INIT_CLASS_NAME_SUFFIX);
+        sourceElement.setAttribute(
+                DatabaseAttributeName.DATABASE_MAP_INIT_CLASS_NAME,
+                databaseMapInitClassName);
         String baseMapInitClassName
             = controllerState.getOption(
-                    TemplateOptionName.OM_BASE_MAP_INIT_CLASS_NAME_PREFIX)
-                + mapInitClassName;
-        databaseElement.setAttribute(
-                DatabaseAttributeName.BASE_MAP_INIT_CLASS_NAME,
+                    TemplateOptionName.OM_BASE_DATABASE_MAP_INIT_CLASS_NAME_PREFIX)
+                + databaseMapInitClassName;
+        sourceElement.setAttribute(
+                DatabaseAttributeName.BASE_DATABASE_MAP_INIT_CLASS_NAME,
                 baseMapInitClassName);
-        super.transform(databaseElement, controllerState);
-        return databaseElement;
+    }
+
+    private SourceElement getDatabaseSetWithDatabaseName(
+            SourceElement databaseSetsElement, String name)
+    {
+        for (SourceElement databaseSetElement
+                : databaseSetsElement.getChildren(DATABASE_SET_ELEMENT))
+        {
+            if (databaseSetElement.getAttribute(TorqueSchemaAttributeName.NAME)
+                    .equals(name))
+            {
+                return databaseSetElement;
+            }
+        }
+        return null;
     }
  }

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/control.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/control.xml?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/control.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/control.xml Sat Nov 26 10:59:15 2011
@@ -420,20 +420,20 @@
       <mergepoint name="package">
         <action
             xsi:type="optionAction"
-            option="torque.om.mapInit.mapInitPackage"
+            option="torque.om.mapInit.databaseMapInitPackage"
             acceptNotSet="false"/>
       </mergepoint>
       <mergepoint name="classname">
         <action
             xsi:type="sourceElementAttributeAction"
             element="."
-            attribute="mapInitClassName"
+            attribute="databaseMapInitClassName"
             acceptNotSet="false"/>
       </mergepoint>
     </filenameOutlet>
-    <source xsi:type="fileSource" elements="database" 
+    <source xsi:type="fileSource" combineFiles="true" elements="source/databaseSets/databaseSet"
         skipDecider="org.apache.torque.templates.skipdecider.MapInitSkipDecider">
-      <transformer class="org.apache.torque.templates.transformer.om.mapInit.MapInitDatabaseTransformer"/>
+      <transformer class="org.apache.torque.templates.transformer.om.mapInit.DatabaseMapInitTransformer"/>
       <include>*schema.xml</include>
       <exclude>id-table-schema.xml</exclude>
     </source>
@@ -455,14 +455,13 @@
         <action
             xsi:type="sourceElementAttributeAction"
             element="."
-            attribute="baseMapInitClassName"
+            attribute="baseDatabaseMapInitClassName"
             acceptNotSet="false"/>
       </mergepoint>
     </filenameOutlet>
-    <source xsi:type="fileSource" elements="database" 
+    <source xsi:type="fileSource" combineFiles="true" elements="source/databaseSets/databaseSet"
         skipDecider="org.apache.torque.templates.skipdecider.MapInitSkipDecider">
-      <transformer class="org.apache.torque.templates.transformer.om.mapInit.MapInitDatabaseTransformer"/>
-      <transformer class="org.apache.torque.templates.transformer.om.OMTransformer"/>
+      <transformer class="org.apache.torque.templates.transformer.om.mapInit.DatabaseMapInitTransformer"/>
       <include>*schema.xml</include>
       <exclude>id-table-schema.xml</exclude>
     </source>

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties Sat Nov 26 10:59:15 2011
@@ -77,10 +77,10 @@ torque.om.trackNew = true
 # If true, a MapInit Class is generated for each database which can be used
 # to initialize all database map classes
 torque.om.generateMapInit = false
-torque.om.mapInit.mapInitClassNamePrefix = 
-torque.om.mapInit.mapInitClassNameSuffix = MapInit
-torque.om.mapInit.baseMapInitClassNamePrefix = Base
-torque.om.mapInit.mapInitPackage = org.apache.torque.linkage
+torque.om.mapInit.databaseMapInitClassNamePrefix = 
+torque.om.mapInit.databaseMapInitClassNameSuffix = DatabaseMapInit
+torque.om.mapInit.baseDatabaseMapInitClassNamePrefix = Base
+torque.om.mapInit.databaseMapInitPackage = org.apache.torque.linkage
 
 # Settings for foreign key methods
 # Prefix and Suffix for the getter of the foreign key

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/mapBuilder.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/mapBuilder.xml?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/mapBuilder.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/mapBuilder.xml Sat Nov 26 10:59:15 2011
@@ -30,20 +30,21 @@
     <mergepoint name="classJavadoc">
       <action xsi:type="applyAction" outlet="torque.om.mapBuilder.classJavadoc"/>
     </mergepoint>
-    <mergepoint name="classNameConstant">
-      <action xsi:type="applyAction" outlet="torque.om.mapBuilder.classNameConstant"/>
+    <mergepoint name="tableConstant">
+      <action xsi:type="applyAction" outlet="torque.om.mapBuilder.tableConstant"/>
     </mergepoint>
-    <mergepoint name="dbMapField">
-      <action xsi:type="applyAction" outlet="torque.om.mapBuilder.dbMapField"/>
+    <mergepoint name="columnConstants">
+      <action xsi:type="traverseAllAction" element="column"
+         outlet="torque.om.mapBuilder.columnConstant"/>
     </mergepoint>
-    <mergepoint name="isBuilt">
-      <action xsi:type="applyAction" outlet="torque.om.mapBuilder.isBuilt"/>
+    <mergepoint name="staticInit">
+      <action xsi:type="applyAction" outlet="torque.om.mapBuilder.staticInit"/>
     </mergepoint>
-    <mergepoint name="getDatabaseMap">
-      <action xsi:type="applyAction" outlet="torque.om.mapBuilder.getDatabaseMap"/>
+    <mergepoint name="initDatabaseMap">
+      <action xsi:type="applyAction" outlet="torque.om.mapBuilder.initDatabaseMap"/>
     </mergepoint>
-    <mergepoint name="doBuild">
-      <action xsi:type="applyAction" outlet="torque.om.mapBuilder.doBuild"/>
+    <mergepoint name="getTableMap">
+      <action xsi:type="applyAction" outlet="torque.om.mapBuilder.getTableMap"/>
     </mergepoint>
     <mergepoint name="extensions"/>
   </outlet>
@@ -58,28 +59,53 @@
       path="mapBuilder/classJavadoc.vm">
   </outlet>
 
-  <outlet name="torque.om.mapBuilder.classNameConstant"
+  <outlet name="torque.om.mapBuilder.tableConstant"
       xsi:type="velocityOutlet"
-      path="mapBuilder/classNameConstant.vm">
+      path="mapBuilder/tableConstant.vm">
   </outlet>
 
-  <outlet name="torque.om.mapBuilder.dbMapField"
+  <outlet name="torque.om.mapBuilder.columnConstant"
       xsi:type="velocityOutlet"
-      path="mapBuilder/dbMapField.vm">
+      path="mapBuilder/columnConstant.vm">
   </outlet>
 
-  <outlet name="torque.om.mapBuilder.isBuilt"
+  <outlet name="torque.om.mapBuilder.staticInit"
       xsi:type="velocityOutlet"
-      path="mapBuilder/isBuilt.vm">
+      path="mapBuilder/staticInit.vm">
+    <mergepoint name="tableConstantInit">
+      <action xsi:type="applyAction" outlet="torque.om.mapBuilder.tableConstantInit"/>
+    </mergepoint>
+    <mergepoint name="columnConstantsInit">
+      <action xsi:type="traverseAllAction" element="column"
+         outlet="torque.om.mapBuilder.columnConstantInit"/>
+    </mergepoint>
+    <mergepoint name="foreignKeysInit">
+      <action xsi:type="applyAction" outlet="torque.om.mapBuilder.foreignKeysInit"/>
+    </mergepoint>
+  </outlet>
+
+  <outlet name="torque.om.mapBuilder.tableConstantInit"
+      xsi:type="velocityOutlet"
+      path="mapBuilder/tableConstantInit.vm">
   </outlet>
 
-  <outlet name="torque.om.mapBuilder.getDatabaseMap"
+  <outlet name="torque.om.mapBuilder.columnConstantInit"
+      xsi:type="velocityOutlet"
+      path="mapBuilder/columnConstantInit.vm">
+  </outlet>
+
+  <outlet name="torque.om.mapBuilder.foreignKeysInit"
+      xsi:type="velocityOutlet"
+      path="mapBuilder/foreignKeysInit.vm">
+  </outlet>
+  
+  <outlet name="torque.om.mapBuilder.initDatabaseMap"
       xsi:type="velocityOutlet"
-      path="mapBuilder/getDatabaseMap.vm">
+      path="mapBuilder/initDatabaseMap.vm">
   </outlet>
 
-  <outlet name="torque.om.mapBuilder.doBuild"
+  <outlet name="torque.om.mapBuilder.getTableMap"
       xsi:type="velocityOutlet"
-      path="mapBuilder/doBuild.vm">
+      path="mapBuilder/getTableMap.vm">
   </outlet>
 </outlets>
\ No newline at end of file

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peer.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peer.xml?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peer.xml (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/peer.xml Sat Nov 26 10:59:15 2011
@@ -70,9 +70,6 @@
     <mergepoint name="serialVersionUid">
       <action xsi:type="applyAction" outlet="torque.om.serialVersionUid"/>
     </mergepoint>
-    <mergepoint name="mapBuilderGetter">
-      <action xsi:type="applyAction" outlet="torque.om.peer.impl.base.mapBuilderGetter"/>
-    </mergepoint>
     <mergepoint name="resultSet2Objects">
       <action xsi:type="applyAction" outlet="torque.om.peer.impl.base.resultSet2Objects"/>
     </mergepoint>
@@ -158,12 +155,7 @@
       path="peer/impl/base/log.vm">
   </outlet>
 
-  <outlet name="torque.om.peer.impl.base.mapBuilderGetter"
-      xsi:type="velocityOutlet"
-      path="peer/impl/base/mapBuilderGetter.vm">
-  </outlet>
-
-  <outlet name="torque.om.peer.impl.base.resultSet2Objects"
+ <outlet name="torque.om.peer.impl.base.resultSet2Objects"
       xsi:type="velocityOutlet"
       path="peer/impl/base/resultSet2Objects.vm">
   </outlet>
@@ -301,9 +293,6 @@
     <mergepoint name="peerImplSetter">
       <action xsi:type="applyAction" outlet="torque.om.peer.base.peerImplSetter"/>
     </mergepoint>
-    <mergepoint name="mapBuilderGetter">
-      <action xsi:type="applyAction" outlet="torque.om.peer.base.mapBuilderGetter"/>
-    </mergepoint>
     <mergepoint name="numColumnConstant">
       <action xsi:type="applyAction" outlet="torque.om.peer.base.numColumnConstant"/>
     </mergepoint>
@@ -418,25 +407,6 @@
     <mergepoint name="tableDatabaseNameConstantsInit">
       <action xsi:type="applyAction" outlet="torque.om.peer.base.tableDatabaseNameConstantsInit"/>
     </mergepoint>
-    <mergepoint name="columnConstantsInit">
-      <action xsi:type="traverseAllAction"
-          element="column"
-          outlet="torque.om.peer.base.columnConstantInit"/>
-    </mergepoint>
-    <mergepoint name="mapBuilderInit">
-      <action xsi:type="applyAction"
-          outlet="torque.om.peer.base.mapBuilderInit"/>
-    </mergepoint>
-  </outlet>
-
-  <outlet name="torque.om.peer.base.columnConstantInit"
-      xsi:type="velocityOutlet"
-      path="peer/base/columnConstantInit.vm">
-  </outlet>
-
-  <outlet name="torque.om.peer.base.mapBuilderInit"
-      xsi:type="velocityOutlet"
-      path="peer/base/mapBuilderInit.vm">
   </outlet>
 
   <outlet name="torque.om.peer.base.peerImplCreator"
@@ -454,11 +424,6 @@
       path="peer/base/peerImplSetter.vm">
   </outlet>
 
-  <outlet name="torque.om.peer.base.mapBuilderGetter"
-      xsi:type="velocityOutlet"
-      path="peer/base/mapBuilderGetter.vm">
-  </outlet>
-
   <outlet name="torque.om.peer.base.numColumnConstant"
       xsi:type="velocityOutlet"
       path="peer/base/numColumnConstant.vm">

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm Sat Nov 26 10:59:15 2011
@@ -27,6 +27,7 @@
 ##
 package $baseDbObjectPackage;
 
+import java.io.Serializable;
 import java.sql.Connection;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -81,7 +82,7 @@ $torqueGen.mergepoint("classJavadoc")
   #set ($extendsBaseClass = "extends $baseClass" )
 #end
 public abstract class $baseDbObjectClassName $extendsBaseClass
-    implements Persistent##
+    implements Persistent, Serializable##
 #if ($torqueGen.booleanOption("torque.om.addIntakeRetrievable")), $torqueGen.option("torque.om.retrievableInterface")#end##
 #if ($torqueGen.booleanOption("torque.om.addGetByNameMethods")), ColumnAccessByName#end##
 

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/getByNameMethods.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/getByNameMethods.vm?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/getByNameMethods.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/getByNameMethods.vm Sat Nov 26 10:59:15 2011
@@ -230,7 +230,7 @@
   #set ( $columnFieldType = ${columnElement.getAttribute("fieldType")} )
   #set ( $javaName = ${columnElement.getAttribute("javaName")} )
   #set ( $peerColumnName = ${columnElement.getAttribute("peerColumnName")} )
-        if (${peerName}.${peerColumnName}.equals(name))
+        if (${peerName}.${peerColumnName}.getSqlExpression().equals(name))
         {
             return setByName("${javaName}", value);
         }

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/dbObject.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/dbObject.vm?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/dbObject.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/dbObject.vm Sat Nov 26 10:59:15 2011
@@ -24,11 +24,6 @@
 ## The template expects as input a "table" element from the torque schema
 ## which was processed by the OMTransformer.  
 ##
-#if ($interface)
-  #set ($interface = ", $interface")
-#else
-  #set ($interface = "")
-#end
 package $dbObjectPackage;
 
 #if ($abstract == "true")
@@ -42,7 +37,9 @@ import org.apache.torque.om.Persistent;
 $torqueGen.mergepoint("classJavadoc")
 public $abstract class $dbObjectClassName
     extends ${baseDbObjectPackage}.${baseDbObjectClassName}
-    implements Persistent$interface
+#if ($interface)
+    implements $interface
+#end
 {
 $torqueGen.mergepoint("serialVersionUid")
 $torqueGen.mergepoint("extensions")

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/columnConstant.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/columnConstant.vm?rev=1206426&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/columnConstant.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/columnConstant.vm Sat Nov 26 10:59:15 2011
@@ -0,0 +1,32 @@
+## 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.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## Creates the constants for the column names in the map builder class. 
+## 
+## This template expects the current source element to be a "table" element 
+## from the torque schema.
+## The schema needs to be processed by the OMTransformer.
+## The options and the attributes of the current source element must be set
+## as velocity variables.  
+##
+
+    /** The column map for the ${name} field */
+    public static final ColumnMap ${peerColumnName};

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/columnConstantInit.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/columnConstantInit.vm?rev=1206426&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/columnConstantInit.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/columnConstantInit.vm Sat Nov 26 10:59:15 2011
@@ -0,0 +1,81 @@
+## 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.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## Initializes the constants for the columns and registers the columns in the
+## table map in the map builder class. 
+## 
+## This template expects the current source element to be a "column" element 
+## from the torque schema.
+## The schema needs to be processed by the OMTransformer.
+## The options and the attributes of the current source element must be set
+## as velocity variables.  
+##
+#set ( $tableElement = $torqueGen.getParent() )
+#set ( $position = 1 )
+    // ------------- Column: $name --------------------
+        ${peerColumnName} = new ColumnMap("$name", TABLE);
+        ${peerColumnName}.setType($sampleObject);
+        ${peerColumnName}.setTorqueType("$type");
+        ${peerColumnName}.setUsePrimitive($primitive);
+        ${peerColumnName}.setPrimaryKey($primaryKey);
+        ${peerColumnName}.setNotNull($required);
+        ${peerColumnName}.setJavaName("$javaName");
+        ${peerColumnName}.setAutoIncrement($autoIncrement);
+        ${peerColumnName}.setProtected($protected);
+#if ($fieldType)
+        ${peerColumnName}.setJavaType( "${fieldType}" );
+#end
+#if ($description)
+        ${peerColumnName}.setDescription("${description}");
+#end
+#if ($default)
+        ${peerColumnName}.setDefault("$default");
+#end
+#if ($inheritance != "false")
+        ${peerColumnName}.setInheritance("$inheritance");
+#end
+#if ($size)
+        ${peerColumnName}.setSize($size);
+  #if ($scale)
+        ${peerColumnName}.setScale($scale);
+  #end
+#end
+#set ( $columnOptionElements = $torqueGen.getChildren("option") )
+#foreach ( $optionElement in $columnOptionElements )
+  #set ( $key = $optionElement.getAttribute("key") )
+  #set ( $value = $optionElement.getAttribute("value") )
+        ${peerColumnName}.setOption("$key", "$value");
+#end
+#if ($inheritance != "false")
+        ${peerColumnName}.setUseInheritance(true);
+        InheritanceMap iMap = null;
+  #set ( $inheritanceElements = $torqueGen.getChildren("inheritance"))
+  #foreach ($inheritanceElement in $inheritanceElements)
+    #set ( $key = $inheritanceElement.getAttribute("key") )
+    #set ( $class = $inheritanceElement.getAttribute("class") )
+    #set ( $extends = $inheritanceElement.getAttribute("extends") )
+        iMap = new InheritanceMap(${peerColumnName},"$key","$class","$extends");
+        ${peerColumnName}.addInheritanceMap(iMap);
+  #end
+#end
+#set ($position = ${torqueGen.getSourceElement().getPreceding("column").size()} + 1)
+        ${peerColumnName}.setPosition($position);
+        TABLE.addColumn(${peerColumnName});

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/foreignKeysInit.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/foreignKeysInit.vm?rev=1206426&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/foreignKeysInit.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/foreignKeysInit.vm Sat Nov 26 10:59:15 2011
@@ -0,0 +1,68 @@
+## 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.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## Initializes the foreign keys for the table map in the map builder class.
+## 
+## This template expects the current source element to be a "table" element 
+## from the torque schema.
+## The options and the attributes of the current source element must be set
+## as velocity variables.  
+##
+#set ( $foreignKeyElements = $torqueGen.getChildren("foreign-key") )
+#if (!$foreignKeyElements.isEmpty())
+
+    // ------------- Foreign keys --------------------
+        ForeignKeyMap foreignKeyMap;
+        TableMap foreignTable;
+        String foreignTableName; 
+  #foreach ($foreignKeyElement in $foreignKeyElements)
+    #set($foreignTableName = $foreignKeyElement.getAttribute("foreignTable"))
+        foreignTableName = "${foreignTableName}"; 
+        foreignTable = dbMap.getTable(foreignTableName);
+        if (foreignTable == null)
+        {
+            foreignKeyMap = new ForeignKeyMap(TABLE, foreignTableName);
+    #set ( $referenceElements = $foreignKeyElement.getChildren("reference") )
+    #foreach ($referenceElement in $referenceElements)
+      #set($localColumn = $referenceElement.getAttribute("local"))
+      #set($foreignColumn = $referenceElement.getAttribute("foreign"))
+            foreignKeyMap.addColumns(new ForeignKeyMap.ColumnPair(
+                foreignKeyMap,
+                TABLE.getColumn("${localColumn}"),
+                "${foreignColumn}"));
+    #end
+        }
+        else
+        {
+            foreignKeyMap = new ForeignKeyMap(TABLE, foreignTable);
+    #foreach ($referenceElement in $referenceElements)
+      #set($localColumn = $referenceElement.getAttribute("local"))
+      #set($foreignColumn = $referenceElement.getAttribute("foreign"))
+            foreignKeyMap.addColumns(new ForeignKeyMap.ColumnPair(
+                foreignKeyMap,
+                TABLE.getColumn("${localColumn}"),
+                foreignTable.getColumn("${foreignColumn}")));
+    #end
+        }
+        TABLE.addForeignKey(foreignKeyMap);
+  #end
+#end
+

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/getTableMap.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/getTableMap.vm?rev=1206426&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/getTableMap.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/getTableMap.vm Sat Nov 26 10:59:15 2011
@@ -0,0 +1,35 @@
+## 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.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## Creates the getTableMap method for a map builder object. 
+## 
+## This template expects the current source element to be a "table" element 
+## from the torque schema.
+## The schema needs to be processed by the OMTransformer.
+## The options and the attributes of the current source element must be set
+## as velocity variables.  
+##
+#set ( $databaseElement = $torqueGen.getParent() )
+#set ( $databaseName = $databaseElement.getAttribute("name") )
+    public static TableMap getTableMap()
+    {
+        return TABLE;
+    }

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/imports.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/imports.vm?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/imports.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/imports.vm Sat Nov 26 10:59:15 2011
@@ -27,19 +27,20 @@
 ## The options and the attributes of the current source element must be set
 ## as velocity variables.  
 ##
+import static org.apache.torque.adapter.DB.AUTO_INCREMENT;
+import static org.apache.torque.adapter.DB.ID_BROKER;
+import static org.apache.torque.adapter.DB.SEQUENCE;
+
 import java.util.Date;
 import java.util.List;
 import java.util.ArrayList;
 
 import org.apache.torque.Torque;
-import org.apache.torque.TorqueException;
 #if ($table.IdMethod == "native")
 import org.apache.torque.adapter.DB;
 #end
-import org.apache.torque.map.MapBuilder;
 import org.apache.torque.map.DatabaseMap;
 import org.apache.torque.map.TableMap;
 import org.apache.torque.map.ColumnMap;
 import org.apache.torque.map.ForeignKeyMap;
 import org.apache.torque.map.InheritanceMap;
-

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/initDatabaseMap.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/initDatabaseMap.vm?rev=1206426&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/initDatabaseMap.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/initDatabaseMap.vm Sat Nov 26 10:59:15 2011
@@ -0,0 +1,47 @@
+## 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.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## Creates the initDatabaseMap method for a map builder object. 
+## 
+## This template expects the current source element to be a "table" element 
+## from the torque schema.
+## The schema needs to be processed by the OMTransformer.
+## The options and the attributes of the current source element must be set
+## as velocity variables.  
+##
+#set ( $databaseElement = $torqueGen.getParent() )
+#set ( $databaseName = $databaseElement.getAttribute("name") )
+#set ( $baseDatabaseMapInitClassName = $databaseElement.getAttribute("baseDatabaseMapInitClassName") )
+#set ( $databaseOptionElements = $databaseElement.getChildren("option") )
+    public static void initDatabaseMap()
+    {
+        ${baseDatabaseMapInitClassName}.init();
+## TODO the following needs not be executed for every table
+## but it causes no harm
+#if (${databaseOptionElements.size()} > 0)
+        DatabaseMap databaseMap = Torque.getDatabaseMap("$databaseName");
+#end
+#foreach($databaseOptionElement in $databaseOptionElements)
+  #set ( $key = $databaseOptionElement.getAttribute("key") )
+  #set ( $value = $databaseOptionElement.getAttribute("value") )
+        databaseMap.setOption("$key", "$value");
+#end
+    }

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/mapBuilder.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/mapBuilder.vm?rev=1206426&r1=1206425&r2=1206426&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/mapBuilder.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/mapBuilder.vm Sat Nov 26 10:59:15 2011
@@ -28,14 +28,16 @@
 ## as velocity variables.  
 ##
 package ${mapBuilderPackage};
+
 $torqueGen.mergepoint("imports")
+
 $torqueGen.mergepoint("classJavadoc")
-public class ${mapBuilderClassName} implements MapBuilder
+public class ${mapBuilderClassName}
 {
-$torqueGen.mergepoint("classNameConstant")
-$torqueGen.mergepoint("dbMapField")
-$torqueGen.mergepoint("isBuilt")
-$torqueGen.mergepoint("getDatabaseMap")
-$torqueGen.mergepoint("doBuild")
+$torqueGen.mergepoint("tableConstant")
+$torqueGen.mergepoint("columnConstants")
+$torqueGen.mergepoint("staticInit")
+$torqueGen.mergepoint("getTableMap")
+$torqueGen.mergepoint("initDatabaseMap")
 $torqueGen.mergepoint("extensions")
 }

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/staticInit.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/staticInit.vm?rev=1206426&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/staticInit.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/staticInit.vm Sat Nov 26 10:59:15 2011
@@ -0,0 +1,45 @@
+## 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.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## Creates the static initializer for a map builder object. 
+## 
+## This template expects the current source element to be a "table" element 
+## from the torque schema.
+## The schema needs to be processed by the OMTransformer.
+## The options and the attributes of the current source element must be set
+## as velocity variables.  
+##
+#set ( $databaseElement = $torqueGen.getParent() )
+#set ( $databaseName = $databaseElement.getAttribute("name") )
+#set ( $databaseOptionElements = $databaseElement.getChildren("option") )
+    static
+    {
+        DatabaseMap dbMap = Torque.getDatabaseMap("$databaseName");
+        if (dbMap.getTable("$name") == null)
+        {
+            dbMap.addTable("$name");
+        }
+
+$torqueGen.mergepoint("tableConstantInit")
+$torqueGen.mergepoint("columnConstantsInit")
+$torqueGen.mergepoint("foreignKeysInit")
+        initDatabaseMap();
+    }

Added: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/tableConstant.vm
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/tableConstant.vm?rev=1206426&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/tableConstant.vm (added)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/mapBuilder/tableConstant.vm Sat Nov 26 10:59:15 2011
@@ -0,0 +1,26 @@
+## 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.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26 Aug 2005) tfischer $
+##
+## Generates the constants for the table map in the map builder class
+## This template expects no input.  
+##
+     /** the table map for this class */
+    public static final TableMap TABLE;
\ No newline at end of file



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