org.objectweb.jonas.resource
Class ConnectionManagerImpl

java.lang.Object
  extended byorg.objectweb.jonas.resource.ConnectionManagerImpl
All Implemented Interfaces:
javax.resource.spi.ConnectionEventListener, javax.resource.spi.ConnectionManager, java.util.EventListener, PoolMatchFactory, java.io.Serializable, SQLManager

public class ConnectionManagerImpl
extends java.lang.Object
implements javax.resource.spi.ConnectionEventListener, javax.resource.spi.ConnectionManager, PoolMatchFactory, SQLManager

Description of the ConnectionManagerImpl

Author:
chassand created 15 novembre 2001
See Also:
Serialized Form

Field Summary
protected  int jdbcConnLevel
          JDBC connection info
protected  java.lang.String jdbcConnTestStmt
           
static java.lang.String LOCAL_TRANS_SUPPORT
           
static java.lang.String LOGGER
          This constant is used in the by the init method
static java.lang.String LOGGER_FACTORY
          This constant is used in the by the init method
protected  int maxPstmtPoolSize
          These are the PrepareStatement pooling members
protected  java.util.Hashtable mc2mci
          This hashtable allows to find the list of connection handle associated to a ManagedConnection
protected  javax.resource.spi.ManagedConnectionFactory mcf
          The ManagedConnectionFactory instance which represents the resource adapter.
protected  int mcMaxPoolSize
          The max pool size of ManagedConnection.
protected  int mcMinPoolSize
          The min pool size of ManagedConnection.
protected  java.util.Vector mcs
          The list of managedConnection used without transaction
static java.lang.String NO_TRANS_SUPPORT
          These constants define the different transaction support values
static java.lang.String POOL_LOGGER
          This constant is used in the by the init method
protected  Pool poolMCs
          The pool of ManagedConnections associated to a ManagedConnectionFactory
protected  org.objectweb.util.monolog.api.Logger poolTrace
           
static java.lang.String PRINT_WRITER
          This constant is used in the by the init method
static int PSWRAP_1
          Constants to determine which PreparedStatement to call
static int PSWRAP_2
           
static int PSWRAP_3
           
static int PSWRAP_4
           
static int PSWRAP_5
           
static java.lang.String RESOURCE_ADAPTER
          This constant is used in the by the init method
static java.lang.String RESOURCE_BUNDLE_NAME
          This constant is used in the by the init method
static java.lang.String RESOURCE_MANAGER_EVENT_LISTENER
          This constant is used in the by the init method
protected  java.lang.String resourceBundleName
           
protected  org.objectweb.transaction.jta.ResourceManagerEventListener rmel
          This variable is used by the server to register connections when no transactionnal context exists
protected  ResourceSpec rs
          This is a cache to the last instance of ResourceSpec used by the ConnectionManager.
protected  java.util.Vector synchros
          The list of Synchronisation instance managed in this ConnectionManager
protected  org.objectweb.transaction.jta.TransactionManager tm
          The transaction manager in server
protected  org.objectweb.util.monolog.api.Logger trace
          The Logger instance where messages are written.
static java.lang.String TRANSACTION_MANAGER
          This constant is used in the by the init method
protected  java.lang.String transSupport
          The holds the transaction support level for the associated RAR file
protected  java.util.Hashtable usedMCs
          The list of used ManagedConnections key = transaction reference value = MCInfo
protected  javax.resource.spi.ValidatingManagedConnectionFactory vmcf
           
protected  java.util.Vector vPstmts
           
static java.lang.String XA_TRANS_SUPPORT
           
 
Constructor Summary
ConnectionManagerImpl(java.lang.String _transSupport)
           
 
Method Summary
 java.lang.Object allocateConnection(javax.resource.spi.ManagedConnectionFactory _mcf, javax.resource.spi.ConnectionRequestInfo cxRequestInfo)
          The method allocateConnection gets called by the resource adapter's connection factory instance.
 void cleanResourceAdapter()
          Description of the Method
 void connectionClosed(javax.resource.spi.ConnectionEvent event)
          IMPLEMENTATION OF INTERFACE ConnectionEventListener * A ManagedConnection instance calls the connectionClosed method to notify its registered set of listeners when an application component closes a connection handle.
 void connectionErrorOccurred(javax.resource.spi.ConnectionEvent event)
          The connectionErrorOccurred method indicates that the associated ManagedConnection instance is now invalid and unusable.
 java.lang.Object createResource(java.lang.Object hints)
          Call the ManagedConnectionFactory in order to create a new instance. of ManagedConnection.
 void destroyPStmts(MCInfo mcinfo)
           
 java.sql.PreparedStatement getPStatement(MCInfo mcinfo, java.lang.Object conn, java.lang.String user, java.lang.String sql)
          IMPLEMENTATION OF INTERFACE SQLManager
 java.sql.PreparedStatement getPStatement(MCInfo mcinfo, java.lang.Object conn, java.lang.String user, java.lang.String sql, int autoGeneratedKeys)
           
 java.sql.PreparedStatement getPStatement(MCInfo mcinfo, java.lang.Object conn, java.lang.String user, java.lang.String sql, int[] columnIndexes)
           
 java.sql.PreparedStatement getPStatement(MCInfo mcinfo, java.lang.Object conn, java.lang.String user, java.lang.String sql, int resultSetType, int resultSetConcurrency)
           
 java.sql.PreparedStatement getPStatement(MCInfo mcinfo, java.lang.Object conn, java.lang.String user, java.lang.String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
           
 java.sql.PreparedStatement getPStatement(MCInfo mcinfo, java.lang.Object conn, java.lang.String user, java.lang.String sql, java.lang.String[] columnNames)
           
protected  java.lang.String getState(java.lang.String prefix)
          Gets the State attribute of the ConnectionManagerImpl object
 void init(javax.naming.Context ctx)
          This method permits to initialize the ConnectionManager with the following parameter: RESOURCE_BUNDLE_NAME: The name of the resource bundle in order to internationalize the logging LOGGER: The logger instance where events are logged LOGGER_FACTORY: A logger factory to obtain a logger PRINT_WRITER: The printwriter where event are logged TRANSACTION_MANAGER: The Transaction manager linked to this resource manager RESOURCE_MANAGER_EVENT_LISTENER: The resource manage event listener which subscribed to later connection enlistement.
 void localTransactionCommitted(javax.resource.spi.ConnectionEvent event)
          Notifies that a Resource Manager Local Transaction was committed on the ManagedConnection instance.
 void localTransactionRolledback(javax.resource.spi.ConnectionEvent event)
          Notifies that a Resource Manager Local Transaction was rolled back on the ManagedConnection instance.
 void localTransactionStarted(javax.resource.spi.ConnectionEvent event)
          Notifies that a Resource Manager Local Transaction was started on the ManagedConnection instance.
 boolean matchResource(java.lang.Object res, java.lang.Object hints)
          All method of the pool match to the right type of ManagedConnection because there is one pool by ManagedConnectionFactory.
 java.lang.Object matchResource(java.util.Set res, java.lang.Object hints)
          All method of the pool match to the right type of ManagedConnection because there is one pool by ManagedConnectionFactory.
 void releaseResource(java.lang.Object _mc)
          releaseResource make sure that any cleanup needed for this entry is done
 void setLogger(org.objectweb.util.monolog.api.Logger l)
          Setters method to initialize the ConnectionManager The logger instance where events are logged
 void setLoggerFactory(org.objectweb.util.monolog.api.LoggerFactory lf)
          Setters method to initialize the ConnectionManager A logger factory to obtain a logger
 void setPrintWriter(java.io.PrintWriter pw)
          Setters method to initialize the ConnectionManager The printwriter where event are logged
 void setResourceAdapter(javax.resource.spi.ManagedConnectionFactory _mcf)
          Setters method to initialize the ConnectionManager The managedConnectionFactory instance of the resource which must be managed by this connectionManager
 void setResourceAdapter(javax.resource.spi.ManagedConnectionFactory _mcf, int initPoolSize, int minPoolSize, int maxPoolSize, int _maxPstmtPoolSize, long maxAge, int jConnLevel, java.lang.String jConnStmt)
          Setters method to initialize the ConnectionManager The managedConnectionFactory instance of the resource which must be maneged by this connectionManager
 void setResourceManagerEventListener(org.objectweb.transaction.jta.ResourceManagerEventListener _rmel)
          Setters method to initialize the ConnectionManager The logger instance where events are logged
 void setTransactionManager(org.objectweb.transaction.jta.TransactionManager _tm)
          Setters method to initialize the ConnectionManager The Transaction manager linked to this resource managed
 java.lang.String toString()
          Description of the Method
 void validateResource(java.util.Set res)
          If supported, call the ManagedConnectionFactory to validate the ManagedConnections see org.objectweb.util.pool.api.PoolMatchFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

trace

protected org.objectweb.util.monolog.api.Logger trace
The Logger instance where messages are written.


poolTrace

protected org.objectweb.util.monolog.api.Logger poolTrace

rmel

protected org.objectweb.transaction.jta.ResourceManagerEventListener rmel
This variable is used by the server to register connections when no transactionnal context exists


resourceBundleName

protected java.lang.String resourceBundleName

tm

protected org.objectweb.transaction.jta.TransactionManager tm
The transaction manager in server


mc2mci

protected java.util.Hashtable mc2mci
This hashtable allows to find the list of connection handle associated to a ManagedConnection


mcMaxPoolSize

protected int mcMaxPoolSize
The max pool size of ManagedConnection. The default value is -1.


mcMinPoolSize

protected int mcMinPoolSize
The min pool size of ManagedConnection. The default value is 0


mcf

protected javax.resource.spi.ManagedConnectionFactory mcf
The ManagedConnectionFactory instance which represents the resource adapter.


vmcf

protected javax.resource.spi.ValidatingManagedConnectionFactory vmcf

poolMCs

protected Pool poolMCs
The pool of ManagedConnections associated to a ManagedConnectionFactory


usedMCs

protected java.util.Hashtable usedMCs
The list of used ManagedConnections key = transaction reference value = MCInfo


maxPstmtPoolSize

protected int maxPstmtPoolSize
These are the PrepareStatement pooling members


vPstmts

protected java.util.Vector vPstmts

jdbcConnLevel

protected int jdbcConnLevel
JDBC connection info


jdbcConnTestStmt

protected java.lang.String jdbcConnTestStmt

mcs

protected java.util.Vector mcs
The list of managedConnection used without transaction


synchros

protected java.util.Vector synchros
The list of Synchronisation instance managed in this ConnectionManager


rs

protected ResourceSpec rs
This is a cache to the last instance of ResourceSpec used by the ConnectionManager. Indeed this instance is always the same.


transSupport

protected java.lang.String transSupport
The holds the transaction support level for the associated RAR file


RESOURCE_BUNDLE_NAME

public static final java.lang.String RESOURCE_BUNDLE_NAME
This constant is used in the by the init method

See Also:
Constant Field Values

LOGGER

public static final java.lang.String LOGGER
This constant is used in the by the init method

See Also:
Constant Field Values

POOL_LOGGER

public static final java.lang.String POOL_LOGGER
This constant is used in the by the init method

See Also:
Constant Field Values

LOGGER_FACTORY

public static final java.lang.String LOGGER_FACTORY
This constant is used in the by the init method

See Also:
Constant Field Values

TRANSACTION_MANAGER

public static final java.lang.String TRANSACTION_MANAGER
This constant is used in the by the init method

See Also:
Constant Field Values

RESOURCE_MANAGER_EVENT_LISTENER

public static final java.lang.String RESOURCE_MANAGER_EVENT_LISTENER
This constant is used in the by the init method

See Also:
Constant Field Values

RESOURCE_ADAPTER

public static final java.lang.String RESOURCE_ADAPTER
This constant is used in the by the init method

See Also:
Constant Field Values

PRINT_WRITER

public static final java.lang.String PRINT_WRITER
This constant is used in the by the init method

See Also:
Constant Field Values

NO_TRANS_SUPPORT

public static final java.lang.String NO_TRANS_SUPPORT
These constants define the different transaction support values

See Also:
Constant Field Values

LOCAL_TRANS_SUPPORT

public static final java.lang.String LOCAL_TRANS_SUPPORT
See Also:
Constant Field Values

XA_TRANS_SUPPORT

public static final java.lang.String XA_TRANS_SUPPORT
See Also:
Constant Field Values

PSWRAP_1

public static final int PSWRAP_1
Constants to determine which PreparedStatement to call

See Also:
Constant Field Values

PSWRAP_2

public static final int PSWRAP_2
See Also:
Constant Field Values

PSWRAP_3

public static final int PSWRAP_3
See Also:
Constant Field Values

PSWRAP_4

public static final int PSWRAP_4
See Also:
Constant Field Values

PSWRAP_5

public static final int PSWRAP_5
See Also:
Constant Field Values
Constructor Detail

ConnectionManagerImpl

public ConnectionManagerImpl(java.lang.String _transSupport)
Method Detail

setLogger

public void setLogger(org.objectweb.util.monolog.api.Logger l)
Setters method to initialize the ConnectionManager The logger instance where events are logged

Parameters:
l - The new Logger value

setLoggerFactory

public void setLoggerFactory(org.objectweb.util.monolog.api.LoggerFactory lf)
Setters method to initialize the ConnectionManager A logger factory to obtain a logger

Parameters:
lf - The new LoggerFactory value

setPrintWriter

public void setPrintWriter(java.io.PrintWriter pw)
Setters method to initialize the ConnectionManager The printwriter where event are logged

Parameters:
pw - The new PrintWriter value

setResourceManagerEventListener

public void setResourceManagerEventListener(org.objectweb.transaction.jta.ResourceManagerEventListener _rmel)
Setters method to initialize the ConnectionManager The logger instance where events are logged

Parameters:
_rmel - The new ResourceManagerEventListener value

setTransactionManager

public void setTransactionManager(org.objectweb.transaction.jta.TransactionManager _tm)
Setters method to initialize the ConnectionManager The Transaction manager linked to this resource managed

Parameters:
_tm - The new TransactionManager value

setResourceAdapter

public void setResourceAdapter(javax.resource.spi.ManagedConnectionFactory _mcf)
                        throws java.lang.Exception
Setters method to initialize the ConnectionManager The managedConnectionFactory instance of the resource which must be managed by this connectionManager

Parameters:
_mcf - The new ResourceAdapter value
Throws:
java.lang.Exception - Description of Exception

setResourceAdapter

public void setResourceAdapter(javax.resource.spi.ManagedConnectionFactory _mcf,
                               int initPoolSize,
                               int minPoolSize,
                               int maxPoolSize,
                               int _maxPstmtPoolSize,
                               long maxAge,
                               int jConnLevel,
                               java.lang.String jConnStmt)
                        throws java.lang.Exception
Setters method to initialize the ConnectionManager The managedConnectionFactory instance of the resource which must be maneged by this connectionManager

Parameters:
_mcf - The new ResourceAdapter value
initPoolSize - The initial pool size
minPoolSize - The min pool size
maxPoolSize - The max pool size
_maxPstmtPoolSize - The max prepared statement pool size
Throws:
java.lang.Exception - Description of Exception

init

public void init(javax.naming.Context ctx)
          throws java.lang.Exception
This method permits to initialize the ConnectionManager with the following parameter: RESOURCE_BUNDLE_NAME: The name of the resource bundle in order to internationalize the logging LOGGER: The logger instance where events are logged LOGGER_FACTORY: A logger factory to obtain a logger PRINT_WRITER: The printwriter where event are logged TRANSACTION_MANAGER: The Transaction manager linked to this resource manager RESOURCE_MANAGER_EVENT_LISTENER: The resource manage event listener which subscribed to later connection enlistement. RESOURCE_ADAPTER: The managedConnectionFactory instance of the resource which must be maneged by this connectionManager

Parameters:
ctx - Description of Parameter
Throws:
java.lang.Exception - Description of Exception

cleanResourceAdapter

public void cleanResourceAdapter()
                          throws javax.resource.ResourceException
Description of the Method

Throws:
javax.resource.ResourceException - Description of Exception

allocateConnection

public java.lang.Object allocateConnection(javax.resource.spi.ManagedConnectionFactory _mcf,
                                           javax.resource.spi.ConnectionRequestInfo cxRequestInfo)
                                    throws javax.resource.ResourceException
The method allocateConnection gets called by the resource adapter's connection factory instance. see javax.resource.cci.ConnectionManager

Specified by:
allocateConnection in interface javax.resource.spi.ConnectionManager
Throws:
javax.resource.ResourceException

matchResource

public boolean matchResource(java.lang.Object res,
                             java.lang.Object hints)
All method of the pool match to the right type of ManagedConnection because there is one pool by ManagedConnectionFactory. see org.objectweb.util.pool.api.PoolMatchFactory

Specified by:
matchResource in interface PoolMatchFactory
Parameters:
res - The Object to test its matching with some "properties" specified by hints.
hints - The "properties" that the Object specified by pr should match.
Returns:
true if the pr Object matches the hints "properties".

matchResource

public java.lang.Object matchResource(java.util.Set res,
                                      java.lang.Object hints)
                               throws java.lang.Exception
All method of the pool match to the right type of ManagedConnection because there is one pool by ManagedConnectionFactory. see org.objectweb.util.pool.api.PoolMatchFactory

Specified by:
matchResource in interface PoolMatchFactory
Parameters:
res - A set of Objects to test if matching with some "properties" specified by hints.
hints - The "properties" that the Object specified by pr should match.
Returns:
Object that matches the hints "properties". or null if no match.
Throws:
java.lang.Exception - Description of Exception

createResource

public java.lang.Object createResource(java.lang.Object hints)
                                throws java.lang.Exception
Call the ManagedConnectionFactory in order to create a new instance. of ManagedConnection. The Object is a ManagedConnection instance. The hints is a local structure: ResourceSpec see org.objectweb.util.pool.api.PoolMatchFactory

Specified by:
createResource in interface PoolMatchFactory
Parameters:
hints - The "properties" that the created Object should conform to.
Returns:
The created Object.
Throws:
java.lang.Exception

validateResource

public void validateResource(java.util.Set res)
                      throws java.lang.Exception
If supported, call the ManagedConnectionFactory to validate the ManagedConnections see org.objectweb.util.pool.api.PoolMatchFactory

Specified by:
validateResource in interface PoolMatchFactory
Parameters:
res - A set of Objects to test if matching with some "properties" specified by hints.
Throws:
java.lang.Exception - Description of Exception

getPStatement

public java.sql.PreparedStatement getPStatement(MCInfo mcinfo,
                                                java.lang.Object conn,
                                                java.lang.String user,
                                                java.lang.String sql)
                                         throws java.sql.SQLException
IMPLEMENTATION OF INTERFACE SQLManager

Specified by:
getPStatement in interface SQLManager
Throws:
java.sql.SQLException

getPStatement

public java.sql.PreparedStatement getPStatement(MCInfo mcinfo,
                                                java.lang.Object conn,
                                                java.lang.String user,
                                                java.lang.String sql,
                                                int resultSetType,
                                                int resultSetConcurrency)
                                         throws java.sql.SQLException
Specified by:
getPStatement in interface SQLManager
Throws:
java.sql.SQLException

getPStatement

public java.sql.PreparedStatement getPStatement(MCInfo mcinfo,
                                                java.lang.Object conn,
                                                java.lang.String user,
                                                java.lang.String sql,
                                                int resultSetType,
                                                int resultSetConcurrency,
                                                int resultSetHoldability)
                                         throws java.sql.SQLException
Specified by:
getPStatement in interface SQLManager
Throws:
java.sql.SQLException

getPStatement

public java.sql.PreparedStatement getPStatement(MCInfo mcinfo,
                                                java.lang.Object conn,
                                                java.lang.String user,
                                                java.lang.String sql,
                                                int autoGeneratedKeys)
                                         throws java.sql.SQLException
Specified by:
getPStatement in interface SQLManager
Throws:
java.sql.SQLException

getPStatement

public java.sql.PreparedStatement getPStatement(MCInfo mcinfo,
                                                java.lang.Object conn,
                                                java.lang.String user,
                                                java.lang.String sql,
                                                int[] columnIndexes)
                                         throws java.sql.SQLException
Specified by:
getPStatement in interface SQLManager
Throws:
java.sql.SQLException

getPStatement

public java.sql.PreparedStatement getPStatement(MCInfo mcinfo,
                                                java.lang.Object conn,
                                                java.lang.String user,
                                                java.lang.String sql,
                                                java.lang.String[] columnNames)
                                         throws java.sql.SQLException
Specified by:
getPStatement in interface SQLManager
Throws:
java.sql.SQLException

releaseResource

public void releaseResource(java.lang.Object _mc)
                     throws java.lang.Exception
Description copied from interface: PoolMatchFactory
releaseResource make sure that any cleanup needed for this entry is done

Specified by:
releaseResource in interface PoolMatchFactory
Parameters:
_mc - The Object to release
Throws:
java.lang.Exception - Description of Exception

destroyPStmts

public void destroyPStmts(MCInfo mcinfo)
                   throws java.lang.Exception
Throws:
java.lang.Exception

connectionClosed

public void connectionClosed(javax.resource.spi.ConnectionEvent event)
IMPLEMENTATION OF INTERFACE ConnectionEventListener * A ManagedConnection instance calls the connectionClosed method to notify its registered set of listeners when an application component closes a connection handle. The application server uses this connection close event to make a decision on whether or not to put the ManagedConnection instance back into the connection pool. see javax.resource.spi.ConnectionEventListener

Specified by:
connectionClosed in interface javax.resource.spi.ConnectionEventListener

connectionErrorOccurred

public void connectionErrorOccurred(javax.resource.spi.ConnectionEvent event)
The connectionErrorOccurred method indicates that the associated ManagedConnection instance is now invalid and unusable. The application server handles the connection error event notification by initiating application server-specific cleanup (for example, removing ManagedConnection instance from the connection pool) and then calling ManagedConnection.destroy method to destroy the physical connection.. see javax.resource.spi.ConnectionEventListener

Specified by:
connectionErrorOccurred in interface javax.resource.spi.ConnectionEventListener

localTransactionCommitted

public void localTransactionCommitted(javax.resource.spi.ConnectionEvent event)
Notifies that a Resource Manager Local Transaction was committed on the ManagedConnection instance. see javax.resource.spi.ConnectionEventListener

Specified by:
localTransactionCommitted in interface javax.resource.spi.ConnectionEventListener

localTransactionRolledback

public void localTransactionRolledback(javax.resource.spi.ConnectionEvent event)
Notifies that a Resource Manager Local Transaction was rolled back on the ManagedConnection instance. see javax.resource.spi.ConnectionEventListener

Specified by:
localTransactionRolledback in interface javax.resource.spi.ConnectionEventListener

localTransactionStarted

public void localTransactionStarted(javax.resource.spi.ConnectionEvent event)
Notifies that a Resource Manager Local Transaction was started on the ManagedConnection instance. see javax.resource.spi.ConnectionEventListener

Specified by:
localTransactionStarted in interface javax.resource.spi.ConnectionEventListener

toString

public java.lang.String toString()
Description of the Method

Returns:
Description of the Returned Value

getState

protected java.lang.String getState(java.lang.String prefix)
Gets the State attribute of the ConnectionManagerImpl object

Parameters:
prefix - Description of Parameter
Returns:
The State value