henning     2002/07/07 04:35:34

  Modified:    src/java/org/apache/torque Torque.java
  Log:
  The mapping of the default database onto another, configured
  data source didn't seem to work right; if you configured the
  "bookstore" example like this:
  
  -- cut --
  torque.database.bookstore.adapter = mysql
  
  
torque.dsfactory.bookstore.factory=org.apache.torque.dsfactory.TorqueDataSourceFactory
  
  torque.dsfactory.bookstore.connection.driver = org.gjt.mm.mysql.Driver
  torque.dsfactory.bookstore.connection.url = jdbc:mysql://localhost:3306/bookstore
  torque.dsfactory.bookstore.connection.user = root
  torque.dsfactory.bookstore.connection.password =
  
  torque.dsfactory.bookstore.pool.maxExpiryTime=3600000
  torque.dsfactory.bookstore.pool.connectionWaitTimeout=10000
  -- cut --
  
  and a mapping for the default onto it:
  
  -- cut --
  database.default = bookstore
  -- cut --
  
  then requesting data from the "default" data source resulted in a
  NullPointerException with "There was no DataSourceFactory configured
  for the connection default" message.
  
  This patch fixes this.
  
  Revision  Changes    Path
  1.65      +26 -2     jakarta-turbine-torque/src/java/org/apache/torque/Torque.java
  
  Index: Torque.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/Torque.java,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- Torque.java       22 Jun 2002 22:17:55 -0000      1.64
  +++ Torque.java       7 Jul 2002 11:35:34 -0000       1.65
  @@ -313,7 +313,31 @@
                   throw new TorqueException(e);
               }
           }
  -    }
  +
  +        //
  +        // 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))
  +        {
  +            category.debug("Adding a dummy entry for "
  +                           + DEFAULT_NAME + ", mapped onto " + defaultDB);
  +            dsFactoryMap.put(DEFAULT_NAME, dsFactoryMap.get(defaultDB));
  +        }
  +}
   
       /**
        * configure torque
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to