org.apache.torque.pool
Class TorqueClassicDataSource

java.lang.Object
  extended byorg.apache.torque.pool.TorqueClassicDataSource
All Implemented Interfaces:
javax.sql.DataSource, javax.naming.spi.ObjectFactory, javax.naming.Referenceable, java.io.Serializable

public class TorqueClassicDataSource
extends java.lang.Object
implements javax.sql.DataSource, javax.naming.Referenceable, java.io.Serializable, javax.naming.spi.ObjectFactory

Torque's default connection pool DataSource

Version:
$Id: TorqueClassicDataSource.java,v 1.5.2.1 2003/05/27 22:38:35 mpoeschl Exp $
Author:
John D. McNally
See Also:
Serialized Form

Field Summary
private  int connectionWaitTimeout
          time to wait when initiating a connection for the database to respond
private  javax.sql.ConnectionPoolDataSource cpds
          Pool Data Source that is used to fetch connections
private static int cpdsCounter
          Counter used to create an internal unique name od the Data Source
private  java.lang.String dataSourceName
          DataSource Name used to find the ConnectionPoolDataSource
private  boolean defaultAutoCommit
          Do connections from this pool are auto-committing?
private  int defaultMaxConnections
          Maximum Number of Connections cached in this Data Source
private  boolean defaultReadOnly
          Are connections from this pool read-only?
private  java.lang.String description
          Description
private  java.util.Properties jndiEnvironment
          Environment that may be used to set up a jndi initial context.
private  int logInterval
          Interval (in seconds) that the monitor thread reports the pool state
private  int loginTimeout
          Login TimeOut in seconds
private  java.io.PrintWriter logWriter
          Log stream
private  int maxExpiryTime
          Maximum lifetime of a database connection
private  java.util.Properties perUserMaxConnections
          Maximum Number of Connections for a specified User in this Data Source
private static java.util.Map pools
          Pools keyed by username.
 
Constructor Summary
TorqueClassicDataSource()
          Default no-arg constructor for Serialization
 
Method Summary
 java.sql.Connection getConnection()
          Attempt to establish a database connection.
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
          Attempt to establish a database connection.
 javax.sql.ConnectionPoolDataSource getConnectionPoolDataSource()
          Get the value of connectionPoolDataSource.
 int getConnectionWaitTimeout()
          Get the amount of time (in seconds) a connection request will have to wait before a time out occurs and an error is thrown.
 java.lang.String getDataSourceName()
          Get the name of the ConnectionPoolDataSource which backs this pool.
 int getDefaultMaxConnections()
          Get the number of database connections to cache per user.
 java.lang.String getDescription()
          Get the description.
 java.lang.String getJndiEnvironment(java.lang.String key)
          Get the value of jndiEnvironment which is used when instantiating a jndi InitialContext.
private  java.lang.String getKey(java.lang.String suffix)
           
 int getLogInterval()
          Get the interval (in seconds) between which the ConnectionPool logs the status of it's Connections.
 int getLoginTimeout()
          Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.
 java.io.PrintWriter getLogWriter()
          Get the log writer for this data source.
 int getMaxExpiryTime()
          Get the amount of time (in seconds) that database connections will be cached.
 java.lang.Object getObjectInstance(java.lang.Object refObj, javax.naming.Name name, javax.naming.Context context, java.util.Hashtable env)
          implements ObjectFactory to create an instance of this class
 java.util.Properties getPerUserMaxConnections()
          Get the number of database connections to cache per user.
 javax.naming.Reference getReference()
          Referenceable implementation.
 boolean isDefaultAutoCommit()
          Get the value of defaultAutoCommit, which defines the state of connections handed out from this pool.
 boolean isDefaultReadOnly()
          Get the value of defaultReadOnly, which defines the state of connections handed out from this pool.
private  void registerPool(java.lang.String username, java.lang.String password)
           
 void setConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource v)
          Set the backend ConnectionPoolDataSource.
 void setConnectionWaitTimeout(int v)
          Eet the amount of time (in seconds) a connection request will have to wait before a time out occurs and an error is thrown.
 void setDataSourceName(java.lang.String v)
          Set the name of the ConnectionPoolDataSource which backs this pool.
 void setDefaultAutoCommit(boolean v)
          Set the value of defaultAutoCommit, which defines the state of connections handed out from this pool.
 void setDefaultMaxConnections(int v)
          Set the number of database connections to cache per user.
 void setDefaultReadOnly(boolean v)
          Set the value of defaultReadOnly, which defines the state of connections handed out from this pool.
 void setDescription(java.lang.String v)
          Set the description.
 void setJndiEnvironment(java.lang.String key, java.lang.String value)
          Set the value of jndiEnvironment which is used when instantiating a jndi InitialContext.
 void setLogInterval(int v)
          Set the interval (in seconds) between which the ConnectionPool logs the status of it's Connections.
 void setLoginTimeout(int seconds)
          Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.
 void setLogWriter(java.io.PrintWriter out)
          Set the log writer for this data source.
 void setMaxExpiryTime(int v)
          Set the amount of time (in seconds) that database connections will be cached.
 void setPerUserMaxConnections(java.util.Properties v)
          Set the number of database connections to cache per user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pools

private static java.util.Map pools
Pools keyed by username.


cpdsCounter

private static int cpdsCounter
Counter used to create an internal unique name od the Data Source


dataSourceName

private java.lang.String dataSourceName
DataSource Name used to find the ConnectionPoolDataSource


description

private java.lang.String description
Description


loginTimeout

private int loginTimeout
Login TimeOut in seconds


cpds

private javax.sql.ConnectionPoolDataSource cpds
Pool Data Source that is used to fetch connections


logWriter

private java.io.PrintWriter logWriter
Log stream


jndiEnvironment

private java.util.Properties jndiEnvironment
Environment that may be used to set up a jndi initial context.


defaultMaxConnections

private int defaultMaxConnections
Maximum Number of Connections cached in this Data Source


perUserMaxConnections

private java.util.Properties perUserMaxConnections
Maximum Number of Connections for a specified User in this Data Source


maxExpiryTime

private int maxExpiryTime
Maximum lifetime of a database connection


connectionWaitTimeout

private int connectionWaitTimeout
time to wait when initiating a connection for the database to respond


logInterval

private int logInterval
Interval (in seconds) that the monitor thread reports the pool state


defaultAutoCommit

private boolean defaultAutoCommit
Do connections from this pool are auto-committing?


defaultReadOnly

private boolean defaultReadOnly
Are connections from this pool read-only?

Constructor Detail

TorqueClassicDataSource

public TorqueClassicDataSource()
Default no-arg constructor for Serialization

Method Detail

getDefaultMaxConnections

public int getDefaultMaxConnections()
Get the number of database connections to cache per user. This value is used for any username which is not specified in perUserMaxConnections. The default is 1.

Returns:
value of maxConnections.

setDefaultMaxConnections

public void setDefaultMaxConnections(int v)
Set the number of database connections to cache per user. This value is used for any username which is not specified in perUserMaxConnections. The default is 1.

Parameters:
v - Value to assign to maxConnections.

getPerUserMaxConnections

public java.util.Properties getPerUserMaxConnections()
Get the number of database connections to cache per user. The keys are usernames and the value is the maximum connections. Any username specified here will override the value of defaultMaxConnections.

Returns:
value of perUserMaxConnections.

setPerUserMaxConnections

public void setPerUserMaxConnections(java.util.Properties v)
Set the number of database connections to cache per user. The keys are usernames and the value is the maximum connections. Any username specified here will override the value of defaultMaxConnections.

Parameters:
v - Value to assign to perUserMaxConnections.

getMaxExpiryTime

public int getMaxExpiryTime()
Get the amount of time (in seconds) that database connections will be cached. The default is 3600 (1 hour).

Returns:
value of expiryTime.

setMaxExpiryTime

public void setMaxExpiryTime(int v)
Set the amount of time (in seconds) that database connections will be cached. The default is 3600 (1 hour).

Parameters:
v - Value to assign to expiryTime.

getConnectionWaitTimeout

public int getConnectionWaitTimeout()
Get the amount of time (in seconds) a connection request will have to wait before a time out occurs and an error is thrown. The default is 10 seconds.

Returns:
value of connectionWaitTimeout.

setConnectionWaitTimeout

public void setConnectionWaitTimeout(int v)
Eet the amount of time (in seconds) a connection request will have to wait before a time out occurs and an error is thrown. The default is 10 seconds.

Parameters:
v - Value to assign to connectionWaitTimeout.

getLogInterval

public int getLogInterval()
Get the interval (in seconds) between which the ConnectionPool logs the status of it's Connections. Default is 0 which indicates no logging.

Returns:
value of logInterval.

setLogInterval

public void setLogInterval(int v)
Set the interval (in seconds) between which the ConnectionPool logs the status of it's Connections. Default is 0 which indicates no logging.

Parameters:
v - Value to assign to logInterval.

isDefaultAutoCommit

public boolean isDefaultAutoCommit()
Get the value of defaultAutoCommit, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setAutoCommit(boolean). The default is true.

Returns:
value of defaultAutoCommit.

setDefaultAutoCommit

public void setDefaultAutoCommit(boolean v)
Set the value of defaultAutoCommit, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setAutoCommit(boolean). The default is true.

Parameters:
v - Value to assign to defaultAutoCommit.

isDefaultReadOnly

public boolean isDefaultReadOnly()
Get the value of defaultReadOnly, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setReadOnly(boolean). The default is false.

Returns:
value of defaultReadOnly.

setDefaultReadOnly

public void setDefaultReadOnly(boolean v)
Set the value of defaultReadOnly, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setReadOnly(boolean). The default is false.

Parameters:
v - Value to assign to defaultReadOnly.

getDataSourceName

public java.lang.String getDataSourceName()
Get the name of the ConnectionPoolDataSource which backs this pool. This name is used to look up the datasource from a jndi service provider.

Returns:
value of dataSourceName.

setDataSourceName

public void setDataSourceName(java.lang.String v)
Set the name of the ConnectionPoolDataSource which backs this pool. This name is used to look up the datasource from a jndi service provider.

Parameters:
v - Value to assign to dataSourceName.

getDescription

public java.lang.String getDescription()
Get the description. This property is defined by jdbc as for use with GUI (or other) tools that might deploy the datasource. It serves no internal purpose.

Returns:
value of description.

setDescription

public void setDescription(java.lang.String v)
Set the description. This property is defined by jdbc as for use with GUI (or other) tools that might deploy the datasource. It serves no internal purpose.

Parameters:
v - Value to assign to description.

getJndiEnvironment

public java.lang.String getJndiEnvironment(java.lang.String key)
Get the value of jndiEnvironment which is used when instantiating a jndi InitialContext. This InitialContext is used to locate the backend ConnectionPoolDataSource.

Parameters:
key - environment key
Returns:
value of jndiEnvironment.

setJndiEnvironment

public void setJndiEnvironment(java.lang.String key,
                               java.lang.String value)
Set the value of jndiEnvironment which is used when instantiating a jndi InitialContext. This InitialContext is used to locate the backend ConnectionPoolDataSource.

Parameters:
key - environment key
value - Value to assign to jndiEnvironment.

getConnectionPoolDataSource

public javax.sql.ConnectionPoolDataSource getConnectionPoolDataSource()
Get the value of connectionPoolDataSource. This method will return null, if the backing datasource is being accessed via jndi.

Returns:
value of connectionPoolDataSource.

setConnectionPoolDataSource

public void setConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource v)
Set the backend ConnectionPoolDataSource. This property should not be set if using jndi to access the datasource.

Parameters:
v - Value to assign to connectionPoolDataSource.

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Attempt to establish a database connection.

Specified by:
getConnection in interface javax.sql.DataSource
Returns:
A database connection.
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Attempt to establish a database connection.

Specified by:
getConnection in interface javax.sql.DataSource
Parameters:
username - The name of the database user.
password - The password of the database user.
Returns:
A database connection.
Throws:
java.sql.SQLException

getKey

private java.lang.String getKey(java.lang.String suffix)
Parameters:
suffix -
Returns:

registerPool

private void registerPool(java.lang.String username,
                          java.lang.String password)
                   throws javax.naming.NamingException
Parameters:
username - The name of the database user.
password - The password of the database user.
Throws:
javax.naming.NamingException

getLoginTimeout

public int getLoginTimeout()
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.

Specified by:
getLoginTimeout in interface javax.sql.DataSource
Returns:
the login timeout

getLogWriter

public java.io.PrintWriter getLogWriter()
Get the log writer for this data source.

Specified by:
getLogWriter in interface javax.sql.DataSource
Returns:
the log writer

setLoginTimeout

public void setLoginTimeout(int seconds)
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. NOT USED.

Specified by:
setLoginTimeout in interface javax.sql.DataSource
Parameters:
seconds - the login timeout

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
Set the log writer for this data source.

Specified by:
setLogWriter in interface javax.sql.DataSource
Parameters:
out - the log writer to use

getReference

public javax.naming.Reference getReference()
                                    throws javax.naming.NamingException
Referenceable implementation.

Specified by:
getReference in interface javax.naming.Referenceable
Returns:
a reference
Throws:
javax.naming.NamingException

getObjectInstance

public java.lang.Object getObjectInstance(java.lang.Object refObj,
                                          javax.naming.Name name,
                                          javax.naming.Context context,
                                          java.util.Hashtable env)
                                   throws java.lang.Exception
implements ObjectFactory to create an instance of this class

Specified by:
getObjectInstance in interface javax.naming.spi.ObjectFactory
Parameters:
refObj -
name -
context -
env -
Returns:
an instance of this class
Throws:
java.lang.Exception


Copyright © 1999-2003 Apache Software Foundation. All Rights Reserved.