jmcnally 02/01/09 00:11:45
Modified: src/java/org/apache/torque Tag: JDBC2POOL_BRANCH Torque.java
src/java/org/apache/torque/oid Tag: JDBC2POOL_BRANCH
IDBroker.java
src/java/org/apache/torque/util Tag: JDBC2POOL_BRANCH
BasePeer.java LargeSelect.java
src/rttest Tag: JDBC2POOL_BRANCH Torque.properties
Log:
removed references to the old pool and DBConnection.
Added code to intialize datasources and/or their location within jndi.
Revision Changes Path
No revision
No revision
1.41.2.2 +237 -354 jakarta-turbine-torque/src/java/org/apache/torque/Torque.java
Index: Torque.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/Torque.java,v
retrieving revision 1.41.2.1
retrieving revision 1.41.2.2
diff -u -r1.41.2.1 -r1.41.2.2
--- Torque.java 30 Dec 2001 17:38:29 -0000 1.41.2.1
+++ Torque.java 9 Jan 2002 08:11:44 -0000 1.41.2.2
@@ -54,6 +54,8 @@
* <http://www.apache.org/>.
*/
+import java.sql.Connection;
+import javax.sql.DataSource;
import java.beans.PropertyDescriptor;
import java.beans.PropertyEditorManager;
import java.beans.PropertyEditor;
@@ -68,6 +70,8 @@
import java.util.ArrayList;
import java.util.Vector;
import java.util.Properties;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NameAlreadyBoundException;
@@ -81,8 +85,6 @@
import org.apache.torque.map.TableMap;
import org.apache.torque.oid.IDGeneratorFactory;
import org.apache.torque.oid.IDBroker;
-import org.apache.torque.pool.ConnectionPool;
-import org.apache.torque.pool.DBConnection;
import org.apache.torque.util.BasePeer;
/**
@@ -92,7 +94,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Magn�s ��r Torfason</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Rafal Krzewski</a>
- * @version $Id: Torque.java,v 1.41.2.1 2001/12/30 17:38:29 jmcnally Exp $
+ * @version $Id: Torque.java,v 1.41.2.2 2002/01/09 08:11:44 jmcnally Exp $
*/
public class Torque
{
@@ -117,6 +119,26 @@
*/
private static Map dbMaps;
+ /**
+ * The cache of initial contexts that contain jdbc datasources
+ */
+ private static Map jndiContexts;
+
+ /**
+ * The cache of jndi paths to jdbc datasources
+ */
+ private static Map dsJndiPaths;
+
+ /**
+ * The cache of datasources
+ */
+ private static Map dsMap;
+
+ /**
+ * The cache of DB adapter keys
+ */
+ private static Map adapterMap;
+
/**
* The various connection pools this broker contains. Keyed by
* database URL.
@@ -135,11 +157,6 @@
private static ExtendedProperties configuration;
/**
- * The connection pool monitor.
- */
- private static Monitor monitor;
-
- /**
* flag to set to true once this class has been initialized
*/
private static boolean isInit = false;
@@ -209,6 +226,8 @@
dbMaps = new HashMap();
pools = new HashMap();
DBFactory.init(configuration);
+ initAdapters(configuration);
+ initJNDI(configuration);
initDataSources(configuration);
isInit = true;
@@ -219,36 +238,101 @@
}
// any further mapBuilders will be called/built on demand
mapBuilders = null;
-
-
- // Create monitor thread
- 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();
}
- private static final void initDataSources(ExtendedProperties configuration)
+ private static final void initJNDI(ExtendedProperties configuration)
throws TorqueException
{
- ExtendedProperties c = configuration.subset("datasource");
+ category.debug("Starting initJNDI");
+ jndiContexts = new HashMap();
+ dsJndiPaths = new HashMap();
+ ExtendedProperties c = configuration.subset("jndi");
//Map dsMap = new HashMap();
try
{
- Context ctx = new InitialContext();
- // add jdbc, if it has not been added already
- try
+ Iterator i = c.getKeys();
+ while (i.hasNext())
{
- ctx.createSubcontext("jdbc");
+ String key = (String)i.next();
+ if (key.endsWith("path"))
+ {
+ String path = c.getString(key);
+ String handle = key.substring(0, key.indexOf('.'));
+ //dsMap.put(name, cpdsClassName);
+ category.debug("JNDI handle: " + handle +
+ " path: " + path);
+
+ ExtendedProperties jndiProps = c.subset(handle);
+
+ Hashtable env = new Hashtable();
+ Iterator j = jndiProps.getKeys();
+ while (j.hasNext())
+ {
+ String property = (String)j.next();
+ if ( !"path".equals(property) )
+ {
+ category.debug("Setting jndi " + handle +
+ " property: " + property);
+ env.put(property, jndiProps.getString(property));
+ }
+ }
+ if ( env.size() == 0 )
+ {
+ jndiContexts.put(handle, new InitialContext());
+ }
+ else
+ {
+ jndiContexts.put(handle, new InitialContext(env));
+ }
+
+ dsJndiPaths.put(handle, path);
+ }
}
- catch(NameAlreadyBoundException nabe)
+ }
+ catch (Exception e)
+ {
+ category.error(e);
+ throw new TorqueException(e);
+ }
+ }
+
+ private static final void initAdapters(ExtendedProperties configuration)
+ throws TorqueException
+ {
+ category.debug("Starting initAdapters");
+ ExtendedProperties c = configuration.subset("database");
+ try
+ {
+ Iterator i = c.getKeys();
+ while (i.hasNext())
{
- // ignore
+ String key = (String)i.next();
+ if (key.endsWith("adapter"))
+ {
+ String adapter = c.getString(key);
+ String handle = key.substring(0, key.indexOf('.'));
+ DB db = DBFactory.create( adapter );
+ // register the adapter for this name
+ adapterMap.put(handle, db);
+ }
}
+ }
+ catch (Exception e)
+ {
+ category.error(e);
+ throw new TorqueException(e);
+ }
+ }
+
+ private static final void initDataSources(ExtendedProperties configuration)
+ throws TorqueException
+ {
+ category.debug("Starting initDataSources");
+ ExtendedProperties c = configuration.subset("datasource");
+ try
+ {
+ Class mapClass = Class.forName("java.util.Map");
Iterator i = c.getKeys();
while (i.hasNext())
{
@@ -257,53 +341,143 @@
{
String classname = c.getString(key);
String handle = key.substring(0, key.indexOf('.'));
- //dsMap.put(name, cpdsClassName);
category.debug("Datasource handle: " + handle +
" classname: " + classname);
Class dsClass = Class.forName(classname);
- Object ds = dsClass.newInstance();
+ DataSource ds = (DataSource)dsClass.newInstance();
ExtendedProperties dsProps = c.subset(handle);
// use reflection to set properties
Iterator j = dsProps.getKeys();
while (j.hasNext())
{
String property = (String)j.next();
- if ( !"classname".equals(property) &&
- !"adapter".equals(property) )
+ if ( !"classname".equals(property) )
{
category.debug("Setting datasource " + handle +
" property: " + property);
+ setProperty(property, dsProps, ds);
+ }
+ }
+
+ Context ctx = (Context)jndiContexts.get(handle);
+ if ( ctx == null )
+ {
+ if ( dsMap == null)
+ {
+ dsMap = new HashMap();
+ }
+ dsMap.put(handle, ds);
+ }
+ else
+ {
+ // bind the datasource
+ String path = (String)dsJndiPaths.get(handle);
+ bindDStoJndi(ctx, path, ds);
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ category.error(e);
+ throw new TorqueException(e);
+ }
+ }
+
+ private static void bindDStoJndi(Context ctx, String path, DataSource ds)
+ throws Exception
+ {
+ // Start debugging
+ category.debug("instantiated InitialContext");
+ Map env = ctx.getEnvironment();
+ Iterator qw = env.keySet().iterator();
+ category.debug("Environment properties:" + env.size() );
+ while ( qw.hasNext() )
+ {
+ Object prop = qw.next();
+ category.debug(" " + prop + ": " + env.get(prop) );
+ }
+ // End debugging
+
+ // add subcontexts, if not added already
+ int start = path.indexOf(':') + 1;
+ if ( start > 0 )
+ {
+ path = path.substring(start);
+ }
+ StringTokenizer st = new StringTokenizer(path, "/");
+ while ( st.hasMoreTokens() )
+ {
+ String subctx = st.nextToken();
+ if ( st.hasMoreTokens() )
+ {
try
{
- PropertyDescriptor pd =
- new PropertyDescriptor(property, dsClass);
- Method setter = pd.getWriteMethod();
- PropertyEditor pe = PropertyEditorManager
- .findEditor(pd.getPropertyType());
- pe.setAsText(dsProps.getString(property));
- Object[] value = { pe.getValue() };
- setter.invoke(ds, value);
+ ctx.createSubcontext(subctx);
+ category.debug("Added sub context: "+subctx);
}
- catch (Exception e)
+ catch(NameAlreadyBoundException nabe)
{
- category.error(
- "Property: " + property + " value: "
- + dsProps.getString(property) +
- " is not supported by DataSource: "
- + classname);
- throw e;
+ // ignore
}
+ ctx = (Context)ctx.lookup(subctx);
}
+ else
+ {
+ // not really a subctx, it is the ds name
+ ctx.bind(subctx, ds);
+ }
}
- ctx.bind("jdbc/" + handle, ds);
- }
- }
+ }
+
+ private static void setProperty(String property, ExtendedProperties c,
+ Object ds)
+ throws Exception
+ {
+ try
+ {
+ int dot = property.indexOf('.');
+ if ( dot > 0 )
+ {
+ property = property.substring(0, dot);
+ }
+ Class dsClass = ds.getClass();
+ PropertyDescriptor pd =
+ new PropertyDescriptor(property, dsClass);
+ Method setter = pd.getWriteMethod();
+ Object[] value = new Object[1];
+ if ( dot > 0 )
+ {
+ Properties propMap = new Properties();
+ ExtendedProperties subProps = c.subset(property);
+ // use reflection to set properties
+ Iterator j = subProps.getKeys();
+ while (j.hasNext())
+ {
+ String subProp = (String)j.next();
+ String propVal = subProps.getString(subProp);
+ propMap.setProperty(subProp, propVal);
+ }
+ value[0] = propMap;
+ }
+ else
+ {
+ PropertyEditor pe = PropertyEditorManager
+ .findEditor(pd.getPropertyType());
+ pe.setAsText(c.getString(property));
+ value[0] = pe.getValue();
+ }
+ setter.invoke(ds, value);
}
catch (Exception e)
{
- throw new TorqueException(e);
- }
+ category.error("Property: " + property + " value: "
+ + c.getString(property) +
+ " is not supported by DataSource: " +
+ ds.getClass().getName());
+ throw e;
+ }
}
public static boolean isInit()
@@ -453,26 +627,6 @@
}
}
}
-
- if ( pools != null )
- {
- // Release connections for each pool.
- Iterator pool = pools.values().iterator();
- while ( pool.hasNext() )
- {
- try
- {
- ((ConnectionPool)pool.next()).shutdown();
- }
- catch (Exception ignored)
- {
- // Unlikely.
- }
- }
- }
-
- // shutdown the thread
- monitor = null;
}
/**
@@ -616,39 +770,13 @@
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- public static DBConnection getConnection()
+ public static Connection getConnection()
throws Exception
{
return getConnection(getDefaultDB());
}
/**
- * 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 TorqueException Any exceptions caught during processing will be
- * rethrown wrapped into a TorqueException.
- */
- public static DBConnection getConnection(String name)
- throws Exception
- {
- // The getPool method ensures the validity of the returned pool.
- return getPool(name).getConnection();
- }
-
- /**
* This method returns a DBConnecton using the given parameters.
*
* @param driver The fully-qualified name of the JDBC driver to use.
@@ -663,148 +791,21 @@
* @deprecated Database parameters should not be specified each
* time a DBConnection is fetched from the service.
*/
- public static DBConnection getConnection(String driver,
- String url,
- String username,
- String password)
- throws Exception
- {
- ConnectionPool pool = null;
- url = url.trim();
-
- // Quick (non-sync) check for the pool we want.
- // NOTE: Here we must not call getPool(), since the pool
- // is almost certainly not defined in the properties file
- pool = (ConnectionPool) pools.get(url + username);
- if ( pool == null )
- {
- registerPool(url + username, driver, url, username, password);
- pool = (ConnectionPool) pools.get(url + username);
- }
-
- return pool.getConnection();
- }
-
- /**
- * Release a connection back to the database pool. <code>null</code>
- * references are ignored.
- *
- * @throws TorqueException Any exceptions caught during processing will be
- * rethrown wrapped into a TorqueException.
- * @exception Exception A generic exception.
- */
- public static void releaseConnection(DBConnection dbconn)
- throws Exception
- {
- if ( dbconn != null )
- {
- ConnectionPool pool = dbconn.getPool();
- if ( pools.containsValue( pool ) )
- {
- pool.releaseConnection( dbconn );
- }
- }
- }
-
- /**
- * 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 Exception Any exceptions caught during processing will be
- * rethrown wrapped into a TorqueException.
- */
- public static void registerPool( String name,
- String driver,
- String url,
- String username,
- String password )
- throws Exception
+ public static Connection getConnection(String name,
+ String username,
+ String password)
+ throws java.sql.SQLException, javax.naming.NamingException
{
- /**
- * Added so that the configuration file can define maxConnections &
- * expiryTime for each database pool that is defined in the
- * TurbineResources.properties
- * Was defined as: database.expiryTime=3600000
- * If you need per database, it is
- * now database.helpdesk.expiryTime=3600000
- */
- registerPool(
- name,
- driver,
- url,
- username,
- password,
- configuration.getInt(getProperty(name, "maxConnections"), 10),
- configuration.getLong(getProperty(name, "expiryTime"), 3600000),
- configuration.getLong(getProperty(name, "maxConnectionAttempts"), 50),
- configuration.getLong(getProperty(name, "connectionWaitTimeout"),
10000));
+ Context ctx = (Context)jndiContexts.get(name);
+ String jndiPath = (String)dsJndiPaths.get(name);
+ return ((DataSource)ctx.lookup(jndiPath))
+ .getConnection(username, password);
}
- /**
- * This thread-safe 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.
- * @exception Exception A generic exception.
- */
- public static void registerPool( String name,
- String driver,
- String url,
- String username,
- String password,
- int maxCons,
- long expiryTime,
- long maxConnectionAttempts,
- long connectionWaitTimeout)
- throws Exception
+ public static Connection getConnection(String name)
+ throws java.sql.SQLException, javax.naming.NamingException
{
-
- // Quick (non-sync) check for the pool we want.
- if ( !pools.containsKey(name) )
- {
- // Pool not there...
- synchronized (pools)
- {
- // ... sync and look again to avoid race collisions.
- if ( !pools.containsKey(name) )
- {
- // Still not there. Create and add.
- ConnectionPool pool =
- new ConnectionPool(
- driver,
- url,
- username,
- password,
- maxCons,
- expiryTime,
- maxConnectionAttempts,
- connectionWaitTimeout);
-
- pools.put( name, pool );
- }
- }
- }
- }
-
- /**
- * Returns the database adapter for the default connection pool.
- *
- * @return The database adapter.
- * @throws TorqueException Any exceptions caught during processing will be
- * rethrown wrapped into a TorqueException.
- */
- public static DB getDB()
- throws Exception
- {
- return getDB(getDefaultDB());
+ return getConnection(name, null, null);
}
/**
@@ -818,128 +819,10 @@
public static DB getDB(String name)
throws Exception
{
- return getPool(name).getDB();
+ return (DB)adapterMap.get(name);
}
///////////////////////////////////////////////////////////////////////////
-
- /**
- * This method returns the default pool.
- *
- * @return The default pool.
- * @exception Exception A generic exception.
- * @see #getPool(String name)
- */
- private static ConnectionPool getPool()
- throws Exception
- {
- return getPool(getDefaultDB());
- }
-
- /**
- * This method returns a 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 TurbineResources properties. This method is used
- * internally by the service.
- *
- * @param name The name of the pool to get.
- * @return The requested pool.
- *
- * @exception Exception A generic exception.
- */
- private static ConnectionPool getPool(String name)
- throws Exception
- {
- if (name == null)
- {
- throw new TorqueException ("Torque.getPool(): name is null");
- }
- if (pools == null)
- {
- throw new TorqueException (
- "Torque.getPool(): pools is null, did you call Torque.init()
first?");
- }
-
- ConnectionPool pool = (ConnectionPool) pools.get(name);
-
- // If the pool is not in the Hashtable, we must register it.
- if ( pool == null )
- {
- registerPool(
- name,
- getDatabaseProperty(name, "driver"),
- getDatabaseProperty(name, "url"),
- getDatabaseProperty(name, "username"),
- getDatabaseProperty(name, "password"));
-
- pool = (ConnectionPool) pools.get(name);
- }
-
- return pool;
- }
-
- /**
- * Returns the string for the specified property of the given database.
- *
- * @param dbName 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 static final String getProperty(String dbName, String prop)
- {
- return ("database." + dbName + '.' + prop);
- }
-
- ///////////////////////////////////////////////////////////////////////////
-
- /**
- * 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 static class Monitor extends Thread
- {
- public void run()
- {
- int logInterval = configuration.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());
-
- category.info(buf.toString());
- }
-
- // Wait for a bit.
- try
- {
- Thread.sleep(logInterval);
- }
- catch (InterruptedException ignored)
- {
- // Don't care.
- }
- }
- }
- }
/**
* Returns the name of the default database.
No revision
No revision
1.10.2.2 +11 -19
jakarta-turbine-torque/src/java/org/apache/torque/oid/IDBroker.java
Index: IDBroker.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/oid/IDBroker.java,v
retrieving revision 1.10.2.1
retrieving revision 1.10.2.2
diff -u -r1.10.2.1 -r1.10.2.2
--- IDBroker.java 30 Dec 2001 17:49:11 -0000 1.10.2.1
+++ IDBroker.java 9 Jan 2002 08:11:44 -0000 1.10.2.2
@@ -70,7 +70,6 @@
import org.apache.torque.TorqueException;
import org.apache.torque.map.DatabaseMap;
import org.apache.torque.map.TableMap;
-import org.apache.torque.pool.DBConnection;
import org.apache.torque.util.BasePeer;
import org.apache.torque.util.Criteria;
@@ -113,7 +112,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Frank Y. Kim</a>
* @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
- * @version $Id: IDBroker.java,v 1.10.2.1 2001/12/30 17:49:11 jmcnally Exp $
+ * @version $Id: IDBroker.java,v 1.10.2.2 2002/01/09 08:11:44 jmcnally Exp $
*/
public class IDBroker
implements Runnable, IdGenerator
@@ -236,12 +235,11 @@
// IDBroker is being used with a database that does not
// support transactions.
String dbName = tMap.getDatabaseMap().getName();
- DBConnection dbCon = null;
+ Connection dbCon = null;
try
{
dbCon = Torque.getConnection(dbName);
- transactionsSupported = dbCon.getConnection()
- .getMetaData().supportsTransactions();
+ transactionsSupported = dbCon.getMetaData().supportsTransactions();
}
catch (Exception e)
{
@@ -252,7 +250,7 @@
try
{
// Return the connection to the pool.
- Torque.releaseConnection(dbCon);
+ dbCon.close();
}
catch (Exception e)
{
@@ -456,16 +454,13 @@
.toString();
boolean exists = false;
- DBConnection dbCon = null;
+ Connection dbCon = null;
try
{
String databaseName = tableMap.getDatabaseMap().getName();
- // Get a connection to the db
dbCon = Torque.getConnection(databaseName);
- Connection connection = dbCon.getConnection();
-
- Statement statement = connection.createStatement();
+ Statement statement = dbCon.createStatement();
ResultSet rs = statement.executeQuery(query);
exists = rs.next();
statement.close();
@@ -475,7 +470,7 @@
// Return the connection to the pool.
try
{
- Torque.releaseConnection(dbCon);
+ dbCon.close();
}
catch (Exception e)
{
@@ -634,7 +629,7 @@
}
else
{
- con = BasePeer.getConnection(databaseName);
+ con = Torque.getConnection(databaseName);
}
// Write the current value of quantity of keys to grab
@@ -728,17 +723,14 @@
}
else
{
- DBConnection dbCon = null;
+ Connection dbCon = null;
try
{
String databaseName = tableMap.getDatabaseMap().getName();
-
- // Get a connection to the db
dbCon = Torque.getConnection(databaseName);
- Connection connection = dbCon.getConnection();
// Read the row from the ID_TABLE.
- BigDecimal[] results = selectRow(connection, tableName);
+ BigDecimal[] results = selectRow(dbCon, tableName);
// QUANTITY column.
quantity = results[1];
@@ -753,7 +745,7 @@
// Return the connection to the pool.
try
{
- Torque.releaseConnection(dbCon);
+ dbCon.close();
}
catch (Exception e)
{
No revision
No revision
1.20.2.2 +11 -21
jakarta-turbine-torque/src/java/org/apache/torque/util/BasePeer.java
Index: BasePeer.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/util/BasePeer.java,v
retrieving revision 1.20.2.1
retrieving revision 1.20.2.2
diff -u -r1.20.2.1 -r1.20.2.2
--- BasePeer.java 30 Dec 2001 17:49:11 -0000 1.20.2.1
+++ BasePeer.java 9 Jan 2002 08:11:45 -0000 1.20.2.2
@@ -78,7 +78,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
-import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.apache.torque.om.NumberKey;
@@ -92,7 +91,6 @@
import org.apache.torque.map.DatabaseMap;
import org.apache.torque.map.MapBuilder;
import org.apache.torque.map.TableMap;
-import org.apache.torque.pool.DBConnection;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Query;
import org.apache.torque.util.SqlExpression;
@@ -113,7 +111,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Frank Y. Kim</a>
* @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Brett McLaughlin</a>
- * @version $Id: BasePeer.java,v 1.20.2.1 2001/12/30 17:49:11 jmcnally Exp $
+ * @version $Id: BasePeer.java,v 1.20.2.2 2002/01/09 08:11:45 jmcnally Exp $
*/
public abstract class BasePeer implements java.io.Serializable
{
@@ -232,7 +230,7 @@
try
{
- con = getConnection(dbName);
+ con = Torque.getConnection(dbName);
schema = new Schema().schema(con, tableName);
}
catch(Exception e)
@@ -249,14 +247,6 @@
return schema;
}
- public static Connection getConnection(String dbName)
- throws java.sql.SQLException, javax.naming.NamingException
- {
- StringBuffer sb = new StringBuffer(dbName.length() + 5);
- String jndiName = sb.append("jdbc/").append(dbName).toString();
- return ((DataSource)ctx.lookup(jndiName)).getConnection();
- }
-
public static void closeConnection(Connection con)
{
try
@@ -344,7 +334,7 @@
public static Connection beginTransaction(String dbName)
throws Exception
{
- Connection con = getConnection(dbName);
+ Connection con = Torque.getConnection(dbName);
if ( con.getMetaData().supportsTransactions() )
{
con.setAutoCommit(false);
@@ -468,7 +458,7 @@
try
{
// Get a connection to the db.
- con = getConnection("default");
+ con = Torque.getConnection("default");
deleteAll( con, table, column, value );
}
finally
@@ -511,7 +501,7 @@
{
try
{
- con = getConnection(dbName);
+ con = Torque.getConnection(dbName);
doDelete(criteria, con);
}
finally
@@ -701,7 +691,7 @@
}
else
{
- con = getConnection(criteria.getDbName());
+ con = Torque.getConnection(criteria.getDbName());
}
id = doInsert(criteria, con);
}
@@ -1333,7 +1323,7 @@
Vector results = null;
try
{
- db = getConnection(dbName);
+ db = Torque.getConnection(dbName);
// execute the query
results = executeQuery(queryString, start, numberOfResults,
singleRecord, db);
@@ -1562,7 +1552,7 @@
}
else
{
- db = getConnection(updateValues.getDbName());
+ db = Torque.getConnection(updateValues.getDbName());
}
doUpdate(updateValues, db);
@@ -1664,7 +1654,7 @@
}
else
{
- db = getConnection(selectCriteria.getDbName());
+ db = Torque.getConnection(selectCriteria.getDbName());
}
doUpdate(selectCriteria, updateValues, db);
}
@@ -1816,7 +1806,7 @@
int rowCount = -1;
try
{
- db = getConnection(dbName);
+ db = Torque.getConnection(dbName);
rowCount = executeStatement( stmt, db );
}
finally
@@ -2039,7 +2029,7 @@
*/
public static Vector doPSSelect(Criteria criteria) throws Exception
{
- Connection con = getConnection(criteria.getDbName());
+ Connection con = Torque.getConnection(criteria.getDbName());
Vector v = null;
try
1.2.2.1 +4 -6
jakarta-turbine-torque/src/java/org/apache/torque/util/LargeSelect.java
Index: LargeSelect.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/util/LargeSelect.java,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -r1.2 -r1.2.2.1
--- LargeSelect.java 10 Aug 2001 12:23:04 -0000 1.2
+++ LargeSelect.java 9 Jan 2002 08:11:45 -0000 1.2.2.1
@@ -58,7 +58,6 @@
import java.util.Vector;
import org.apache.torque.Torque;
import org.apache.torque.util.BasePeer;
-import org.apache.torque.pool.DBConnection;
import org.apache.torque.util.BasePeer;
import com.workingdogs.village.QueryDataSet;
@@ -77,7 +76,7 @@
* untested and in all likelihood contains several bugs.
*
* @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
- * @version $Id: LargeSelect.java,v 1.2 2001/08/10 12:23:04 knielsen Exp $
+ * @version $Id: LargeSelect.java,v 1.2.2.1 2002/01/09 08:11:45 jmcnally Exp $
*/
public class LargeSelect
implements Runnable
@@ -90,7 +89,7 @@
private int currentlyFilledTo = -1;
private String query;
private String dbName;
- private DBConnection db = null;
+ private Connection db = null;
private QueryDataSet qds = null;
private Vector results = null;
private Thread thread = null;
@@ -328,10 +327,9 @@
{
// Get a connection to the db.
db = Torque.getConnection(dbName);
- Connection connection = db.getConnection();
// Execute the query.
- qds = new QueryDataSet( connection, query );
+ qds = new QueryDataSet( db, query );
// Continue getting rows until the memory limit is
// reached, all results have been retrieved, or the rest
@@ -368,7 +366,7 @@
{
qds.close();
}
- Torque.releaseConnection(db);
+ db.close();
}
catch(Exception e)
{
No revision
No revision
1.6.2.1 +13 -5 jakarta-turbine-torque/src/rttest/Torque.properties
Index: Torque.properties
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/rttest/Torque.properties,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -u -r1.6 -r1.6.2.1
--- Torque.properties 27 Nov 2001 00:37:11 -0000 1.6
+++ Torque.properties 9 Jan 2002 08:11:45 -0000 1.6.2.1
@@ -1,5 +1,5 @@
# -------------------------------------------------------------------
-# $Id: Torque.properties,v 1.6 2001/11/27 00:37:11 dlr Exp $
+# $Id: Torque.properties,v 1.6.2.1 2002/01/09 08:11:45 jmcnally Exp $
#
# This is the configuration file for Torque.
#
@@ -44,10 +44,18 @@
torque.database.default=bookstore
-torque.database.bookstore.driver = @DATABASE_DRIVER@
-torque.database.bookstore.url = @DATABASE_URL@
-torque.database.bookstore.username = @DATABASE_USER@
-torque.database.bookstore.password = @DATABASE_PASSWORD@
+torque.jndi.bookstore.path=java:jdbc/bookstore
+torque.jndi.bookstore.java.naming.factory.initial =
org.apache.naming.java.javaURLContextFactory
+torque.jndi.bookstore.java.naming.factory.url.pkgs = org.apache.naming
+
+torque.datasource.bookstore.classname=org.apache.torque.jdbc2pool.TorqueDataSource
+torque.datasource.bookstore.dataSourceName=DBbookstore
+torque.datasource.bookstore.adapter=mysql
+
+torque.datasource.DBbookstore.driver = @DATABASE_DRIVER@
+torque.datasource.DBbookstore.url = @DATABASE_URL@
+torque.datasource.DBbookstore.user = @DATABASE_USER@
+torque.datasource.DBbookstore.password = @DATABASE_PASSWORD@
# The number of database connections to cache per ConnectionPool
# instance (specified per database).
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>