org.objectweb.jonas.resource.cm
Class ConnectionManagerImpl

java.lang.Object
  extended by org.objectweb.jonas.resource.cm.ConnectionManagerImpl
All Implemented Interfaces:
Serializable, EventListener, ConnectionEventListener, ConnectionManager, PoolMatchFactory, SQLManager, org.objectweb.jotm.TransactionResourceManager

public class ConnectionManagerImpl
extends Object
implements ConnectionEventListener, ConnectionManager, PoolMatchFactory, SQLManager, org.objectweb.jotm.TransactionResourceManager

Description of the ConnectionManagerImpl

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

Field Summary
static int JDBC_CHECK_CONNECTION
           
static int JDBC_KEEP_ALIVE
           
static int JDBC_NO_TEST
          Constants for use with JDBC connection level
static int JDBC_SEND_STATEMENT
           
static String LOCAL_TRANS_SUPPORT
          Rar supports local transactions
static String LOGGER
          This constant is used in the by the init method
static String LOGGER_FACTORY
          This constant is used in the by the init method
protected  Hashtable mc2mci
          This hashtable allows to find the list of connection handle associated to a ManagedConnection
static String NO_TRANS_SUPPORT
          Rar doesn't support transactions
static String POOL_LOGGER
          This constant is used in the by the init method
static org.objectweb.util.monolog.api.Logger poolTrace
          Pool infomation logger
static String PRINT_WRITER
          This constant is used in the by the init method
static int PSWRAP_1
          Constants to determine which PreparedStatement types to call
static int PSWRAP_2
           
static int PSWRAP_3
           
static int PSWRAP_4
           
static int PSWRAP_5
           
static String RESOURCE_ADAPTER
          This constant is used in the by the init method
static String RESOURCE_BUNDLE_NAME
          This constant is used in the by the init method
static String RESOURCE_MANAGER_EVENT_LISTENER
          This constant is used in the by the init method
protected  org.objectweb.transaction.jta.ResourceManagerEventListener rmel
          Used by the server to register connections when no transactionnal context exists
protected  org.objectweb.transaction.jta.TransactionManager tm
          The transaction manager in server
static org.objectweb.util.monolog.api.Logger trace
          Main logger
static String TRANSACTION_MANAGER
          This constant is used in the by the init method
static String XA_TRANS_SUPPORT
          Rar supports XA transactions
 
Constructor Summary
ConnectionManagerImpl(String transSupport)
          ConnectionManagerImpl constructor
 
Method Summary
 Object allocateConnection(ManagedConnectionFactory pMcf, ConnectionRequestInfo cxRequestInfo)
          The method allocateConnection gets called by the resource adapter's connection factory instance.
 void cleanResourceAdapter()
          Description of the Method
 void connectionClosed(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(ConnectionEvent event)
          The connectionErrorOccurred method indicates that the associated ManagedConnection instance is now invalid and unusable.
 Object createResource(Object hints)
          Call the ManagedConnectionFactory in order to create a new instance.
 void destroyPStmts(ManagedConnectionInfo mcinfo)
          Destroying of the PreparedStatement objects of the Pool
 int getCheckLevel()
           
 int getCurrentInTx()
           
 List getManagedConnectionsWithoutTransaction()
           
 int getMaxPstmtPoolSize()
           
 Pool getPool()
           
 PreparedStatement getPStatement(ManagedConnectionInfo mcinfo, Object conn, String user, String sql)
          IMPLEMENTATION OF INTERFACE SQLManager
 PreparedStatement getPStatement(ManagedConnectionInfo mcinfo, Object conn, String user, String sql, int autoGeneratedKeys)
          Get the specified PreparedStatement
 PreparedStatement getPStatement(ManagedConnectionInfo mcinfo, Object conn, String user, String sql, int[] columnIndexes)
          Get the specified PreparedStatement
 PreparedStatement getPStatement(ManagedConnectionInfo mcinfo, Object conn, String user, String sql, int resultSetType, int resultSetConcurrency)
          Get the specified PreparedStatement
 PreparedStatement getPStatement(ManagedConnectionInfo mcinfo, Object conn, String user, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)
          Get the specified PreparedStatement
 PreparedStatement getPStatement(ManagedConnectionInfo mcinfo, Object conn, String user, String sql, String[] columnNames)
          Get the specified PreparedStatement
 String getState(String prefix)
          Gets the State attribute of the ConnectionManagerImpl object
 List getSynchros()
           
 String getTestStatement()
           
 Map getUsedManagedConnections()
           
 String getXAName()
          Get the XAName to use
 void init(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(ConnectionEvent event)
          Notifies that a Resource Manager Local Transaction was committed on the ManagedConnection instance.
 void localTransactionRolledback(ConnectionEvent event)
          Notifies that a Resource Manager Local Transaction was rolled back on the ManagedConnection instance.
 void localTransactionStarted(ConnectionEvent event)
          Notifies that a Resource Manager Local Transaction was started on the ManagedConnection instance.
 boolean matchResource(Object res, Object hints)
          All method of the pool match to the right type of ManagedConnection because there is one pool by ManagedConnectionFactory.
 Object matchResource(Set res, Object hints)
          All method of the pool match to the right type of ManagedConnection because there is one pool by ManagedConnectionFactory.
 void registerXAResource(Properties tmProp)
          Register an XAResource with JOTM for recovery
 void releaseResource(Object rMc)
          Release the ManagedConnection object resource
 void returnXAResource(String rmName, XAResource rmXares)
          Called from JOTM to free the XAResource and associated Managed Connection when recovery is complete
 void setCheckLevel(int level)
           
 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 setMaxPstmtPoolSize(int maxPstmtPoolSize)
           
 void setPrintWriter(PrintWriter pw)
          Setters method to initialize the ConnectionManager The printwriter where event are logged
 void setResourceAdapter(ManagedConnectionFactory tmcf)
          Setters method to initialize the ConnectionManager The managedConnectionFactory instance of the resource which must be managed by this connectionManager
 void setResourceAdapter(ManagedConnectionFactory tmcf, ConnectionManagerPoolParams cmpp)
          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 setTestStatement(String stmt)
           
 void setTransactionManager(org.objectweb.transaction.jta.TransactionManager tm)
          Setters method to initialize the ConnectionManager The Transaction manager linked to this resource managed
 void setXAName(String xanm)
          Set the XAName to use
 String toString()
          Description of the Method
 void validateResource(Set res)
          If supported, call the ManagedConnectionFactory to validate the ManagedConnections
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

trace

public static org.objectweb.util.monolog.api.Logger trace
Main logger


poolTrace

public static org.objectweb.util.monolog.api.Logger poolTrace
Pool infomation logger


rmel

protected org.objectweb.transaction.jta.ResourceManagerEventListener rmel
Used by the server to register connections when no transactionnal context exists


tm

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


mc2mci

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


RESOURCE_BUNDLE_NAME

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

See Also:
Constant Field Values

LOGGER

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

See Also:
Constant Field Values

POOL_LOGGER

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

See Also:
Constant Field Values

LOGGER_FACTORY

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

See Also:
Constant Field Values

TRANSACTION_MANAGER

public static final 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 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 String RESOURCE_ADAPTER
This constant is used in the by the init method

See Also:
Constant Field Values

PRINT_WRITER

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

See Also:
Constant Field Values

NO_TRANS_SUPPORT

public static final String NO_TRANS_SUPPORT
Rar doesn't support transactions

See Also:
Constant Field Values

LOCAL_TRANS_SUPPORT

public static final String LOCAL_TRANS_SUPPORT
Rar supports local transactions

See Also:
Constant Field Values

XA_TRANS_SUPPORT

public static final String XA_TRANS_SUPPORT
Rar supports XA transactions

See Also:
Constant Field Values

PSWRAP_1

public static final int PSWRAP_1
Constants to determine which PreparedStatement types 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

JDBC_NO_TEST

public static final int JDBC_NO_TEST
Constants for use with JDBC connection level

See Also:
Constant Field Values

JDBC_CHECK_CONNECTION

public static final int JDBC_CHECK_CONNECTION
See Also:
Constant Field Values

JDBC_SEND_STATEMENT

public static final int JDBC_SEND_STATEMENT
See Also:
Constant Field Values

JDBC_KEEP_ALIVE

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

ConnectionManagerImpl

public ConnectionManagerImpl(String transSupport)
ConnectionManagerImpl constructor

Parameters:
transSupport - String defining level of support needed
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(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 - TransactionManager value

setResourceAdapter

public void setResourceAdapter(ManagedConnectionFactory tmcf)
                        throws Exception
Setters method to initialize the ConnectionManager The managedConnectionFactory instance of the resource which must be managed by this connectionManager

Parameters:
tmcf - The new ResourceAdapter value
Throws:
Exception - Description of Exception

setResourceAdapter

public void setResourceAdapter(ManagedConnectionFactory tmcf,
                               ConnectionManagerPoolParams cmpp)
                        throws Exception
Setters method to initialize the ConnectionManager The managedConnectionFactory instance of the resource which must be maneged by this connectionManager

Parameters:
tmcf - The ManagedConnectionFactory object
cmpp - The pool parameters
Throws:
Exception - Description of Exception

init

public void init(Context ctx)
          throws 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:
Exception - Description of Exception

cleanResourceAdapter

public void cleanResourceAdapter()
                          throws ResourceException
Description of the Method

Throws:
ResourceException - Description of Exception

allocateConnection

public Object allocateConnection(ManagedConnectionFactory pMcf,
                                 ConnectionRequestInfo cxRequestInfo)
                          throws ResourceException
The method allocateConnection gets called by the resource adapter's connection factory instance.

Specified by:
allocateConnection in interface ConnectionManager
Throws:
ResourceException
See Also:
ConnectionManager

matchResource

public boolean matchResource(Object res,
                             Object hints)
All method of the pool match to the right type of ManagedConnection because there is one pool by ManagedConnectionFactory.

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".
See Also:
org.objectweb.util.pool.api.PoolMatchFactory

matchResource

public Object matchResource(Set res,
                            Object hints)
                     throws Exception
All method of the pool match to the right type of ManagedConnection because there is one pool by ManagedConnectionFactory.

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:
Exception - Description of Exception
See Also:
org.objectweb.util.pool.api.PoolMatchFactory

createResource

public Object createResource(Object hints)
                      throws 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: ConnectionResourceHint

Specified by:
createResource in interface PoolMatchFactory
Parameters:
hints - The "properties" that the created Object should conform to.
Returns:
The created Object.
Throws:
Exception - if an error occurs
See Also:
org.objectweb.util.pool.api.PoolMatchFactory

validateResource

public void validateResource(Set res)
                      throws Exception
If supported, call the ManagedConnectionFactory to validate the ManagedConnections

Specified by:
validateResource in interface PoolMatchFactory
Parameters:
res - A set of Objects to test if matching with some "properties" specified by hints.
Throws:
Exception - Description of Exception
See Also:
org.objectweb.util.pool.api.PoolMatchFactory

getPStatement

public PreparedStatement getPStatement(ManagedConnectionInfo mcinfo,
                                       Object conn,
                                       String user,
                                       String sql)
                                throws SQLException
IMPLEMENTATION OF INTERFACE SQLManager

Specified by:
getPStatement in interface SQLManager
Parameters:
mcinfo - ManagedConnectionInfo
conn - Object connection
user - String
sql - String
Returns:
PreparedStatment
Throws:
SQLException - if an Exception occurs

getPStatement

public PreparedStatement getPStatement(ManagedConnectionInfo mcinfo,
                                       Object conn,
                                       String user,
                                       String sql,
                                       int resultSetType,
                                       int resultSetConcurrency)
                                throws SQLException
Description copied from interface: SQLManager
Get the specified PreparedStatement

Specified by:
getPStatement in interface SQLManager
Parameters:
mcinfo - ManagedConnectionInfo
conn - Object connection
user - String
sql - String
resultSetType - int
resultSetConcurrency - int
Returns:
PreparedStatment
Throws:
SQLException - if an Exception occurs

getPStatement

public PreparedStatement getPStatement(ManagedConnectionInfo mcinfo,
                                       Object conn,
                                       String user,
                                       String sql,
                                       int resultSetType,
                                       int resultSetConcurrency,
                                       int resultSetHoldability)
                                throws SQLException
Description copied from interface: SQLManager
Get the specified PreparedStatement

Specified by:
getPStatement in interface SQLManager
Parameters:
mcinfo - ManagedConnectionInfo
conn - Object connection
user - String
sql - String
resultSetType - int
resultSetConcurrency - int
resultSetHoldability - int
Returns:
PreparedStatment
Throws:
SQLException - if an Exception occurs

getPStatement

public PreparedStatement getPStatement(ManagedConnectionInfo mcinfo,
                                       Object conn,
                                       String user,
                                       String sql,
                                       int autoGeneratedKeys)
                                throws SQLException
Description copied from interface: SQLManager
Get the specified PreparedStatement

Specified by:
getPStatement in interface SQLManager
Parameters:
mcinfo - ManagedConnectionInfo
conn - Object connection
user - String
sql - String
autoGeneratedKeys - key
Returns:
PreparedStatment
Throws:
SQLException - if an Exception occurs

getPStatement

public PreparedStatement getPStatement(ManagedConnectionInfo mcinfo,
                                       Object conn,
                                       String user,
                                       String sql,
                                       int[] columnIndexes)
                                throws SQLException
Description copied from interface: SQLManager
Get the specified PreparedStatement

Specified by:
getPStatement in interface SQLManager
Parameters:
mcinfo - ManagedConnectionInfo
conn - Object connection
user - String
sql - String
columnIndexes - int []
Returns:
PreparedStatment
Throws:
SQLException - if an Exception occurs

getPStatement

public PreparedStatement getPStatement(ManagedConnectionInfo mcinfo,
                                       Object conn,
                                       String user,
                                       String sql,
                                       String[] columnNames)
                                throws SQLException
Description copied from interface: SQLManager
Get the specified PreparedStatement

Specified by:
getPStatement in interface SQLManager
Parameters:
mcinfo - ManagedConnectionInfo
conn - Object connection
user - String
sql - String
columnNames - String []
Returns:
PreparedStatment
Throws:
SQLException - if an Exception occurs

releaseResource

public void releaseResource(Object rMc)
                     throws Exception
Release the ManagedConnection object resource

Specified by:
releaseResource in interface PoolMatchFactory
Parameters:
rMc - Object to release
Throws:
Exception - if an Exception occurs

destroyPStmts

public void destroyPStmts(ManagedConnectionInfo mcinfo)
                   throws Exception
Destroying of the PreparedStatement objects of the Pool

Parameters:
mcinfo - ManagedConnection information
Throws:
Exception - Exception

connectionClosed

public void connectionClosed(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.

Specified by:
connectionClosed in interface ConnectionEventListener
See Also:
ConnectionEventListener

connectionErrorOccurred

public void connectionErrorOccurred(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..

Specified by:
connectionErrorOccurred in interface ConnectionEventListener
See Also:
ConnectionEventListener

localTransactionCommitted

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

Specified by:
localTransactionCommitted in interface ConnectionEventListener
See Also:
ConnectionEventListener

localTransactionRolledback

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

Specified by:
localTransactionRolledback in interface ConnectionEventListener
See Also:
ConnectionEventListener

localTransactionStarted

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

Specified by:
localTransactionStarted in interface ConnectionEventListener
See Also:
ConnectionEventListener

toString

public String toString()
Description of the Method

Overrides:
toString in class Object
Returns:
Description of the Returned Value

getState

public String getState(String prefix)
Gets the State attribute of the ConnectionManagerImpl object

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

setXAName

public void setXAName(String xanm)
Set the XAName to use

Parameters:
xanm - String of XA Name

getXAName

public String getXAName()
Get the XAName to use

Returns:
String of XA Name

registerXAResource

public void registerXAResource(Properties tmProp)
Register an XAResource with JOTM for recovery


returnXAResource

public void returnXAResource(String rmName,
                             XAResource rmXares)
Called from JOTM to free the XAResource and associated Managed Connection when recovery is complete

Specified by:
returnXAResource in interface org.objectweb.jotm.TransactionResourceManager
Parameters:
rmName - The Resource Manager to be unregistered.
rmXares - XAResource to be returned

getPool

public Pool getPool()

getCheckLevel

public int getCheckLevel()

setCheckLevel

public void setCheckLevel(int level)

getTestStatement

public String getTestStatement()

setTestStatement

public void setTestStatement(String stmt)

getCurrentInTx

public int getCurrentInTx()

getMaxPstmtPoolSize

public int getMaxPstmtPoolSize()
Specified by:
getMaxPstmtPoolSize in interface SQLManager
Returns:
Returns the maxPstmtPoolSize.

setMaxPstmtPoolSize

public void setMaxPstmtPoolSize(int maxPstmtPoolSize)
Parameters:
maxPstmtPoolSize - The maxPstmtPoolSize to set.

getSynchros

public List getSynchros()
Returns:
the synchros

getUsedManagedConnections

public Map getUsedManagedConnections()
Returns:
the used (within Transaction) MC (Transaction)

getManagedConnectionsWithoutTransaction

public List getManagedConnectionsWithoutTransaction()
Returns:
the mcs


Copyright © 2007 OW2 Consortium. All Rights Reserved.