org.ow2.jonas.resource.internal.cm
Class ConnectionManagerImpl

java.lang.Object
  extended by org.ow2.jonas.resource.internal.cm.ConnectionManagerImpl
All Implemented Interfaces:
Serializable, EventListener, ConnectionEventListener, ConnectionManager, PoolMatchFactory, SQLManager, TxResourceManager

public class ConnectionManagerImpl
extends Object
implements ConnectionEventListener, ConnectionManager, PoolMatchFactory, SQLManager, TxResourceManager

Description of the ConnectionManagerImpl

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

Field Summary
protected  boolean dummyPool
          True if the ConnectionManager pool is dummy.
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
           
protected  String jndiname
          The jndiname of the associated factory
static String JNDINAME
          This constant is used by the init method
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
protected  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
 void forceCloseConnection(int connectionId)
          force the close of the Connection identified by ots Id
 void freeXAResource(XAResource rmXares)
          Called from JOTM to free the XAResource and associated Managed Connection when recovery is complete
 int getCheckLevel()
           
 Map getConnectionDetails(int connectionId)
          Return a Map with details about a Connection
 int getCurrentInTx()
           
 List getManagedConnectionsWithoutTransaction()
           
 int getMaxPstmtPoolSize()
           
 int[] getOpenedConnections()
          return a list of idents that represent the connections opened for a given nb of seconds
 int[] getOpenedConnections(int usedTimeSec)
          return a list of idents that represent the connections opened for a given nb of seconds
 Pool getPool()
           
 PreparedStatement getPStatement(ManagedConnectionInfo mcinfo, Object conn, String user, String sql)
          Get the specified PreparedStatement
 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()
           
 ValidatingManagedConnectionFactory getValidatingMCFactory()
           
 String getXAName()
          Get the XAName to use
 void init(Context ctx, boolean generic)
          Called by ResourceUtility.createConnectionManager to initialize the ConnectionManager with the following parameters: RESOURCE_BUNDLE_NAME: Name of the resource bundle 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: for later connection enlistement.
 boolean isJdbcConnSetUp()
           
 boolean isObservable()
           
 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 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 setObservable(boolean observable)
           
 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 setTestStatement(String stmt)
           
 void setTransactionManager(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
 
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


dummyPool

protected boolean dummyPool
True if the ConnectionManager pool is dummy.


tm

protected 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


jndiname

protected String jndiname
The jndiname of the associated factory


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

JNDINAME

public static final String JNDINAME
This constant is used 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_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

setTransactionManager

public void setTransactionManager(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,
                 boolean generic)
          throws Exception
Called by ResourceUtility.createConnectionManager to initialize the ConnectionManager with the following parameters: RESOURCE_BUNDLE_NAME: Name of the resource bundle 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: for later connection enlistement. RESOURCE_ADAPTER: The managedConnectionFactory instance of the resource to be managed JNDINAME: JndiName from the factory associated with this ConnectionManager

Parameters:
ctx - Description of Parameter
generic - RA is generic: No actual pool of Connections
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

getValidatingMCFactory

public ValidatingManagedConnectionFactory getValidatingMCFactory()
Specified by:
getValidatingMCFactory in interface PoolMatchFactory
Returns:
the ValidatingManagedConnectionFactory if the RA implements it

getPStatement

public PreparedStatement getPStatement(ManagedConnectionInfo mcinfo,
                                       Object conn,
                                       String user,
                                       String sql)
                                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
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


freeXAResource

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

Specified by:
freeXAResource in interface TxResourceManager
Parameters:
rmName - The Resource Manager to be unregistered.
rmXares - XAResource to be returned

getPool

public Pool getPool()

isJdbcConnSetUp

public boolean isJdbcConnSetUp()

getCheckLevel

public int getCheckLevel()

setCheckLevel

public void setCheckLevel(int level)

getTestStatement

public String getTestStatement()

setTestStatement

public void setTestStatement(String stmt)

isObservable

public boolean isObservable()
Returns:
the observable

setObservable

public void setObservable(boolean observable)
Parameters:
observable - the observable to set

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.

getOpenedConnections

public int[] getOpenedConnections(int usedTimeSec)
return a list of idents that represent the connections opened for a given nb of seconds

Parameters:
usedTimeSec - nb of seconds the Connection has been opened
Returns:
array of idents representing the Connections

getOpenedConnections

public int[] getOpenedConnections()
return a list of idents that represent the connections opened for a given nb of seconds

Returns:
array of idents representing the Connections

forceCloseConnection

public void forceCloseConnection(int connectionId)
force the close of the Connection identified by ots Id

Parameters:
connectionId - int that represent the Connection

getConnectionDetails

public Map getConnectionDetails(int connectionId)
Return a Map with details about a Connection

Parameters:
connectionId - Ident that represent the connection
Returns:
map given the details about this connection.

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 © 2010 OW2 Consortium. All Rights Reserved.