org.objectweb.jonas.dbm
Class ConnectionManager

java.lang.Object
  |
  +--org.objectweb.jonas.dbm.ConnectionManager
All Implemented Interfaces:
javax.sql.ConnectionEventListener, ConnectionManagerMBean, javax.sql.DataSource, java.util.EventListener, JmxDataSourceMBean, javax.naming.Referenceable, java.io.Serializable

public class ConnectionManager
extends java.lang.Object
implements javax.sql.DataSource, javax.naming.Referenceable, java.io.Serializable, javax.sql.ConnectionEventListener, ConnectionManagerMBean

JOnAS generic implementation of DataSource to manage an underlying JDBC-XA driver (XADataSource, XAConnection, XAResource, ...) This class acts as a factory for Connection objects. Its main goal is to manage a pool of XAConnection objects, to avoid closing the actual Connection on DBMS, and to deal with distributed transactions. This DataSource is registered in JNDI (=> implements Referenceable)

Author:
Philippe Durieux Contributor(s): 00/01/08 Markus Fritz make connection pooling thread safe (with same tx) introduce MaxAge for connections optimize pooling add some 'paranoia code': test conns before returning them from the pool. 00/18/04 Jun Inamori (j-office@osa.att.ne.jp) For closing correctly all connections at server shutdown. 01/11/06 Christophe Ney cney@batisseurs.com for Lutris Technologies Added ResourceManagerListener mechanism. 02/01/15 Dean Jennings - Map instead of Hashtable for cmList 03/01/13 Adriana Danes - Manage datasource name additionally to the jndi name for the datasource using this ConnectionManager
See Also:
Serialized Form

Constructor Summary
ConnectionManager()
          Constructor for Factory
 
Method Summary
 java.lang.String _getDSName()
           
 void _setDSName(java.lang.String s)
           
 void closeAllConnection()
           
 void connectionClosed(javax.sql.ConnectionEvent event)
          Invoked when the application calls close() on its representation of the connection.
 void connectionErrorOccurred(javax.sql.ConnectionEvent event)
          Invoked when a fatal connection error occurs, just before an SQLException is thrown to the application.
 java.lang.String getClassName()
           
 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.
static ConnectionManager getConnectionManager(java.lang.String dsname)
          get the ConnectionManager matching the DataSource name
 java.lang.Integer getCurrentNumberOfJDBCConnectionOpen()
          MBean method:
 java.lang.String getDataSourceDescription()
          MBean Method:
 java.lang.String getDataSourceFactory()
          MBean method:
 java.lang.String getDatasourceName()
           
 java.lang.String getDataSourceType()
          Mbean Method: return the type of this data source
 java.lang.String getDataSourceXADataName()
          MBean method:
 java.lang.String getDSName()
          MBean method:
 java.lang.Integer getJDBCConnCheckLevel()
          MBean method:
 java.lang.Integer getJDBCConnMaxAge()
          MBean method:
 java.lang.Integer getJDBCDeadLockPool()
          MBean method:
 java.lang.Integer getJDBCLoopWaitPool()
          MBean method:
 java.lang.Integer getJDBCMaxConnPool()
          MBean method:
 java.lang.Integer getJDBCMinConnPool()
          MBean method:
 java.lang.Integer getJDBCSleepTimeOut()
          MBean method:
 java.lang.String getJDBCTestStatement()
          MBean method:
 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.
 java.lang.String getMapperName()
           
 java.lang.String getPassword()
           
 javax.naming.Reference getReference()
          Retrieves the Reference of this object.
static org.objectweb.transaction.api.ResourceManagerEventListener getResourceManagerEventListener()
           
 java.lang.String getTransactionIsolation()
           
 java.lang.String getUrl()
           
 java.lang.String getUserName()
           
 void poolConfigure(java.lang.String connchecklevel, java.lang.String connmaxage, java.lang.String connteststmt)
          Configure the Connection pool.
 void setClassName(java.lang.String s)
           
 void setDataSourceDescription(java.lang.String dsDesc)
          Management Method:
 void setDatasourceName(java.lang.String s)
           
 void setDataSourceXADataName(java.lang.String xaName)
          Management method:
 void setDSName(java.lang.String s)
           
 void setJDBCConnCheckLevel(java.lang.Integer level)
          MBean method:
 void setJDBCConnMaxAge(java.lang.Integer age)
          MBean method:
 void setJDBCDeadLockPool(java.lang.Integer size)
          MBean method: do nothing
 void setJDBCLoopWaitPool(java.lang.Integer size)
          MBean method: do nothing
 void setJDBCMaxConnPool(java.lang.Integer max)
          MBean method: do nothing
 void setJDBCMinConnPool(java.lang.Integer min)
          MBean method: do nothing
 void setJDBCSleepTimeOut(java.lang.Integer timeOut)
          MBean method: do nothing
 void setJDBCTestStatement(java.lang.String test)
          MBean method:
 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 setMapperName(java.lang.String mappername)
           
 void setPassword(java.lang.String s)
           
 void setRMEListener(org.objectweb.transaction.api.ResourceManagerEventListener rmel)
           
 void setTransactionIsolation(java.lang.String level)
           
 void setUrl(java.lang.String s)
           
 void setUserName(java.lang.String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionManager

public ConnectionManager()
Constructor for Factory
Method Detail

setRMEListener

public void setRMEListener(org.objectweb.transaction.api.ResourceManagerEventListener rmel)

_getDSName

public java.lang.String _getDSName()
Returns:
jndi name of the datasource

_setDSName

public void _setDSName(java.lang.String s)
Parameters:
s - jndi name for the datasource

getUrl

public java.lang.String getUrl()
Specified by:
getUrl in interface JmxDataSourceMBean
Following copied from interface: org.objectweb.jonas.dbm.JmxDataSourceMBean
Returns:
String data source url

setUrl

public void setUrl(java.lang.String s)

getClassName

public java.lang.String getClassName()
Specified by:
getClassName in interface JmxDataSourceMBean
Following copied from interface: org.objectweb.jonas.dbm.JmxDataSourceMBean
Returns:
String data source class name

setClassName

public void setClassName(java.lang.String s)

getUserName

public java.lang.String getUserName()
Specified by:
getUserName in interface JmxDataSourceMBean
Following copied from interface: org.objectweb.jonas.dbm.JmxDataSourceMBean
Returns:
String data source user

setUserName

public void setUserName(java.lang.String s)

getPassword

public java.lang.String getPassword()
Specified by:
getPassword in interface JmxDataSourceMBean
Following copied from interface: org.objectweb.jonas.dbm.JmxDataSourceMBean
Returns:
String data source password

setPassword

public void setPassword(java.lang.String s)

setTransactionIsolation

public void setTransactionIsolation(java.lang.String level)

getTransactionIsolation

public java.lang.String getTransactionIsolation()

setMapperName

public void setMapperName(java.lang.String mappername)

getMapperName

public java.lang.String getMapperName()

poolConfigure

public void poolConfigure(java.lang.String connchecklevel,
                          java.lang.String connmaxage,
                          java.lang.String connteststmt)
Configure the Connection pool. Called by the Container at init. Configuration can be set in datasource.properties files.

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 Connection to the database
Throws:
java.sql.SQLException - - if a database-access error occurs.

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:
user - - the database user on whose behalf the Connection is being made
password - - the user's password
Returns:
a Connection to the database
Throws:
java.sql.SQLException - - if a database-access error occurs.

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
Get the log writer for this data source. The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specificlog writer are not printed to the log writer associated with the Drivermanager class. When a data source object is created the log writer is initially null, in other words, logging is disabled.
Specified by:
getLogWriter in interface javax.sql.DataSource
Returns:
the log writer for this data source, null if disabled
Throws:
java.sql.SQLException - - if a database-access error occurs.

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException
Set the log writer for this data source. The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the Drivermanager class. When a data source object is created the log writer is initially null, in other words, logging is disabled.
Specified by:
setLogWriter in interface javax.sql.DataSource
Parameters:
out - - the new log writer; to disable, set to null
Throws:
java.sql.SQLException - - if a database-access error occurs.

setLoginTimeout

public void setLoginTimeout(int seconds)
                     throws java.sql.SQLException
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise it specifies that there is no timeout. When a data source object is created the login timeout is initially zero.
Specified by:
setLoginTimeout in interface javax.sql.DataSource
Parameters:
seconds - - the data source login time limit
Throws:
java.sql.SQLException - - if a database access error occurs.

getLoginTimeout

public int getLoginTimeout()
                    throws java.sql.SQLException
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. A value of zero means that the timeout is the default system timeout if there is one; otherwise it means that there is no timeout. When a data source object is created the login timeout is initially zero.
Specified by:
getLoginTimeout in interface javax.sql.DataSource
Returns:
the data source login time limit
Throws:
java.sql.SQLException - - if a database access error occurs.

connectionClosed

public void connectionClosed(javax.sql.ConnectionEvent event)
Invoked when the application calls close() on its representation of the connection.
Specified by:
connectionClosed in interface javax.sql.ConnectionEventListener
Parameters:
event - - an event object describing the source of the event

connectionErrorOccurred

public void connectionErrorOccurred(javax.sql.ConnectionEvent event)
Invoked when a fatal connection error occurs, just before an SQLException is thrown to the application.
Specified by:
connectionErrorOccurred in interface javax.sql.ConnectionEventListener
Parameters:
event - - an event object describing the source of the event

getReference

public javax.naming.Reference getReference()
                                    throws javax.naming.NamingException
Retrieves the Reference of this object. Used at binding time by JNDI to build a reference on this object.
Specified by:
getReference in interface javax.naming.Referenceable
Returns:
The non-null Reference of this object.
Throws:
javax.naming.NamingException - If a naming exception was encountered while retrieving the reference.

getConnectionManager

public static ConnectionManager getConnectionManager(java.lang.String dsname)
get the ConnectionManager matching the DataSource name

closeAllConnection

public void closeAllConnection()

getResourceManagerEventListener

public static org.objectweb.transaction.api.ResourceManagerEventListener getResourceManagerEventListener()

getCurrentNumberOfJDBCConnectionOpen

public java.lang.Integer getCurrentNumberOfJDBCConnectionOpen()
MBean method:
Specified by:
getCurrentNumberOfJDBCConnectionOpen in interface JmxDataSourceMBean
Returns:
Integer number of open connection in this ds

getDSName

public java.lang.String getDSName()
MBean method:
Specified by:
getDSName in interface JmxDataSourceMBean
Returns:
Jndi name of the datasource

setDSName

public void setDSName(java.lang.String s)
Parameters:
s - Jndi name of the datasource

getDatasourceName

public java.lang.String getDatasourceName()
Specified by:
getDatasourceName in interface JmxDataSourceMBean
Returns:
datasource name

setDatasourceName

public void setDatasourceName(java.lang.String s)
Parameters:
s - datasource name

getDataSourceFactory

public java.lang.String getDataSourceFactory()
MBean method:
Specified by:
getDataSourceFactory in interface JmxDataSourceMBean
Returns:
the data source factory none or JonasStandardXADataSource

setDataSourceXADataName

public void setDataSourceXADataName(java.lang.String xaName)
Management method:
Parameters:
the - DataSourceXAName

getDataSourceXADataName

public java.lang.String getDataSourceXADataName()
MBean method:
Specified by:
getDataSourceXADataName in interface JmxDataSourceMBean
Returns:
the DataSourceXAName

getJDBCConnCheckLevel

public java.lang.Integer getJDBCConnCheckLevel()
MBean method:
Specified by:
getJDBCConnCheckLevel in interface JmxDataSourceMBean
Returns:
connection level

setJDBCConnCheckLevel

public void setJDBCConnCheckLevel(java.lang.Integer level)
MBean method:
Specified by:
setJDBCConnCheckLevel in interface JmxDataSourceMBean
Parameters:
connection - level

getJDBCConnMaxAge

public java.lang.Integer getJDBCConnMaxAge()
MBean method:
Specified by:
getJDBCConnMaxAge in interface JmxDataSourceMBean
Returns:
connection max age

setJDBCConnMaxAge

public void setJDBCConnMaxAge(java.lang.Integer age)
MBean method:
Specified by:
setJDBCConnMaxAge in interface JmxDataSourceMBean
Parameters:
connection - max age

getJDBCTestStatement

public java.lang.String getJDBCTestStatement()
MBean method:
Specified by:
getJDBCTestStatement in interface JmxDataSourceMBean
Returns:
test statement

setJDBCTestStatement

public void setJDBCTestStatement(java.lang.String test)
MBean method:
Specified by:
setJDBCTestStatement in interface JmxDataSourceMBean
Parameters:
test - statement

getDataSourceType

public java.lang.String getDataSourceType()
Mbean Method: return the type of this data source
Specified by:
getDataSourceType in interface JmxDataSourceMBean

getDataSourceDescription

public java.lang.String getDataSourceDescription()
MBean Method:
Specified by:
getDataSourceDescription in interface JmxDataSourceMBean
Returns:
the desrciption of this datasource

setDataSourceDescription

public void setDataSourceDescription(java.lang.String dsDesc)
Management Method:
Parameters:
the - desrciption of this datasource

getJDBCMinConnPool

public java.lang.Integer getJDBCMinConnPool()
MBean method:
Specified by:
getJDBCMinConnPool in interface JmxDataSourceMBean
Returns:
null

setJDBCMinConnPool

public void setJDBCMinConnPool(java.lang.Integer min)
MBean method: do nothing
Specified by:
setJDBCMinConnPool in interface JmxDataSourceMBean
Parameters:
min -  

getJDBCMaxConnPool

public java.lang.Integer getJDBCMaxConnPool()
MBean method:
Specified by:
getJDBCMaxConnPool in interface JmxDataSourceMBean
Returns:
null

setJDBCMaxConnPool

public void setJDBCMaxConnPool(java.lang.Integer max)
MBean method: do nothing
Specified by:
setJDBCMaxConnPool in interface JmxDataSourceMBean
Parameters:
max -  

getJDBCSleepTimeOut

public java.lang.Integer getJDBCSleepTimeOut()
MBean method:
Specified by:
getJDBCSleepTimeOut in interface JmxDataSourceMBean
Returns:
null

setJDBCSleepTimeOut

public void setJDBCSleepTimeOut(java.lang.Integer timeOut)
MBean method: do nothing
Specified by:
setJDBCSleepTimeOut in interface JmxDataSourceMBean
Parameters:
timeout -  

getJDBCDeadLockPool

public java.lang.Integer getJDBCDeadLockPool()
MBean method:
Specified by:
getJDBCDeadLockPool in interface JmxDataSourceMBean
Returns:
null

setJDBCDeadLockPool

public void setJDBCDeadLockPool(java.lang.Integer size)
MBean method: do nothing
Specified by:
setJDBCDeadLockPool in interface JmxDataSourceMBean
Parameters:
size -  

getJDBCLoopWaitPool

public java.lang.Integer getJDBCLoopWaitPool()
MBean method:
Specified by:
getJDBCLoopWaitPool in interface JmxDataSourceMBean
Returns:
null

setJDBCLoopWaitPool

public void setJDBCLoopWaitPool(java.lang.Integer size)
MBean method: do nothing
Specified by:
setJDBCLoopWaitPool in interface JmxDataSourceMBean
Parameters:
size -