CVS: fulcrum/db/src/java/org/apache/fulcrum/db DefaultDatabaseService.java,1.1,1.2 DatabaseService.java,1.2,1.3

[email protected] Tue, 6 May 2003 12:07:02 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/fulcrum/db/src/java/org/apache/fulcrum/db
In directory eng.werken.com:/tmp/cvs-serv14801/db/src/java/org/apache/fulcrum/db

Modified Files:
	DefaultDatabaseService.java DatabaseService.java 
Log Message:
No more seperate torque properties files.  Load them in from
<properties>
<property name="somename" value="blah"/>
</properties>

in the configuration..

Also this is NOT deprecated.  Torque hasn't given me any avalon
service to replace this yet, so, until then!

Index: DefaultDatabaseService.java
===================================================================
RCS file: /cvsroot/plexus/fulcrum/db/src/java/org/apache/fulcrum/db/DefaultDatabaseService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- DefaultDatabaseService.java	29 Mar 2003 15:55:32 -0000	1.1
+++ DefaultDatabaseService.java	6 May 2003 17:06:55 -0000	1.2
@@ -1,267 +1,274 @@
-package org.apache.fulcrum.db;
-
-/* ====================================================================
- * The Apache Software License, Version 1.1
- *
- * Copyright (c) 2001 The Apache Software Foundation.  All rights
- * reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in
- *    the documentation and/or other materials provided with the
- *    distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- *    if any, must include the following acknowledgment:
- *       "This product includes software developed by the
- *        Apache Software Foundation (http://www.apache.org/)."
- *    Alternately, this acknowledgment may appear in the software itself,
- *    if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Apache" and "Apache Software Foundation" and
- *    "Apache Turbine" must not be used to endorse or promote products
- *    derived from this software without prior written permission. For
- *    written permission, please contact [email protected].
- *
- * 5. Products derived from this software may not be called "Apache",
- *    "Apache Turbine", nor may "Apache" appear in their name, without
- *    prior written permission of the Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation.  For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- */
-
-import java.sql.Connection;
-
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.activity.Startable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.log4j.Category;
-import org.apache.torque.Torque;
-import org.apache.torque.adapter.DB;
-import org.apache.torque.map.DatabaseMap;
-
-/**
- * Fulcrum's default implementation of {@link DatabaseService}.
- *
- * @author <a href="mailto:[email protected]">Jason van Zyl</a>
- * @version $Id$
- * @deprecated you should use org.apache.torque.Torque
- */
-public class DefaultDatabaseService
-    extends AbstractLogEnabled
-    implements DatabaseService, Initializable, Configurable, Startable
-{
-    String propertiesFile;
-    
-    public static final String PROPERTIES_FILE = "torque-properties";
-        
-    /**
-     * Initializes the service by setting up Torque.
-     */
-    public void initialize()
-        throws Exception
-    {
-        try
-        {
-            Torque.init( propertiesFile );
-        }
-        catch (Exception e)
-        {
-            throw new Exception("Can't initialize Torque!", e);
-        }
-    }
-
-    /**
-     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
-     */
-    public void configure(Configuration configuration)
-        throws ConfigurationException
-    {
-        propertiesFile = configuration.getAttribute( PROPERTIES_FILE );
-    }
-
-    /**
-     * The log4j category used for logging db service events.
-     *
-     * @return a <code>Category</code> value
-     */
-    public Category getCategory()
-    {
-        return Category.getInstance(getClass().getName());
-    }
-
-    /**
-     * Returns the default database map information.
-     *
-     * @return A DatabaseMap.
-     * @throws ServiceException Any exceptions caught during procssing will be
-     *         rethrown wrapped into a ServiceException.
-     */
-    public DatabaseMap getDatabaseMap()
-        throws Exception
-    {
-        return Torque.getDatabaseMap();
-    }
-
-    /**
-     * Returns the database map information. Name relates to the name
-     * of the connection pool to associate with the map.
-     *
-     * @param name The name of the <code>DatabaseMap</code> to
-     * retrieve.
-     * @return The named <code>DatabaseMap</code>.
-     * @throws ServiceException Any exceptions caught during procssing will be
-     *         rethrown wrapped into a ServiceException.
-     */
-    public DatabaseMap getDatabaseMap(String name)
-        throws Exception
-    {
-        return Torque.getDatabaseMap(name);
-    }
-
-    /**
-     * This method returns a Connection from the default pool.
-     *
-     * @return The requested connection.
-     * @throws ServiceException Any exceptions caught during processing will be
-     *         rethrown wrapped into a ServiceException.
-     */
-    public Connection getConnection()
-        throws Exception
-    {
-        return Torque.getConnection();
-    }
-
-    /**
-     * This method returns a Connection from the pool with the
-     * specified name.  The pool must either have been registered
-     * with the {@link #registerPool(String,String,String,String,String)}
-     * method, or be specified in the property file using the
-     * following syntax:
-     *
-     * <pre>
-     * database.[name].driver
-     * database.[name].url
-     * database.[name].username
-     * database.[name].password
-     * </pre>
-     *
-     * @param name The name of the pool to get a connection from.
-     * @return     The requested connection.
-     * @throws ServiceException Any exceptions caught during processing will be
-     *         rethrown wrapped into a ServiceException.
-     */
-    public Connection getConnection(String name)
-        throws Exception
-    {
-        // The getPool method ensures the validity of the returned pool.
-        return Torque.getConnection(name);
-    }
-
-    /**
-     * Release a connection back to the database pool.  <code>null</code>
-     * references are ignored.
-     *
-     * @throws ServiceException Any exceptions caught during processing will be
-     *         rethrown wrapped into a ServiceException.
-     * @exception Exception A generic exception.
-     */
-    public void releaseConnection(Connection dbconn)
-        throws Exception
-    {
-        Torque.closeConnection(dbconn);
-    }
-
-
-    /**
-     * Returns the database adapter for the default connection pool.
-     *
-     * @return The database adapter.
-     * @throws ServiceException Any exceptions caught during processing will be
-     *         rethrown wrapped into a ServiceException.
-     */
-    public DB getDB()
-        throws Exception
-    {
-        return Torque.getDB(getDefaultDB());
-    }
-
-    /**
-     * Returns database adapter for a specific connection pool.
-     *
-     * @param name A pool name.
-     * @return     The corresponding database adapter.
-     * @throws ServiceException Any exceptions caught during processing will be
-     *         rethrown wrapped into a ServiceException.
-     */
-    public DB getDB(String name)
-        throws Exception
-    {
-        return Torque.getDB(name);
-    }
-
-    public String getDefaultDB()
-    {
-        return Torque.getDefaultDB();
-    }
-
-    /**
-     * This method is gone in Torque HEAD as it is a duplicate
-     * for getDefaultDB, but will stay here marked as deprecated
-     * for a little while.
-     *
-     * @deprecated
-     */
-    public String getDefaultMap()
-    {
-        return Torque.getDefaultDB();
-    }
-
-    /**
-     * @see org.apache.avalon.framework.activity.Startable#start()
-     */
-    public void start() throws Exception
-    {
-        // do nothing
-    }
-
-    /**
-     * Shuts down the service.
-     *
-     * This method halts the IDBroker's daemon thread in all of
-     * the DatabaseMap's.
-     * 
-     * @see org.apache.avalon.framework.activity.Startable#stop()
-     */
-    public void stop() throws Exception
-    {
-        Torque.shutdown();
-    }
-}
+package org.apache.fulcrum.db;
+
+/* ====================================================================
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" and
+ *    "Apache Turbine" must not be used to endorse or promote products
+ *    derived from this software without prior written permission. For
+ *    written permission, please contact [email protected].
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    "Apache Turbine", nor may "Apache" appear in their name, without
+ *    prior written permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+import java.sql.Connection;
+import java.util.Properties;
+
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.activity.Startable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.commons.configuration.ConfigurationConverter;
+import org.apache.log4j.Category;
+import org.apache.torque.Torque;
+import org.apache.torque.adapter.DB;
+import org.apache.torque.map.DatabaseMap;
+
+/**
+ * Fulcrum's default implementation of {@link DatabaseService}.
+ *
+ * @author <a href="mailto:[email protected]">Jason van Zyl</a>
+ * @version $Id$
+ * @deprecated you should use org.apache.torque.Torque
+ */
+public class DefaultDatabaseService
+    extends AbstractLogEnabled
+    implements DatabaseService, Initializable, Configurable, Startable
+{
+    private Properties properties;
+    
+    /**
+     * Initializes the service by setting up Torque.
+     */
+    public void initialize()
+        throws Exception
+    {
+        try
+        {
+            Torque.init( ConfigurationConverter.getConfiguration( properties ) );
+        }
+        catch (Exception e)
+        {
+            throw new Exception("Can't initialize Torque!", e);
+        }
+    }
+
+    public void configure(Configuration configuration)
+        throws ConfigurationException
+    {
+        Configuration[] propertyElements =
+            configuration.getChild("properties").getChildren("property");
+
+        properties = new Properties();
+        for (int i = 0; i < propertyElements.length; i++)
+        {
+            String property = propertyElements[i].getAttribute("name");
+            String value = propertyElements[i].getAttribute("value");
+            
+            properties.setProperty( property, value );
+        }
+    }
+
+    /**
+     * The log4j category used for logging db service events.
+     *
+     * @return a <code>Category</code> value
+     */
+    public Category getCategory()
+    {
+        return Category.getInstance(getClass().getName());
+    }
+
+    /**
+     * Returns the default database map information.
+     *
+     * @return A DatabaseMap.
+     * @throws ServiceException Any exceptions caught during procssing will be
+     *         rethrown wrapped into a ServiceException.
+     */
+    public DatabaseMap getDatabaseMap()
+        throws Exception
+    {
+        return Torque.getDatabaseMap();
+    }
+
+    /**
+     * Returns the database map information. Name relates to the name
+     * of the connection pool to associate with the map.
+     *
+     * @param name The name of the <code>DatabaseMap</code> to
+     * retrieve.
+     * @return The named <code>DatabaseMap</code>.
+     * @throws ServiceException Any exceptions caught during procssing will be
+     *         rethrown wrapped into a ServiceException.
+     */
+    public DatabaseMap getDatabaseMap(String name)
+        throws Exception
+    {
+        return Torque.getDatabaseMap(name);
+    }
+
+    /**
+     * This method returns a Connection from the default pool.
+     *
+     * @return The requested connection.
+     * @throws ServiceException Any exceptions caught during processing will be
+     *         rethrown wrapped into a ServiceException.
+     */
+    public Connection getConnection()
+        throws Exception
+    {
+        return Torque.getConnection();
+    }
+
+    /**
+     * This method returns a Connection from the pool with the
+     * specified name.  The pool must either have been registered
+     * with the {@link #registerPool(String,String,String,String,String)}
+     * method, or be specified in the property file using the
+     * following syntax:
+     *
+     * <pre>
+     * database.[name].driver
+     * database.[name].url
+     * database.[name].username
+     * database.[name].password
+     * </pre>
+     *
+     * @param name The name of the pool to get a connection from.
+     * @return     The requested connection.
+     * @throws ServiceException Any exceptions caught during processing will be
+     *         rethrown wrapped into a ServiceException.
+     */
+    public Connection getConnection(String name)
+        throws Exception
+    {
+        // The getPool method ensures the validity of the returned pool.
+        return Torque.getConnection(name);
+    }
+
+    /**
+     * Release a connection back to the database pool.  <code>null</code>
+     * references are ignored.
+     *
+     * @throws ServiceException Any exceptions caught during processing will be
+     *         rethrown wrapped into a ServiceException.
+     * @exception Exception A generic exception.
+     */
+    public void releaseConnection(Connection dbconn)
+        throws Exception
+    {
+        Torque.closeConnection(dbconn);
+    }
+
+
+    /**
+     * Returns the database adapter for the default connection pool.
+     *
+     * @return The database adapter.
+     * @throws ServiceException Any exceptions caught during processing will be
+     *         rethrown wrapped into a ServiceException.
+     */
+    public DB getDB()
+        throws Exception
+    {
+        return Torque.getDB(getDefaultDB());
+    }
+
+    /**
+     * Returns database adapter for a specific connection pool.
+     *
+     * @param name A pool name.
+     * @return     The corresponding database adapter.
+     * @throws ServiceException Any exceptions caught during processing will be
+     *         rethrown wrapped into a ServiceException.
+     */
+    public DB getDB(String name)
+        throws Exception
+    {
+        return Torque.getDB(name);
+    }
+
+    public String getDefaultDB()
+    {
+        return Torque.getDefaultDB();
+    }
+
+    /**
+     * This method is gone in Torque HEAD as it is a duplicate
+     * for getDefaultDB, but will stay here marked as deprecated
+     * for a little while.
+     *
+     * @deprecated
+     */
+    public String getDefaultMap()
+    {
+        return Torque.getDefaultDB();
+    }
+
+    /**
+     * @see org.apache.avalon.framework.activity.Startable#start()
+     */
+    public void start() throws Exception
+    {
+        // do nothing
+    }
+
+    /**
+     * Shuts down the service.
+     *
+     * This method halts the IDBroker's daemon thread in all of
+     * the DatabaseMap's.
+     * 
+     * @see org.apache.avalon.framework.activity.Startable#stop()
+     */
+    public void stop() throws Exception
+    {
+        Torque.shutdown();
+    }
+}

Index: DatabaseService.java
===================================================================
RCS file: /cvsroot/plexus/fulcrum/db/src/java/org/apache/fulcrum/db/DatabaseService.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- DatabaseService.java	5 May 2003 21:16:33 -0000	1.2
+++ DatabaseService.java	6 May 2003 17:06:55 -0000	1.3
@@ -83,7 +83,6 @@
  *
  * @author <a href="mailto:[email protected]">Rafal Krzewski</a>
  * @version $Id$
- * @deprecated you should use org.apache.torque.Torque
  */
 public interface DatabaseService
 {