You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2005/10/19 22:36:12 UTC

svn commit: r326694 - in /db/torque/runtime/trunk: src/java/org/apache/torque/TorqueInstance.java src/test/TurbineResources.properties src/test/org/apache/torque/TorqueInstanceTest.java xdocs/changes.xml

Author: tfischer
Date: Wed Oct 19 13:36:03 2005
New Revision: 326694

URL: http://svn.apache.org/viewcvs?rev=326694&view=rev
Log:
The Data Source Key "default" is now again mapped to the default data source.
A test case is added to check that the behaviouris retained in the future.
Fixes TRQS322.

Added:
    db/torque/runtime/trunk/src/test/org/apache/torque/TorqueInstanceTest.java   (with props)
Modified:
    db/torque/runtime/trunk/src/java/org/apache/torque/TorqueInstance.java
    db/torque/runtime/trunk/src/test/TurbineResources.properties
    db/torque/runtime/trunk/xdocs/changes.xml

Modified: db/torque/runtime/trunk/src/java/org/apache/torque/TorqueInstance.java
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/src/java/org/apache/torque/TorqueInstance.java?rev=326694&r1=326693&r2=326694&view=diff
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/TorqueInstance.java (original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/TorqueInstance.java Wed Oct 19 13:36:03 2005
@@ -63,6 +63,9 @@
     /** Logging */
     private static Log log = LogFactory.getLog(TorqueInstance.class);
 
+    /** A constant for <code>default</code>. */
+    private static final String DEFAULT_NAME = "default";
+
     /** The db name that is specified as the default in the property file */
     private String defaultDBName = null;
 
@@ -83,6 +86,14 @@
 
     /** flag to set to true once this class has been initialized */
     private boolean isInit = false;
+    
+    /** 
+     * a flag which indicates whether the DataSourceFactory with the key
+     * <code>DEFAULT</code> is a reference to another
+     * DataSourceFactory. This is important to know when closing the 
+     * DataSourceFactories on shutdown(); 
+     */ 
+    private boolean defaultDSFIsReference = false;
 
     /**
      * Store mapbuilder classnames for peers that have been referenced prior
@@ -323,6 +334,30 @@
             log.error(error);
             throw new TorqueException(error);
         }
+        
+        // As there might be a default database configured
+        // to map "default" onto an existing datasource, we
+        // must check, whether there _is_ really an entry for
+        // the "default" in the dsFactoryMap or not. If it is
+        // not, then add a dummy entry for the "default"
+        //
+        // Without this, you can't actually access the "default"
+        // data-source, even if you have an entry like
+        //
+        // database.default = bookstore
+        //
+        // in your Torque.properties
+        //
+        String defaultDB = getDefaultDB();
+
+        if (dsFactoryMap.get(DEFAULT_NAME) == null
+                && !defaultDB.equals(DEFAULT_NAME))
+        {
+            log.debug("Adding a dummy entry for "
+                    + DEFAULT_NAME + ", mapped onto " + defaultDB);
+            dsFactoryMap.put(DEFAULT_NAME, dsFactoryMap.get(defaultDB));
+            this.defaultDSFIsReference = true;
+        }
     }
 
     /**
@@ -568,6 +603,16 @@
         for (Iterator it = dsFactoryMap.keySet().iterator(); it.hasNext();)
         {
             Object dsfKey = it.next();
+
+            if (DEFAULT_NAME.equals(dsfKey) && defaultDSFIsReference)
+            {
+                // the entry with the key DEFAULT_NAME
+                // is just a reference to aynother entry. Do not close because
+                // this leads to closing the same DataSourceFactory twice.
+                it.remove();
+                break;
+            }
+
             DataSourceFactory dsf
                     = (DataSourceFactory) dsFactoryMap.get(dsfKey);
             try

Modified: db/torque/runtime/trunk/src/test/TurbineResources.properties
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/src/test/TurbineResources.properties?rev=326694&r1=326693&r2=326694&view=diff
==============================================================================
--- db/torque/runtime/trunk/src/test/TurbineResources.properties (original)
+++ db/torque/runtime/trunk/src/test/TurbineResources.properties Wed Oct 19 13:36:03 2005
@@ -69,9 +69,9 @@
 #
 # -------------------------------------------------------------------
 
-torque.database.default = default
-torque.database.default.adapter=mysql
-torque.dsfactory.default.factory= org.apache.torque.dsfactory.SharedPoolDataSourceFactory
+torque.database.default = turbine
+torque.database.turbine.adapter=mysql
+torque.dsfactory.turbine.factory= org.apache.torque.dsfactory.SharedPoolDataSourceFactory
 torque.idbroker.prefetch=false
 
 

Added: db/torque/runtime/trunk/src/test/org/apache/torque/TorqueInstanceTest.java
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/src/test/org/apache/torque/TorqueInstanceTest.java?rev=326694&view=auto
==============================================================================
--- db/torque/runtime/trunk/src/test/org/apache/torque/TorqueInstanceTest.java (added)
+++ db/torque/runtime/trunk/src/test/org/apache/torque/TorqueInstanceTest.java Wed Oct 19 13:36:03 2005
@@ -0,0 +1,50 @@
+package org.apache.torque;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/**
+ * Tests the TorqueInstance Class.
+ *
+ * @author <a href="mailto:fischer@seitenbau.de">Thomas Fischer</a>
+ * @version $Id$
+ */
+public class TorqueInstanceTest extends BaseTestCase
+{  
+    /** The name of the "default" dataSourceFactory" as used by Turbine */
+    private static final String DEFAULT_NAME = "default";
+    
+    /**
+     * Creates a new instance.
+     *
+     * @param name the name of the test case to run
+     */
+    public TorqueInstanceTest(String name)
+    {
+        super(name);
+    }
+    
+    /**
+     * Checks whether a DataSourceFactory with the name 
+     * <code>DEFAULT_NAME</code> is defined (TRQS 322)
+     * @throws Exception if an error occurs during the Test
+     */
+    public void testDefaultDataSourceFactory() throws Exception
+    {
+        assertNotNull(Torque.getInstance().getDataSourceFactory(DEFAULT_NAME));
+    }
+}

Propchange: db/torque/runtime/trunk/src/test/org/apache/torque/TorqueInstanceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: db/torque/runtime/trunk/src/test/org/apache/torque/TorqueInstanceTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: db/torque/runtime/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/xdocs/changes.xml?rev=326694&r1=326693&r2=326694&view=diff
==============================================================================
--- db/torque/runtime/trunk/xdocs/changes.xml (original)
+++ db/torque/runtime/trunk/xdocs/changes.xml Wed Oct 19 13:36:03 2005
@@ -26,6 +26,11 @@
   <body>
 
   <release version="3.2-rc3-dev" date="in SVN">
+    <action type="fix" dev="tfischer" issue="TRQS322">
+      The DataSourceFactory with the name "default" is created 
+      automatically again. This was removed when fixing TRQS308,
+      but is required by Turbine.
+    </action>
     <action type="add" dev="tfischer" issue="TRQS323">
       The size and scale attributes from the schema.xml are now used
       to fill the fields size and scale in the column objects



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org