db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r388792 - in /db/torque: runtime/trunk/src/java/org/apache/torque/avalon/ site/trunk/xdocs/ site/trunk/xdocs/version-specific/other-howtos/
Date Sat, 25 Mar 2006 18:06:20 GMT
Author: tv
Date: Sat Mar 25 10:06:18 2006
New Revision: 388792

URL: http://svn.apache.org/viewcvs?rev=388792&view=rev
Log:
- Update to the Avalon components of Torque. The component 
now understands Merlin- and YAAFI-type context entries and 
provides again all methods from TorqueInstance.
- The Torque interface provides access to all methods of 
TorqueComponent
- Add a little HowTo about using Torque with Avalon.

Added:
    db/torque/site/trunk/xdocs/version-specific/other-howtos/avalon-howto.xml
Modified:
    db/torque/runtime/trunk/src/java/org/apache/torque/avalon/Torque.java
    db/torque/runtime/trunk/src/java/org/apache/torque/avalon/TorqueComponent.java
    db/torque/site/trunk/xdocs/changes.xml
    db/torque/site/trunk/xdocs/navigation.xml

Modified: db/torque/runtime/trunk/src/java/org/apache/torque/avalon/Torque.java
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/src/java/org/apache/torque/avalon/Torque.java?rev=388792&r1=388791&r2=388792&view=diff
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/avalon/Torque.java (original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/avalon/Torque.java Sat Mar 25 10:06:18
2006
@@ -16,16 +16,168 @@
  * limitations under the License.
  */
 
+import java.sql.Connection;
+
 import org.apache.avalon.framework.component.Component;
+import org.apache.torque.TorqueException;
+import org.apache.torque.adapter.DB;
+import org.apache.torque.manager.AbstractBaseManager;
+import org.apache.torque.map.DatabaseMap;
 
 /**
  * Avalon role interface for Torque.
  *
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
  * @version $Id$
  */
 public interface Torque
         extends Component
 {
-    String ROLE = "org.apache.torque.avalon.Torque";
+    String ROLE = Torque.class.getName();
+
+    /*
+     * ========================================================================
+     *
+     * Torque Methods, accessible from the Component
+     *
+     * ========================================================================
+     */
+
+    /**
+     * Determine whether Torque has already been initialized.
+     *
+     * @return true if Torque is already initialized
+     */
+    public boolean isInit();
+
+    /**
+     * Get the configuration for this component.
+     *
+     * @return the Configuration
+     */
+    public org.apache.commons.configuration.Configuration getConfiguration();
+
+    /**
+     * This method returns a Manager for the given name.
+     *
+     * @param name name of the manager
+     * @return a Manager
+     */
+    public AbstractBaseManager getManager(String name);
+
+    /**
+     * This methods returns either the Manager from the configuration file,
+     * or the default one provided by the generated code.
+     *
+     * @param name name of the manager
+     * @param defaultClassName the class to use if name has not been configured
+     * @return a Manager
+     */
+    public AbstractBaseManager getManager(String name, String defaultClassName);
+
+    /**
+     * Returns the default database map information.
+     *
+     * @return A DatabaseMap.
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public DatabaseMap getDatabaseMap() throws TorqueException;
+
+    /**
+     * 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 database corresponding to the
+     *        <code>DatabaseMap</code> to retrieve.
+     * @return The named <code>DatabaseMap</code>.
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public DatabaseMap getDatabaseMap(String name) throws TorqueException;
+
+    /**
+     * Register a MapBuilder
+     *
+     * @param className the MapBuilder
+     */
+    public void registerMapBuilder(String className);
+
+    /**
+     * This method returns a Connection from the default pool.
+     *
+     * @return The requested connection.
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public Connection getConnection() throws TorqueException;
+
+    /**
+     *
+     * @param name The database name.
+     * @return a database connection
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public Connection getConnection(String name) throws TorqueException;
+
+    /**
+     * This method returns a Connecton using the given parameters.
+     * You should only use this method if you need user based access to the
+     * database!
+     *
+     * @param name The database name.
+     * @param username The name of the database user.
+     * @param password The password of the database user.
+     * @return A Connection.
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public Connection getConnection(String name, String username, String password)
+            throws TorqueException;
+
+    /**
+     * Returns database adapter for a specific connection pool.
+     *
+     * @param name A pool name.
+     * @return The corresponding database adapter.
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public DB getDB(String name) throws TorqueException;
+
+    /**
+     * Returns the name of the default database.
+     *
+     * @return name of the default DB
+     */
+    public String getDefaultDB();
+
+    /**
+     * Closes a connection.
+     *
+     * @param con A Connection to close.
+     */
+    public void closeConnection(Connection con);
+
+    /**
+     * Sets the current schema for a database connection
+     *
+     * @param name The database name.
+     * @param schema The current schema name
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public void setSchema(String name, String schema) throws TorqueException;
+
+    /**
+     * This method returns the current schema for a database connection
+     *
+     * @param name The database name.
+     * @return The current schema name. Null means, no schema has been set.
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public String getSchema(String name) throws TorqueException;
 }

Modified: db/torque/runtime/trunk/src/java/org/apache/torque/avalon/TorqueComponent.java
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/src/java/org/apache/torque/avalon/TorqueComponent.java?rev=388792&r1=388791&r2=388792&view=diff
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/avalon/TorqueComponent.java (original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/avalon/TorqueComponent.java Sat Mar
25 10:06:18 2006
@@ -16,11 +16,11 @@
  * limitations under the License.
  */
 
+import java.io.File;
 import java.sql.Connection;
 
 import org.apache.avalon.framework.activity.Initializable;
 import org.apache.avalon.framework.activity.Startable;
-import org.apache.avalon.framework.component.Component;
 import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -41,19 +41,20 @@
  *
  * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
  * @version $Id$
  */
 public class TorqueComponent
         extends AbstractLogEnabled
-        implements Component,
+        implements Torque,
                    Configurable,
                    Initializable,
                    Contextualizable,
                    Startable,
                    ThreadSafe
 {
-    /** The Avalon Context */
-    private Context context = null;
+    /** The Avalon Application Root */
+    private String appRoot = null;
 
     /** The instance of Torque used by this component. */
     private TorqueInstance torqueInstance = null;
@@ -111,26 +112,9 @@
         getLogger().debug("configure(" + configuration + ")");
 
         String configFile = configuration.getChild("configfile").getValue();
-        String appRoot = null;
-
-        try
-        {
-            appRoot = (context == null)
-                    ? null : (String) context.get("componentAppRoot");
-        }
-        catch (ContextException ce)
-        {
-            getLogger().error("Could not load Application Root from Context");
-        }
 
         if (StringUtils.isNotEmpty(appRoot))
         {
-            if (appRoot.endsWith("/"))
-            {
-                appRoot = appRoot.substring(0, appRoot.length() - 1);
-                getLogger().debug("Application Root changed to " + appRoot);
-            }
-
             if (configFile.startsWith("/"))
             {
                 configFile = configFile.substring(1);
@@ -139,7 +123,7 @@
 
             StringBuffer sb = new StringBuffer();
             sb.append(appRoot);
-            sb.append('/');
+            sb.append(File.separator);
             sb.append(configFile);
 
             configFile = sb.toString();
@@ -156,7 +140,30 @@
     public void contextualize(Context context)
             throws ContextException
     {
-        this.context = context;
+        // check context Merlin and YAAFI style
+        try
+        {
+            appRoot = ((File)context.get("urn:avalon:home")).getAbsolutePath();
+        }
+        catch (ContextException ce)
+        {
+            appRoot = null;
+        }
+
+        if (appRoot == null)
+        {
+            // check context old ECM style, let exception flow if not available
+            appRoot = (String) context.get("componentAppRoot");
+        }
+
+        if (StringUtils.isNotEmpty(appRoot))
+        {
+            if (appRoot.endsWith("/"))
+            {
+                appRoot = appRoot.substring(0, appRoot.length() - 1);
+                getLogger().debug("Application Root changed to " + appRoot);
+            }
+        }
     }
 
     /**
@@ -362,5 +369,31 @@
     public void closeConnection(Connection con)
     {
         getTorque().closeConnection(con);
+    }
+
+    /**
+     * Sets the current schema for a database connection
+     *
+     * @param name The database name.
+     * @param schema The current schema name
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public void setSchema(String name, String schema) throws TorqueException
+    {
+        getTorque().setSchema(name, schema);
+    }
+
+    /**
+     * This method returns the current schema for a database connection
+     *
+     * @param name The database name.
+     * @return The current schema name. Null means, no schema has been set.
+     * @throws TorqueException Any exceptions caught during processing will be
+     *         rethrown wrapped into a TorqueException.
+     */
+    public String getSchema(String name) throws TorqueException
+    {
+        return getTorque().getSchema(name);
     }
 }

Modified: db/torque/site/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/db/torque/site/trunk/xdocs/changes.xml?rev=388792&r1=388791&r2=388792&view=diff
==============================================================================
--- db/torque/site/trunk/xdocs/changes.xml (original)
+++ db/torque/site/trunk/xdocs/changes.xml Sat Mar 25 10:06:18 2006
@@ -22,12 +22,18 @@
     <author email="dion@multitask.com.au">dIon Gillard</author>
     <author email="hps@intermeta.de">Henning P. Schmiedehausen</author>
     <author email="fischer@seitenbau.de">Thomas Fischer</author>
+    <author email="tv@apache.org">Thomas Vandahl</author>
   </properties>
 
   <body>
 
   <release version="3.2.1-dev" date="in SVN">
   
+    <action type="update" dev="tv">
+      Update to the Avalon components of Torque. The component now understands
+      Merlin- and YAAFI-type context entries and provides again all methods from
+      TorqueInstance.
+    </action>
     <action type="fix" dev="tfischer" issue="TRQS335">
       HSQL's autoincrement columns now start with one instead of zero.
       Thanks to Patrick Carl for an early version of the patch.

Modified: db/torque/site/trunk/xdocs/navigation.xml
URL: http://svn.apache.org/viewcvs/db/torque/site/trunk/xdocs/navigation.xml?rev=388792&r1=388791&r2=388792&view=diff
==============================================================================
--- db/torque/site/trunk/xdocs/navigation.xml (original)
+++ db/torque/site/trunk/xdocs/navigation.xml Sat Mar 25 10:06:18 2006
@@ -62,6 +62,7 @@
           <item name="Database Layout"   href="/version-specific/other-howtos/database-layout-howto.html"/>
           <item name="DB Schema Support" href="/version-specific/other-howtos/schema-howto.html"/>
           <item name="Inheritance"       href="/version-specific/other-howtos/inheritance-guide.html"/>
+          <item name="Avalon Component"  href="/version-specific/other-howtos/avalon-howto.html"/>
         </item>
         <item name="Tutorial"            href="/releases/torque-3.2/tutorial/index.html"
collapse="true">
           <item name="dummy"/>

Added: db/torque/site/trunk/xdocs/version-specific/other-howtos/avalon-howto.xml
URL: http://svn.apache.org/viewcvs/db/torque/site/trunk/xdocs/version-specific/other-howtos/avalon-howto.xml?rev=388792&view=auto
==============================================================================
--- db/torque/site/trunk/xdocs/version-specific/other-howtos/avalon-howto.xml (added)
+++ db/torque/site/trunk/xdocs/version-specific/other-howtos/avalon-howto.xml Sat Mar 25 10:06:18
2006
@@ -0,0 +1,77 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+
+<document>
+ <properties>
+  	<title>Using Torque as an Avalon Component</title>
+    <author email="tv@apache.org">Thomas Vandahl</author>
+ </properties>
+
+ <body>
+
+  <section name="General">
+    <p>
+     Torque has provided Avalon Component support for some time now. This little
+     HowTo should provide the necessary information to use Torque with some Avalon 
+     containers, namely ECM, Merlin and Fulcrum-YAAFI.
+    </p>
+  </section>
+
+  <section name="Configuration">
+    <p>
+     The configuration is straightforward. Use the following snippet to make
+     the Torque component available in your container:
+    </p>
+    <source><![CDATA[
+<role-list>
+    <role
+        name="org.apache.torque.avalon.Torque"
+        shorthand="Torque"
+        default-class="org.apache.torque.avalon.TorqueComponent"/>
+</role-list>
+]]></source>
+    <p>
+     Torque will need access to its configuration file, so the component 
+     configuration looks like this:
+    </p>
+    <source><![CDATA[
+<componentConfig>
+    <Torque>
+      <configFile>/WEB-INF/conf/Torque.properties</configFile>
+    </Torque>
+</componentConfig>
+]]></source>
+    <p>
+     The path of the configuration file is relative to the application root
+     of the container.
+    </p>
+  </section>
+
+  <section name="Use">
+
+    <p>
+     All access to the Torque component should go through the 
+     <code>org.apache.torque.avalon.Torque</code> interface. It provides all
methods
+     available in <code>TorqueInstance</code>.
+     The role name to lookup the component in your container is also
+     <code>org.apache.torque.avalon.Torque</code>.
+    </p>
+
+  </section>
+
+ </body>
+</document>



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