You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Chris Kimpton <ki...@yahoo.com> on 2002/04/06 02:00:42 UTC

Fwd: cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/torquewrapper TorqueDBAdaptor.java TorqueDBConnectionAdaptor.java TorquePoolServiceAdaptor.java

Hi,

As part of upgrading Jetspeed to use the latest torque, I want to
ensure that all db access goes through one set of torque pools.

Fine for new stuff - does it automatically - the issue is the
existing security/user stuff in turbine-2.  In order to route any db
access for users to go through the new torque3 stuff I have added the
following service to Jetspeed.  This makes torque look like the
TurbinePoolService.

This makes the db settings in TR.props redundant - the ones in
Torque.props are used for everything.

Does this like the right thing to do?

It would really help if someone could review what I've done and
comment on whether there might be any problems.

I have currently put this in the Jetspeed cvs repository - but I
realise that it might have a wider audience...  So feel free to stick
it in the turbine-2 cvs repo.  Obviously this would then be removed
from the Jetspeed one.

TIA,
Chris



--- kimptoc@apache.org wrote:
> Reply-to: "Jetspeed Developers List"
> <je...@jakarta.apache.org>
> Date: 5 Apr 2002 23:54:05 -0000
> From: kimptoc@apache.org
> To: jakarta-jetspeed-cvs@apache.org
> Subject: cvs commit:
>
jakarta-jetspeed/src/java/org/apache/jetspeed/services/torquewrapper
> TorqueDBAdaptor.java TorqueDBConnectionAdaptor.java
> TorquePoolServiceAdaptor.java
> 
> kimptoc     02/04/05 15:54:05
> 
>   Added:       src/java/org/apache/jetspeed/services/torquewrapper
>                         TorqueDBAdaptor.java
> TorqueDBConnectionAdaptor.java
>                         TorquePoolServiceAdaptor.java
>   Log:
>   wrapper around torque pools so that it looks like turbine-2, part
> of the changes towards using the dbpsml based on torque3
>   
>   Revision  Changes    Path
>   1.1                 
>
jakarta-jetspeed/src/java/org/apache/jetspeed/services/torquewrapper/TorqueDBAdaptor.java
>   
>   Index: TorqueDBAdaptor.java
>  
> ===================================================================
>   /*
>
====================================================================
>    * The Apache Software License, Version 1.1
>    *
>    * Copyright (c) 2000-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 Jetspeed" must not be used to endorse or promote
> products
>    *    derived from this software without prior written
> permission. For
>    *    written permission, please contact apache@apache.org.
>    *
>    * 5. Products derived from this software may not be called
> "Apache" or
>    *    "Apache Jetspeed", 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/>.
>    */
>   
>   package org.apache.jetspeed.services.torquewrapper;
>   
>   import org.apache.turbine.util.db.adapter.DB;
>   
>   import java.sql.Connection;
>   import java.sql.SQLException;
>   
>   /**
>    * Adaptor for the new torque DB object that makes it look the
> old turbine-2 DB object
>    *
>    * @author <a href="mailto:kimptoc_mail@yahoo.com">Chris
> Kimpton</a>
>    * @version $Id: TorqueDBAdaptor.java,v 1.1 2002/04/05 23:54:05
> kimptoc Exp $
>    */
>   public class TorqueDBAdaptor extends DB {
>   
>       private org.apache.torque.adapter.DB _torqueDB = null;
>   
>       TorqueDBAdaptor(org.apache.torque.adapter.DB torqueDB)
>       {
>           _torqueDB = torqueDB;
>       }
>   
>       /**
>        * This method is used to ignore case.
>        *
>        * @param in The string to transform to upper case.
>        * @return The upper case string.
>        */
>       public String toUpperCase(String in) {
>           return _torqueDB.toUpperCase(in);
>       }
>   
>       /**
>        * Gets the string delimiter (usually '\'').
>        *
>        * @return The delimeter.
>        */
>       public char getStringDelimiter() {
>           return _torqueDB.getStringDelimiter();
>       }
>   
>       /**
>        * Returns the constant from the {@see IDMethod} interface
> denoting which
>        * type of primary key generation method this type of RDBMS
> uses.
>        */
>       public String getIDMethodType() {
>           return _torqueDB.getIDMethodType();
>       }
>   
>       /**
>        * Returns SQL used to get the most recently inserted primary
> key.
>        * Databases which have no support for this return
>        * <code>null</code>.
>        *
>        * @param obj Information used for key generation.
>        * @return The most recently inserted database key.
>        */
>       public String getIDMethodSQL(Object obj) {
>           return _torqueDB.getIDMethodSQL(obj);
>       }
>   
>       /**
>        * Locks the specified table.
>        *
>        * @param con The JDBC connection to use.
>        * @param table The name of the table to lock.
>        * @exception SQLException
>        */
>       public void lockTable(Connection con,
>                             String table)
>               throws SQLException {
>           _torqueDB.lockTable(con,table);
>       }
>   
>       /**
>        * Unlocks the specified table.
>        *
>        * @param con The JDBC connection to use.
>        * @param table The name of the table to unlock.
>        * @exception SQLException
>        */
>       public void unlockTable(Connection con,
>                               String table)
>               throws SQLException {
>           _torqueDB.unlockTable(con,table);
>       }
>   
>       /**
>        * This method is used to ignore case.
>        *
>        * @param in The string whose case to ignore.
>        * @return The string in a case that can be ignored.
>        */
>       public String ignoreCase(String in) {
>           return _torqueDB.ignoreCase(in);
>       }
>   }
>   
>   
>   
>   1.1                 
>
jakarta-jetspeed/src/java/org/apache/jetspeed/services/torquewrapper/TorqueDBConnectionAdaptor.java
>   
>   Index: TorqueDBConnectionAdaptor.java
>  
> ===================================================================
>   /*
>
====================================================================
>    * The Apache Software License, Version 1.1
>    *
>    * Copyright (c) 2000-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 Jetspeed" must not be used to endorse or promote
> products
>    *    derived from this software without prior written
> permission. For
>    *    written permission, please contact apache@apache.org.
>    *
>    * 5. Products derived from this software may not be called
> "Apache" or
>    *    "Apache Jetspeed", 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/>.
>    */
>   
>   package org.apache.jetspeed.services.torquewrapper;
>   
>   import org.apache.turbine.util.db.pool.DBConnection;
>   import org.apache.turbine.util.db.pool.ConnectionPool;
>   
>   import javax.sql.PooledConnection;
>   import javax.sql.ConnectionEventListener;
>   import javax.sql.ConnectionEvent;
>   import java.sql.Connection;
>   import java.sql.SQLException;
>   import java.sql.Statement;
>   import java.sql.PreparedStatement;
>   
>   /**
>    * Adaptor for the new torque DBConnection that makes it look the
> old turbine-2 DBConnection
>    *
>    * @author <a href="mailto:kimptoc_mail@yahoo.com">Chris
> Kimpton</a>
>    * @version $Id: TorqueDBConnectionAdaptor.java,v 1.1 2002/04/05
> 23:54:05 kimptoc Exp $
>    */
>   public class TorqueDBConnectionAdaptor extends DBConnection {
>   
>       private org.apache.torque.pool.DBConnection _torqueConn =
> null;
>   
>       TorqueDBConnectionAdaptor(org.apache.torque.pool.DBConnection
> torqueConn) throws SQLException
>       {
>           super(torqueConn.getConnection());
>           _torqueConn = torqueConn;
>       }
>   
>       org.apache.torque.pool.DBConnection getTorqueDBConnection()
>       {
>           return _torqueConn;
>       }
>   
>       /**
>        * Commit the connection.
>        */
>       public void commit() {
>           _torqueConn.commit();
>       }
>   
>       /**
>        * Roll back the connection.
>        */
>       public void rollback() {
>           _torqueConn.rollback();
>       }
>   
>       /**
>        * Set the autocommit flag for the connection.
>        *
>        * @param b True if autocommit should be set to true.
>        */
>       public void setAutoCommit(boolean b) {
>           _torqueConn.setAutoCommit(b);
>       }
>   
>   
>       /**
>        * Returns a JDBC connection.
>        *
>        * @return The database connection.
>        */
>       public Connection getConnection()
>               throws SQLException {
>           return _torqueConn.getConnection();
>       }
>   
>   
>       /**
>        * Create a Java SQL statement for this connection.
>        *
>        * @return A new <code>Statement</code>.
>        */
>       public Statement createStatement() {
>           return _torqueConn.createStatement();
>       }
>   
>       /**
>        * Create a prepared Java SQL statement for this connection.
>        *
>        * @param sql The SQL statement to prepare.
>        * @return A new <code>PreparedStatement</code>.
>        */
>       public PreparedStatement prepareStatement(String sql) {
>           return _torqueConn.prepareStatement(sql);
>       }
>   
>       /**
>        * Force the close of this database connection.
>        *
>        * @exception SQLException The database connection couldn't
> be closed.
>        */
>       public void close()
>               throws SQLException {
>           _torqueConn.close();
>       }
>   
>       /**
>        * This will be called if the Connection returned by the
> getConnection
>        * method came from a PooledConnection, and the user calls
> the close()
>        * method of this connection object. What we need to do here
> is to
>        * release this DBConnection from our pool...
>        */
>       public void connectionClosed(ConnectionEvent event) {
>           _torqueConn.connectionClosed(event);
>       }
>   
>       /**
>        * If a fatal error occurs, close the undelying physical
> connection so as not to
>        * be returned in the future
>        */
>       public void connectionErrorOccurred(ConnectionEvent e) {
>           _torqueConn.connectionErrorOccurred(e);
>       }
>   }
>   
>   
>   
>   1.1                 
>
jakarta-jetspeed/src/java/org/apache/jetspeed/services/torquewrapper/TorquePoolServiceAdaptor.java
>   
>   Index: TorquePoolServiceAdaptor.java
>  
> ===================================================================
>   /*
>
====================================================================
>    * The Apache Software License, Version 1.1
>    *
>    * Copyright (c) 2000-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 Jetspeed" must not be used to endorse or promote
> products
>    *    derived from this software without prior written
> permission. For
>    *    written permission, please contact apache@apache.org.
>    *
>    * 5. Products derived from this software may not be called
> "Apache" or
>    *    "Apache Jetspeed", 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/>.
>    */
>   
>   package org.apache.jetspeed.services.torquewrapper;
>   
>   import org.apache.turbine.services.BaseService;
>   import org.apache.turbine.services.db.PoolBrokerService;
>   import org.apache.turbine.services.db.TurbinePoolBrokerService;
>   import org.apache.turbine.util.db.pool.DBConnection;
>   import org.apache.turbine.util.db.adapter.DB;
>   import org.apache.torque.Torque;
>   import org.apache.stratum.configuration.Configuration;
>   
>   import java.util.Map;
>   import java.util.HashMap;
>   
>   /** This class exposes the new Torque pool service as if it was
> the old Turbine-2 Pool service
>    *
>    * @author <a href="mailto:kimptoc_mail@yahoo.com">Chris
> Kimpton</a>
>    * @version $Id: TorquePoolServiceAdaptor.java,v 1.1 2002/04/05
> 23:54:05 kimptoc Exp $
>    **/
>   public class TorquePoolServiceAdaptor extends BaseService
>       implements PoolBrokerService{
>       /** Return default DB */
>       public String getDefaultDB() {
>           return Torque.getDefaultDB();
>       }
>   
>       public void init()
>        {
>            // indicate that the service initialized correctly
>            setInit(true);
>        }
>   
>   
>       /**
>        * This method returns a DBConnection from the default pool.
>        *
>        * @return The requested connection.
>        * @throws TurbineException Any exceptions caught during
> processing will be
>        *         rethrown wrapped into a TurbineException.
>        */
>       public DBConnection getConnection()
>               throws Exception {
>           return new
> TorqueDBConnectionAdaptor(Torque.getConnection());
>       }
>   
>       /**
>        * This method returns a DBConnection 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 TurbineException Any exceptions caught during
> processing will be
>        *         rethrown wrapped into a TurbineException.
>        */
>       public DBConnection getConnection(String name)
>               throws Exception {
>           return new
> TorqueDBConnectionAdaptor(Torque.getConnection(name));
>       }
>   
>       /**
>        * This method returns a DBConnecton using the given
> parameters.
>        *
>        * @param driver The fully-qualified name of the JDBC driver
> to use.
>        * @param url The URL of the database from which the
> connection is
>        * desired.
>        * @param username The name of the database user.
>        * @param password The password of the database user.
>        * @return A DBConnection.
>        * @throws TurbineException Any exceptions caught during
> processing will be
>        *         rethrown wrapped into a TurbineException.
>        *
>        * @deprecated Database parameters should not be specified
> each
>        * time a DBConnection is fetched from the service.
>        */
>       public DBConnection getConnection(String driver,
>                                         String url,
>                                         String username,
>                                         String password)
>               throws Exception {
>           return new
>
TorqueDBConnectionAdaptor(Torque.getConnection(driver,url,username,password));
>       }
>   
>       /**
>        * Release a connection back to the database pool.
>        *
>        * @throws TurbineException Any exceptions caught during
> processing will be
>        *         rethrown wrapped into a TurbineException.
>        * @exception Exception A generic exception.
>        */
>       public void releaseConnection(DBConnection dbconn)
>               throws Exception {
>           TorqueDBConnectionAdaptor _wrappedConn =
> (TorqueDBConnectionAdaptor)dbconn;
>          
> Torque.releaseConnection(_wrappedConn.getTorqueDBConnection());
>       }
>   
>       /**
>        * This method registers a new pool using the given
> parameters.
>        *
>        * @param name The name of the pool to register.
>        * @param driver The fully-qualified name of the JDBC driver
> to use.
>        * @param url The URL of the database to use.
>        * @param username The name of the database user.
>        * @param password The password of the database user.
>        *
>        * @throws TurbineException Any exceptions caught during
> processing will be
>        *         rethrown wrapped into a TurbineException.
>        */
>       public void registerPool(String name,
>                                String driver,
>                                String url,
>                                String username,
>                                String password)
>               throws Exception {
>           Torque.registerPool(name,driver,url,username,password);
>       }
>   
>       /**
>        * Returns the database adapter for the default connection
> pool.
>        *
>        * @return The database adapter.
>        * @throws TurbineException Any exceptions caught during
> processing will be
>        *         rethrown wrapped into a TurbineException.
>        */
>       public DB getDB()
>               throws Exception {
>           return new TorqueDBAdaptor(Torque.getDB());
>       }
>   
>       /**
>        * Returns database adapter for a specific connection pool.
>        *
>        * @param name A pool name.
>        * @return     The corresponding database adapter.
>        * @throws TurbineException Any exceptions caught during
> processing will be
>        *         rethrown wrapped into a TurbineException.
>        */
>       public DB getDB(String name)
>               throws Exception {
>           return new TorqueDBAdaptor(Torque.getDB(name));
>       }
>   }
>   
>   
>   
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


=====
------------------------------------------
http://www.soccer2002.org.uk

__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>