tyrex.resource.jdbc
Class ConnectionPool

java.lang.Object
  extended bytyrex.resource.PoolMetrics
      extended bytyrex.resource.jdbc.ConnectionPool
All Implemented Interfaces:
javax.sql.ConnectionEventListener, javax.sql.DataSource, java.util.EventListener, Resource, java.lang.Runnable

final class ConnectionPool
extends PoolMetrics
implements Resource, javax.sql.DataSource, javax.sql.ConnectionEventListener, java.lang.Runnable

Version:
$Revision: 1.21 $
Author:
Assaf Arkin

Field Summary
(package private)  Category _category
          The category used for writing log information.
(package private) static int AVAILABLE
          Flag that signifies that the pooled connection is available
(package private) static int CLOSED
          Flag that signifies that the connection from the pooled connection has been closed but the pooled connection is not available
(package private) static int IN_USE
          Flag that signifies that the pooled connection is not available
static int TABLE_SIZE
          The initial table size, unless a maximum number of connections is specified.
 
Fields inherited from class tyrex.resource.PoolMetrics
_available, _total
 
Constructor Summary
(package private) ConnectionPool(java.lang.String name, PoolLimits limits, java.lang.ClassLoader loader, javax.sql.XADataSource xaDataSource, javax.sql.ConnectionPoolDataSource poolDataSource, TyrexTransactionManager txManager, Category category)
           
 
Method Summary
 void connectionClosed(javax.sql.ConnectionEvent event)
           
 void connectionErrorOccurred(javax.sql.ConnectionEvent event)
           
 void destroy()
          Called to destory the resource once it is no longer in use.
protected  long expire()
          Called periodically to expire connections that have been available in the pool for longer than maxRetain seconds.
 java.lang.Object getClientFactory()
          Returns the client connection factory.
 java.lang.Class getClientFactoryClass()
          Returns the client connection factory class.
 java.sql.Connection getConnection()
           
 java.sql.Connection getConnection(java.lang.String user, java.lang.String password)
           
 int getLoginTimeout()
           
 java.io.PrintWriter getLogWriter()
           
 PoolLimits getPoolLimits()
          Returns the limits placed on the connection pool.
 PoolMetrics getPoolMetrics()
          Returns the pool metrics.
 javax.transaction.xa.XAResource getXAResource()
          Returns the XA resource interface.
(package private)  boolean release(javax.sql.PooledConnection pooled, boolean success)
          Releases a connection.
 void run()
           
 void setLoginTimeout(int seconds)
           
 void setLogWriter(java.io.PrintWriter logWriter)
           
 java.lang.String toString()
           
 
Methods inherited from class tyrex.resource.PoolMetrics
getAvailable, getCurrentUnused, getCurrentUsed, getTotal, getTotalCreated, getTotalDiscarded, getTotalErrors, getTotalUsed, getUnusedAvgDuration, getUsedAvgDuration, recordCreated, recordDiscard, recordError, recordUnusedDuration, recordUsedDuration, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

AVAILABLE

static final int AVAILABLE
Flag that signifies that the pooled connection is available

See Also:
Constant Field Values

IN_USE

static final int IN_USE
Flag that signifies that the pooled connection is not available

See Also:
Constant Field Values

CLOSED

static final int CLOSED
Flag that signifies that the connection from the pooled connection has been closed but the pooled connection is not available

See Also:
Constant Field Values

TABLE_SIZE

public static final int TABLE_SIZE
The initial table size, unless a maximum number of connections is specified.

See Also:
Constant Field Values

_category

final Category _category
The category used for writing log information.

Constructor Detail

ConnectionPool

ConnectionPool(java.lang.String name,
               PoolLimits limits,
               java.lang.ClassLoader loader,
               javax.sql.XADataSource xaDataSource,
               javax.sql.ConnectionPoolDataSource poolDataSource,
               TyrexTransactionManager txManager,
               Category category)
         throws ResourceException
Method Detail

getPoolMetrics

public PoolMetrics getPoolMetrics()
Description copied from interface: Resource
Returns the pool metrics. The pool metrics object can be used to collect statistical information about the connection pool.

Specified by:
getPoolMetrics in interface Resource
Returns:
The pool metrics

getPoolLimits

public PoolLimits getPoolLimits()
Description copied from interface: Resource
Returns the limits placed on the connection pool. This object can be used to investigate the limits of the connection pool and to change them at run time.

Specified by:
getPoolLimits in interface Resource
Returns:
The limits placed on the connection pool

getClientFactory

public java.lang.Object getClientFactory()
Description copied from interface: Resource
Returns the client connection factory. The client connection factory is enlisted in the JNDI environment naming context for access by the application.

Specified by:
getClientFactory in interface Resource
Returns:
The client connection factory

getClientFactoryClass

public java.lang.Class getClientFactoryClass()
Description copied from interface: Resource
Returns the client connection factory class. This the class or interface that a client connection factory would implement.

Specified by:
getClientFactoryClass in interface Resource
Returns:
The client connection factory class

toString

public java.lang.String toString()

getXAResource

public javax.transaction.xa.XAResource getXAResource()
Description copied from interface: Resource
Returns the XA resource interface. The XA resource is used to manage transaction enlistment and recovery of the resource. This method returns null if the resource does not support XA transactions.

Specified by:
getXAResource in interface Resource
Returns:
The XA resource interface

destroy

public void destroy()
Description copied from interface: Resource
Called to destory the resource once it is no longer in use. After successful return from this method, all open connections are invalidated and no new connections can be obtained from the pool.

The application server must render the connection factory inaccessible to the application before calling this method.

Specified by:
destroy in interface Resource

run

public void run()
Specified by:
run in interface java.lang.Runnable

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(java.lang.String user,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getLogWriter

public java.io.PrintWriter getLogWriter()
Specified by:
getLogWriter in interface javax.sql.DataSource

setLogWriter

public void setLogWriter(java.io.PrintWriter logWriter)
Specified by:
setLogWriter in interface javax.sql.DataSource

getLoginTimeout

public int getLoginTimeout()
Specified by:
getLoginTimeout in interface javax.sql.DataSource

setLoginTimeout

public void setLoginTimeout(int seconds)
Specified by:
setLoginTimeout in interface javax.sql.DataSource

connectionClosed

public void connectionClosed(javax.sql.ConnectionEvent event)
Specified by:
connectionClosed in interface javax.sql.ConnectionEventListener

connectionErrorOccurred

public void connectionErrorOccurred(javax.sql.ConnectionEvent event)
Specified by:
connectionErrorOccurred in interface javax.sql.ConnectionEventListener

release

boolean release(javax.sql.PooledConnection pooled,
                boolean success)
Releases a connection. The connection is returned to the pool and becomes available for subsequent use.

This method returns true if the connection was used and is now available. It returns false if the connection was not found in the pool.

The XA resource, if available, is delisted from the transaction manager and dissociated from the thread context.

If success is false, it assumes the connection has been released due to an error. There is no need to discard a connection released with an error.

Parameters:
pooled - The pooled connection to release
success - True if the connection is useable, false if the connection is released due to an error
Returns:
True if the connection has been released

expire

protected long expire()
Called periodically to expire connections that have been available in the pool for longer than maxRetain seconds. This method returns the next expiration time, or zero if no connection is expected to expire soon.

Returns:
The next expiration time, or zero if no connection is expected to expire soon.


Original code is Copyright (c) 1999-2001, Intalio, Inc. All Rights Reserved. Contributions by MetaBoss team are Copyright (c) 2003-2005, Softaris Pty. Ltd. All Rights Reserved.