You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by mp...@apache.org on 2002/07/12 22:46:56 UTC
cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/services/db MapBrokerService.java PoolBrokerService.java TurbineDB.java TurbineMapBrokerService.java TurbinePoolBrokerService.java
mpoeschl 2002/07/12 13:46:55
Modified: src/java/org/apache/turbine/services/db
MapBrokerService.java PoolBrokerService.java
TurbineDB.java TurbineMapBrokerService.java
TurbinePoolBrokerService.java
Log:
deprecate the db services
they are just facades for Torque now
Revision Changes Path
1.4 +5 -6 jakarta-turbine-2/src/java/org/apache/turbine/services/db/MapBrokerService.java
Index: MapBrokerService.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/db/MapBrokerService.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MapBrokerService.java 11 Jul 2002 07:16:42 -0000 1.3
+++ MapBrokerService.java 12 Jul 2002 20:46:55 -0000 1.4
@@ -54,9 +54,9 @@
* <http://www.apache.org/>.
*/
+import org.apache.torque.map.DatabaseMap;
import org.apache.turbine.services.Service;
import org.apache.turbine.util.TurbineException;
-import org.apache.torque.map.DatabaseMap;
/**
* This service manages {@link org.apache.turbine.util.db.map.DatabaseMap}
@@ -66,6 +66,7 @@
*
* @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
* @version $Id$
+ * @deprecated use org.apache.torque.Torque
*/
public interface MapBrokerService extends Service
{
@@ -89,8 +90,7 @@
* @throws TurbineException Any exceptions caught during procssing will be
* rethrown wrapped into a TurbineException.
*/
- public DatabaseMap getDatabaseMap()
- throws TurbineException;
+ public DatabaseMap getDatabaseMap() throws TurbineException;
/**
* Returns the database map information. Name relates to the name
@@ -102,6 +102,5 @@
* @throws TurbineException Any exceptions caught during procssing will be
* rethrown wrapped into a TurbineException.
*/
- public DatabaseMap getDatabaseMap(String name)
- throws TurbineException;
+ public DatabaseMap getDatabaseMap(String name) throws TurbineException;
}
1.4 +13 -55 jakarta-turbine-2/src/java/org/apache/turbine/services/db/PoolBrokerService.java
Index: PoolBrokerService.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/db/PoolBrokerService.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PoolBrokerService.java 11 Jul 2002 07:16:42 -0000 1.3
+++ PoolBrokerService.java 12 Jul 2002 20:46:55 -0000 1.4
@@ -79,6 +79,7 @@
*
* @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
* @version $Id$
+ * @deprecated use org.apache.torque.Torque
*/
public interface PoolBrokerService extends Service
{
@@ -98,84 +99,41 @@
* 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.
+ * @throws Exception A generic exception.
*/
- public Connection getConnection()
- throws Exception;
+ public Connection getConnection() throws Exception;
/**
* 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>
+ * specified name.
*
* @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.
+ * @throws Exception A generic exception.
*/
- public Connection getConnection(String name)
- throws Exception;
-
+ public Connection getConnection(String name) throws Exception;
/**
* 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(Connection dbconn)
- throws Exception;
-
- /**
- * 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.
+ * @throws Exception A generic exception.
*/
-/*
- public void registerPool( String name,
- String driver,
- String url,
- String username,
- String password )
- throws Exception;
-*/
+ public void releaseConnection(Connection dbconn) throws Exception;
/**
* 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.
+ * @throws Exception A generic exception.
*/
- public DB getDB()
- throws Exception;
+ public DB getDB() throws Exception;
/**
* 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.
+ * @throws Exception A generic exception.
*/
- public DB getDB(String name)
- throws Exception;
+ public DB getDB(String name) throws Exception;
}
1.5 +14 -15 jakarta-turbine-2/src/java/org/apache/turbine/services/db/TurbineDB.java
Index: TurbineDB.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/db/TurbineDB.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TurbineDB.java 11 Jul 2002 07:16:42 -0000 1.4
+++ TurbineDB.java 12 Jul 2002 20:46:55 -0000 1.5
@@ -54,11 +54,11 @@
* <http://www.apache.org/>.
*/
-import org.apache.turbine.services.TurbineServices;
-import org.apache.turbine.util.TurbineException;
+import java.sql.Connection;
import org.apache.torque.adapter.DB;
import org.apache.torque.map.DatabaseMap;
-import java.sql.Connection;
+import org.apache.turbine.services.TurbineServices;
+import org.apache.turbine.util.TurbineException;
/**
* This class provides a common front end to all database - related
@@ -67,14 +67,12 @@
* can call to access the methods of system's configured service
* implementations.
* <p>
- * Assuming that your TurbineResources.properties file is setup correctly, the
- * sample code below demonstrates the right way to get and release a database
- * connection (exception handling is application dependent):
- * <blockquote><code><pre>
- * DBConnection dbConn = null;
+ * <b> This class is deprecated you should use org.apache.torque.Torque</b>
+ *
+ * Connection dbConn = null;
* try
* {
- * dbConn = TurbineDB.getConnection();
+ * dbConn = Torque.getConnection();
* // Do something with the connection here...
* }
* catch (Exception e)
@@ -85,7 +83,7 @@
* {
* try
* {
- * TurbineDB.releaseConnection(dbConn);
+ * dbConn.close();
* }
* catch (Exception e)
* {
@@ -96,6 +94,7 @@
*
* @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
* @version $Id$
+ * @deprecated use org.apache.torque.Torque
*/
public abstract class TurbineDB
{
@@ -190,7 +189,7 @@
* This method returns a DBConnection from the default pool.
*
* @return The requested connection.
- * @throws TurbineException Any exceptions caught during processing will be
+ * @throws Exception Any exceptions caught during processing will be
* rethrown wrapped into a TurbineException.
*/
public static Connection getConnection()
@@ -215,7 +214,7 @@
*
* @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
+ * @throws Exception Any exceptions caught during processing will be
* rethrown wrapped into a TurbineException.
*/
public static Connection getConnection(String name)
@@ -268,7 +267,7 @@
* Returns the database adapter for the default connection pool.
*
* @return The database adapter.
- * @throws TurbineException Any exceptions caught during processing will be
+ * @throws Exception Any exceptions caught during processing will be
* rethrown wrapped into a TurbineException.
*/
public static DB getDB()
@@ -282,7 +281,7 @@
*
* @param name A pool name.
* @return The corresponding database adapter.
- * @throws TurbineException Any exceptions caught during processing will be
+ * @throws Exception Any exceptions caught during processing will be
* rethrown wrapped into a TurbineException.
*/
public static DB getDB(String name)
1.7 +20 -117 jakarta-turbine-2/src/java/org/apache/turbine/services/db/TurbineMapBrokerService.java
Index: TurbineMapBrokerService.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/db/TurbineMapBrokerService.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TurbineMapBrokerService.java 11 Jul 2002 07:16:42 -0000 1.6
+++ TurbineMapBrokerService.java 12 Jul 2002 20:46:55 -0000 1.7
@@ -54,19 +54,10 @@
* <http://www.apache.org/>.
*/
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
+import org.apache.torque.Torque;
+import org.apache.torque.map.DatabaseMap;
import org.apache.turbine.services.BaseService;
-import org.apache.turbine.services.resources.TurbineResources;
import org.apache.turbine.util.TurbineException;
-import org.apache.torque.oid.IDGeneratorFactory;
-import org.apache.torque.oid.IDBroker;
-import org.apache.torque.adapter.DB;
-import org.apache.torque.adapter.DBFactory;
-import org.apache.torque.map.DatabaseMap;
-import org.apache.torque.map.TableMap;
-import org.apache.commons.configuration.Configuration;
/**
@@ -80,30 +71,17 @@
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
* @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
* @version $Id$
+ * @deprecated use org.apache.torque.Torque instead
*/
public class TurbineMapBrokerService extends BaseService
- implements MapBrokerService
+ implements MapBrokerService
{
- /** The global cache of database maps */
- private Map dbMaps;
-
- /** Default database map */
- private String defaultMap;
/**
* Initializes the service.
*/
public void init()
{
- dbMaps = (Map)new HashMap();
- Configuration configuration = getConfiguration();
-
- // Get the value for the default map, but if there
- // isn't a value than fall back to the standard
- // "default" value.
- defaultMap = configuration.getString(DEFAULT_MAP, DEFAULT);
-
- // indicate that the service initialized correctly
setInit(true);
}
@@ -112,7 +90,7 @@
*/
public String getDefaultMap()
{
- return defaultMap;
+ return Torque.getDefaultMap();
}
/**
@@ -123,16 +101,6 @@
*/
public void shutdown()
{
- Iterator maps = dbMaps.values().iterator();
- while ( maps.hasNext() )
- {
- DatabaseMap map = (DatabaseMap) maps.next();
- IDBroker idBroker = map.getIDBroker();
- if (idBroker != null)
- {
- idBroker.stop();
- }
- }
}
/**
@@ -143,9 +111,16 @@
* rethrown wrapped into a TurbineException.
*/
public DatabaseMap getDatabaseMap()
- throws TurbineException
+ throws TurbineException
{
- return getDatabaseMap(defaultMap);
+ try
+ {
+ return Torque.getDatabaseMap();
+ }
+ catch (Exception ex)
+ {
+ throw new TurbineException(ex);
+ }
}
/**
@@ -159,88 +134,16 @@
* rethrown wrapped into a TurbineException.
*/
public DatabaseMap getDatabaseMap(String name)
- throws TurbineException
+ throws TurbineException
{
- if ( name == null )
+ try
{
- throw new TurbineException ("DatabaseMap name was null!");
+ return Torque.getDatabaseMap(name);
}
-
- // Quick (non-sync) check for the map we want.
- DatabaseMap map = (DatabaseMap)dbMaps.get(name);
- if ( map == null )
+ catch (Exception ex)
{
- // Map not there...
- synchronized( dbMaps )
- {
- // ... sync and look again to avoid race condition.
- map = (DatabaseMap)dbMaps.get(name);
- if ( map == null )
- {
- // Still not there. Create and add.
- map = new DatabaseMap(name);
-
- // Add info about IDBroker's table.
- setupIdTable(map);
- // setup other id generators
- try
- {
- DB db = DBFactory.create(
- getDatabaseProperty(name, "driver") );
- for (int i = 0; i < IDGeneratorFactory.ID_GENERATOR_METHODS.length;
- i++)
- {
- map.addIdGenerator(IDGeneratorFactory.ID_GENERATOR_METHODS[i],
- IDGeneratorFactory.create(db));
- }
- }
- catch (java.lang.InstantiationException e)
- {
- throw new TurbineException(e);
- }
-
- dbMaps.put(name, map);
- }
- }
+ throw new TurbineException(ex);
}
- return map;
- }
-
- /**
- * Returns the specified property of the given database, or the empty
- * string if no value is set for the property.
- *
- * @param db The name of the database whose property to get.
- * @param prop The name of the property to get.
- * @return The property's value.
- */
- private static final String getDatabaseProperty(String db, String prop)
- {
- return TurbineResources.getString
- ( new StringBuffer("database.")
- .append(db)
- .append('.')
- .append(prop)
- .toString(), "" );
- }
-
- /**
- * Setup IDBroker's table information within given database map.
- *
- * This method should be called on all new database map to ensure that
- * IDBroker functionality is available in all databases userd by the
- * application.
- *
- * @param map the DataBaseMap to setup.
- */
- private void setupIdTable(DatabaseMap map)
- {
- map.setIdTable("ID_TABLE");
- TableMap tMap = map.getIdTable();
- tMap.addPrimaryKey("ID_TABLE_ID", new Integer(0));
- tMap.addColumn("TABLE_NAME", new String(""));
- tMap.addColumn("NEXT_ID", new Integer(0));
- tMap.addColumn("QUANTITY", new Integer(0));
}
}
1.7 +16 -160 jakarta-turbine-2/src/java/org/apache/turbine/services/db/TurbinePoolBrokerService.java
Index: TurbinePoolBrokerService.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/services/db/TurbinePoolBrokerService.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TurbinePoolBrokerService.java 11 Jul 2002 16:53:28 -0000 1.6
+++ TurbinePoolBrokerService.java 12 Jul 2002 20:46:55 -0000 1.7
@@ -55,14 +55,10 @@
*/
import java.sql.Connection;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.commons.configuration.Configuration;
import org.apache.torque.Torque;
import org.apache.torque.adapter.DB;
import org.apache.torque.util.BasePeer;
import org.apache.turbine.services.BaseService;
-import org.apache.turbine.services.resources.TurbineResources;
/**
@@ -76,47 +72,16 @@
* @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
* @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
* @version $Id$
+ * @deprecated use org.apache.torque.Torque instead
*/
public class TurbinePoolBrokerService extends BaseService
- implements PoolBrokerService
+ implements PoolBrokerService
{
/**
- * Name of the default connection pool.
- */
- public static final String DEFAULT = "default";
-
- /** Default database pool */
- private String defaultPool;
-
- /**
- * The various connection pools this broker contains. Keyed by
- * database URL.
- */
- private Map pools;
-
- /**
* Initialize the connection pool broker.
*/
public void init()
{
- pools = (Map) new HashMap();
-
- Configuration configuration = getConfiguration();
-
- // Get the value for the default pool, but if there
- // isn't a value than fall back to the standard
- // "default" value.
- defaultPool = configuration.getString(DEFAULT_POOL, DEFAULT);
-
- // Create monitor thread
-// Monitor monitor = new Monitor();
- // Indicate that this is a system thread. JVM will quit only when there
- // are no more active user threads. Settings threads spawned internally
- // by Turbine as daemons allows commandline applications using Turbine
- // to terminate in an orderly manner.
-// monitor.setDaemon(true);
-// monitor.start();
-
// indicate that the service initialized correctly
setInit(true);
}
@@ -141,36 +106,22 @@
* 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.
+ * @throws Exception A generic exception.
*/
- public Connection getConnection()
- throws Exception
+ public Connection getConnection() throws Exception
{
return 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>
+ * specified name.
*
* @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.
+ * @throws Exception A generic exception.
*/
- public Connection getConnection(String name)
- throws Exception
+ public Connection getConnection(String name) throws Exception
{
return Torque.getConnection(name);
}
@@ -179,12 +130,9 @@
* Release a connection back to the database pool. <code>null</code>
* references are ignored.
*
- * @throws TurbineException Any exceptions caught during processing will be
- * rethrown wrapped into a TurbineException.
- * @exception Exception A generic exception.
+ * @throws Exception A generic exception.
*/
- public void releaseConnection(Connection dbconn)
- throws Exception
+ public void releaseConnection(Connection dbconn) throws Exception
{
BasePeer.closeConnection(dbconn);
}
@@ -193,13 +141,11 @@
* 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.
+ * @throws Exception A generic exception.
*/
- public DB getDB()
- throws Exception
+ public DB getDB() throws Exception
{
- return getDB(DEFAULT);
+ return Torque.getDB(Torque.getDefaultDB());
}
/**
@@ -207,100 +153,10 @@
*
* @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 Torque.getDB(getDefaultDB());
- }
-
- ///////////////////////////////////////////////////////////////////////////
-
- /**
- * Returns the specified property of the given database, or the empty
- * string if no value is set for the property.
- *
- * @param db The name of the database whose property to get.
- * @param prop The name of the property to get.
- * @return The property's value.
+ * @throws Exception A generic exception.
*/
- private static final String getDatabaseProperty(String db, String prop)
+ public DB getDB(String name) throws Exception
{
- return TurbineResources.getString
- ( new StringBuffer("database.")
- .append(db)
- .append('.')
- .append(prop)
- .toString(), "" );
- }
-
- /**
- * Returns the string for the specified property of the given database.
- *
- * @param db The name of the database whose property to get.
- * @param prop The name of the property to get.
- * @return The string of the property.
- */
- private String getProperty(String db, String prop)
- {
- return
- new StringBuffer("database.")
- .append(db)
- .append('.')
- .append(prop)
- .toString();
- }
-
- ///////////////////////////////////////////////////////////////////////////
-
- /**
- * This inner class monitors the <code>PoolBrokerService</code>.
- *
- * This class is capable of logging the number of connections available in
- * the pool periodically. This can prove useful if you application
- * frozes after certain amount of time/requests and you suspect
- * that you have connection leakage problem.
- *
- * Set the <code>database.logInterval</code> property to the number of
- * milliseconds you want to elapse between loging the number of
- * connections.
- */
-/*
- protected class Monitor extends Thread
- {
- public void run()
- {
- int logInterval = TurbineResources.getInt("database.logInterval",0);
- StringBuffer buf = new StringBuffer();
- while (logInterval > 0)
- {
- // Loop through all pools and log.
- Iterator poolIter = pools.keySet().iterator();
- while ( poolIter.hasNext() )
- {
- String poolName = (String) poolIter.next();
- ConnectionPool pool = (ConnectionPool) pools.get(poolName);
- buf.setLength(0);
- buf.append(poolName).append(" (in + out = total): ")
- .append(pool.getNbrAvailable()).append(" + ")
- .append(pool.getNbrCheckedOut()).append(" = ")
- .append(pool.getTotalCount());
- Log.info("database",buf.toString());
- }
-
- // Wait for a bit.
- try
- {
- Thread.sleep(logInterval);
- }
- catch (InterruptedException ignored)
- {
- // Don't care.
- }
- }
- }
+ return Torque.getDB(name);
}
-*/
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>