Return-Path: Delivered-To: apmail-db-torque-dev-archive@www.apache.org Received: (qmail 56190 invoked from network); 2 Jul 2005 07:22:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 Jul 2005 07:22:38 -0000 Received: (qmail 4242 invoked by uid 500); 2 Jul 2005 07:22:38 -0000 Delivered-To: apmail-db-torque-dev-archive@db.apache.org Received: (qmail 4087 invoked by uid 500); 2 Jul 2005 07:22:36 -0000 Mailing-List: contact torque-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Apache Torque Developers List" Reply-To: "Apache Torque Developers List" Delivered-To: mailing list torque-dev@db.apache.org Received: (qmail 4074 invoked by uid 500); 2 Jul 2005 07:22:36 -0000 Received: (qmail 4070 invoked by uid 99); 2 Jul 2005 07:22:36 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 02 Jul 2005 00:22:36 -0700 Received: (qmail 56186 invoked by uid 1977); 2 Jul 2005 07:22:34 -0000 Date: 2 Jul 2005 07:22:34 -0000 Message-ID: <20050702072234.56185.qmail@minotaur.apache.org> From: tfischer@apache.org To: db-torque-cvs@apache.org Subject: cvs commit: db-torque/src/java/org/apache/torque/avalon TorqueComponent.java X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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 DataSource. */ - 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 DataSource. */ - 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 @@ *
* * @author Daniel Rall - * @author Magn�s ��r Torfason + * @author Magn�s ��r Torfason * @author Jason van Zyl * @author Rafal Krzewski * @author Martin Poeschl @@ -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 @@ + + Torque.shutdown() now closes the datasourcee initialized by Torque, + except the Datasource obtained via a JndiDataSourceFactory. + 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