db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject cvs commit: db-torque/src/java/org/apache/torque/avalon TorqueComponent.java
Date Sat, 02 Jul 2005 07:22:34 GMT
tfischer    2005/07/02 00:22:34

  Modified:    src/java/org/apache/torque/dsfactory
                        PerUserPoolDataSourceFactory.java
                        DataSourceFactory.java
                        SharedPoolDataSourceFactory.java
                        JndiDataSourceFactory.java
               src/java/org/apache/torque TorqueInstance.java Torque.java
               xdocs    changes.xml
               src/java/org/apache/torque/avalon TorqueComponent.java
  Log:
  Torque.shutdown() now closes the datasourcee initialized by Torque, except the Datasources
obtained via a JndiDataSourceFactory.
  
  Revision  Changes    Path
  1.4       +21 -2     db-torque/src/java/org/apache/torque/dsfactory/PerUserPoolDataSourceFactory.java
  
  Index: PerUserPoolDataSourceFactory.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/dsfactory/PerUserPoolDataSourceFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PerUserPoolDataSourceFactory.java	31 Jan 2005 19:43:56 -0000	1.3
  +++ PerUserPoolDataSourceFactory.java	2 Jul 2005 07:22:33 -0000	1.4
  @@ -46,7 +46,7 @@
               = LogFactory.getLog(PerUserPoolDataSourceFactory.class);
   
       /** The wrapped <code>DataSource</code>. */
  -    private DataSource ds;
  +    private PerUserPoolDataSource ds;
   
       /**
        * @see org.apache.torque.dsfactory.DataSourceFactory#getDataSource
  @@ -98,4 +98,23 @@
           applyConfiguration(conf, ds);
           return ds;
       }
  +    
  +    /**
  +     * Closes the pool associated with this factory and releases it.
  +     * @throws TorqueException if the pool cannot be closed properly
  +     */
  +    public void close() throws TorqueException
  +    {
  +        try 
  +        {
  +            ds.close();
  +        }
  +        catch (Exception e)
  +        {
  +            log.error("Exception caught during close()", e);
  +            throw new TorqueException(e);
  +        }
  +        ds = null;
  +    }
  +
   }
  
  
  
  1.5       +16 -1     db-torque/src/java/org/apache/torque/dsfactory/DataSourceFactory.java
  
  Index: DataSourceFactory.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/dsfactory/DataSourceFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DataSourceFactory.java	31 Jan 2005 19:43:56 -0000	1.4
  +++ DataSourceFactory.java	2 Jul 2005 07:22:33 -0000	1.5
  @@ -61,4 +61,19 @@
        */
       String getSchema();
   
  +    /**
  +     * A hook which is called when the resources of the associated DataSource 
  +     * can be released.
  +     * After close() is called, the other methods may not work any more 
  +     * (e.g. getDataSource() might return null).
  +     * It is not guaranteed that this method does anything. For example, 
  +     * we do not want to close connections retrieved via JNDI, so the
  +     * JndiDataSouurceFactory does not close these connections  
  +     * 
  +     * @throws TorqueException Any exceptions caught during processing will be
  +     *         rethrown wrapped into a TorqueException.
  +     */
  +    void close()
  +        throws TorqueException;
  +    
   }
  
  
  
  1.4       +21 -2     db-torque/src/java/org/apache/torque/dsfactory/SharedPoolDataSourceFactory.java
  
  Index: SharedPoolDataSourceFactory.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/dsfactory/SharedPoolDataSourceFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SharedPoolDataSourceFactory.java	31 Jan 2005 19:43:56 -0000	1.3
  +++ SharedPoolDataSourceFactory.java	2 Jul 2005 07:22:33 -0000	1.4
  @@ -46,7 +46,7 @@
               = LogFactory.getLog(SharedPoolDataSourceFactory.class);
   
       /** The wrapped <code>DataSource</code>. */
  -    private DataSource ds;
  +    private SharedPoolDataSource ds;
   
       /**
        * @see org.apache.torque.dsfactory.DataSourceFactory#getDataSource
  @@ -98,4 +98,23 @@
           applyConfiguration(conf, ds);
           return ds;
       }
  +    
  +    
  +    /**
  +     * Closes the pool associated with this factory and releases it.
  +     * @throws TorqueException if the pool cannot be closed properly
  +     */
  +    public void close() throws TorqueException
  +    {
  +        try 
  +        {
  +        	ds.close();
  +        }
  +        catch (Exception e)
  +        {
  +            log.error("Exception caught during close()", e);
  +            throw new TorqueException(e);
  +        }
  +        ds = null;
  +    }
   }
  
  
  
  1.9       +10 -1     db-torque/src/java/org/apache/torque/dsfactory/JndiDataSourceFactory.java
  
  Index: JndiDataSourceFactory.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/dsfactory/JndiDataSourceFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JndiDataSourceFactory.java	31 Jan 2005 19:43:56 -0000	1.8
  +++ JndiDataSourceFactory.java	2 Jul 2005 07:22:33 -0000	1.9
  @@ -226,6 +226,15 @@
       }
   
       /**
  +     * Does nothing. We do not want to close a dataSource retrieved from Jndi,
  +     * because other applications might use it as well.
  +     */
  +    public void close()
  +    {
  +        // do nothing
  +    }
  +    
  +    /**
        *
        * @param ctx the context
        * @throws NamingException
  
  
  
  1.12      +39 -3     db-torque/src/java/org/apache/torque/TorqueInstance.java
  
  Index: TorqueInstance.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/TorqueInstance.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TorqueInstance.java	12 Mar 2005 20:14:50 -0000	1.11
  +++ TorqueInstance.java	2 Jul 2005 07:22:33 -0000	1.12
  @@ -502,9 +502,14 @@
        * Shuts down the service.
        *
        * This method halts the IDBroker's daemon thread in all of
  -     * the DatabaseMap's.
  +     * the DatabaseMap's. It also closes all SharedPoolDataSourceFactories
  +     * and PerUserPoolDataSourceFactories initialized by Torque.
  +     * @exception TorqueException if a DataSourceFactory could not be closed 
  +     *            cleanly. Only the first exception is rethrown, any following 
  +     *            exceptions are logged but ignored.
        */
  -    public synchronized void shutdown()
  +    public synchronized void shutdown() 
  +        throws TorqueException
       {
           if (dbMaps != null)
           {
  @@ -518,6 +523,37 @@
                   }
               }
           }
  +        TorqueException exception = null;
  +        for (Iterator it = dsFactoryMap.keySet().iterator(); it.hasNext();)
  +        {
  +            Object dsfKey = it.next();
  +            DataSourceFactory dsf 
  +                    = (DataSourceFactory) dsFactoryMap.get(dsfKey);
  +            try 
  +            {
  +                // Database "default" is just a reference to another database.
  +                // We must not close it explicitly.
  +                if (!DEFAULT_NAME.equals(dsfKey))
  +                {
  +                	dsf.close();
  +                }
  +                it.remove();
  +            }
  +            catch (TorqueException e)
  +            {
  +                log.error("Error while closing the DataSourceFactory "
  +                        + dsfKey, 
  +                        e);
  +                if (exception == null)
  +                {
  +                	exception = e;
  +                }
  +            }
  +        }
  +        if (exception != null)
  +        {
  +            throw exception;
  +        }
           resetConfiguration();
       }
   
  
  
  
  1.95      +8 -3      db-torque/src/java/org/apache/torque/Torque.java
  
  Index: Torque.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/Torque.java,v
  retrieving revision 1.94
  retrieving revision 1.95
  diff -u -r1.94 -r1.95
  --- Torque.java	31 Jan 2005 19:43:58 -0000	1.94
  +++ Torque.java	2 Jul 2005 07:22:33 -0000	1.95
  @@ -30,7 +30,7 @@
    * <br/>
    *
    * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
  - * @author <a href="mailto:magnus@handtolvur.is">Magns r Torfason</a>
  + * @author <a href="mailto:magnus@handtolvur.is">Magn�s ��r Torfason</a>
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
    * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
  @@ -176,9 +176,14 @@
        * Shuts down the service.
        *
        * This method halts the IDBroker's daemon thread in all of
  -     * the DatabaseMap's.
  +     * the DatabaseMap's. It also closes all SharedPoolDataSourceFactories
  +     * and PerUserPoolDataSourceFactories initialized by Torque.
  +     * @exception TorqueException if a DataSourceFactory could not be closed 
  +     *            cleanly. Only the first exception is rethrown, any following 
  +     *            exceptions are logged but ignored.
        */
       public static void shutdown()
  +        throws TorqueException
       {
           getInstance().shutdown();
       }
  
  
  
  1.168     +4 -0      db-torque/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/db-torque/xdocs/changes.xml,v
  retrieving revision 1.167
  retrieving revision 1.168
  diff -u -r1.167 -r1.168
  --- changes.xml	27 Jun 2005 21:34:10 -0000	1.167
  +++ changes.xml	2 Jul 2005 07:22:33 -0000	1.168
  @@ -28,6 +28,10 @@
     <body>
   
     <release version="3.2-dev" date="in CVS">
  +    <action type="fix" dev="tfischer" issue="TRQS294">
  +      Torque.shutdown() now closes the datasourcee initialized by Torque,
  +      except the Datasource obtained via a JndiDataSourceFactory.
  +    </action>
       <action type="add" dev="tfischer" issue="TRQS306">
         Added a "protected" attribute to the column. If set to true, the getters
         and setters of a column are protected rather than public.
  
  
  
  1.10      +9 -4      db-torque/src/java/org/apache/torque/avalon/TorqueComponent.java
  
  Index: TorqueComponent.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/avalon/TorqueComponent.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TorqueComponent.java	31 Jan 2005 19:43:58 -0000	1.9
  +++ TorqueComponent.java	2 Jul 2005 07:22:34 -0000	1.10
  @@ -29,9 +29,7 @@
   import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.thread.ThreadSafe;
  -
   import org.apache.commons.lang.StringUtils;
  -
   import org.apache.torque.TorqueException;
   import org.apache.torque.TorqueInstance;
   import org.apache.torque.adapter.DB;
  @@ -185,7 +183,14 @@
       public void stop()
       {
           getLogger().debug("stop()");
  -        getTorque().shutdown();
  +        try 
  +        {
  +        	getTorque().shutdown();
  +        }
  +        catch (Exception e)
  +        {
  +            getLogger().error("Error while stopping Torque", e);
  +        }
       }
   
   
  
  
  

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