org.objectweb.jonas.dbm
Class ConnectionManager

java.lang.Object
  extended byorg.objectweb.jonas.dbm.ConnectionManager
All Implemented Interfaces:
javax.sql.ConnectionEventListener, javax.sql.DataSource, java.util.EventListener, 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

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

Adriana Danes

03/01/13 - Manage datasource name additionally to the jndi name for the datasource using this ConnectionManager

03/04/08 - ConnectionManager extends ReconfigDispatcher in order to send reconfiguration Notifications to ReconfigManager

03/05/23 - Introduce pool size configuration

04/09/20 - Remove ReconfigDispatcher inheritance; management features moved to new MBeans (JSR77 JDBCDataSource, JDBCDriver)

See Also:
Serialized Form

Constructor Summary
ConnectionManager()
          Constructor for Factory
ConnectionManager(boolean isClient)
          Constructor for the client case
 
Method Summary
 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 getCurrentOpened()
          Method called by the a management method in the dbm service MBean
 java.lang.String getDataSourceDescription()
           
 java.lang.String getDatasourceName()
           
 java.lang.String getDSName()
           
 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()
           
 Pool getPool()
           
 javax.naming.Reference getReference()
          Retrieves the Reference of this object.
static org.objectweb.transaction.jta.ResourceManagerEventListener getResourceManagerEventListener()
           
 java.lang.String getTransactionIsolation()
           
 java.lang.String getUrl()
           
 java.lang.String getUserName()
           
 boolean isClientCase()
          This manager is in the client case or not ?
 void poolConfigure(java.lang.String connchecklevel, java.lang.String connmaxage, java.lang.String maxopentime, java.lang.String connteststmt, java.lang.String minconpool, java.lang.String maxconpool, java.lang.String maxwaittime, java.lang.String maxwaiters, java.lang.String samplingperiod)
          Configure the Connection pool.
 void setClassName(java.lang.String s)
           
 void setDataSourceDescription(java.lang.String dsDesc)
           
 void setDatasourceName(java.lang.String s)
           
 void setDSName(java.lang.String s)
           
 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.jta.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()
                  throws java.lang.Exception
Constructor for Factory


ConnectionManager

public ConnectionManager(boolean isClient)
                  throws java.lang.Exception
Constructor for the client case

Parameters:
isClient - true if this is the client case TODO : must be removed. A client can lookup a datasource
Method Detail

getPool

public Pool getPool()
Returns:
The pool associated to this datasource

isClientCase

public boolean isClientCase()
This manager is in the client case or not ?

Returns:
boolean true if this is the client case TODO : must be removed. A client can lookup a datasource

setRMEListener

public void setRMEListener(org.objectweb.transaction.jta.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()

setUrl

public void setUrl(java.lang.String s)

getClassName

public java.lang.String getClassName()

setClassName

public void setClassName(java.lang.String s)
                  throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

getUserName

public java.lang.String getUserName()

setUserName

public void setUserName(java.lang.String s)

getPassword

public java.lang.String getPassword()

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 maxopentime,
                          java.lang.String connteststmt,
                          java.lang.String minconpool,
                          java.lang.String maxconpool,
                          java.lang.String maxwaittime,
                          java.lang.String maxwaiters,
                          java.lang.String samplingperiod)
Configure the Connection pool. Called by the Container at init. Configuration can be set in datasource.properties files.

Parameters:
connchecklevel - JDBC connection checking level
connmaxage - JDBC connection maximum age
maxopentime - JDBC connection maximum open time
connteststmt - SQL query for test statement
minconpool - Min size for the connection pool
maxconpool - Max size for the connection pool
maxwaittime - Max time to wait for a connection (in seconds)
maxwaiters - Max nb of waiters for a connection
samplingperiod - sampling period in sec.

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:
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.jta.ResourceManagerEventListener getResourceManagerEventListener()

getDatasourceName

public java.lang.String getDatasourceName()
Returns:
datasource name

setDatasourceName

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

getDataSourceDescription

public java.lang.String getDataSourceDescription()
Returns:
the desrciption of this datasource

setDataSourceDescription

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

getCurrentOpened

public java.lang.Integer getCurrentOpened()
Method called by the a management method in the dbm service MBean

Returns:
Integer number of open connection in this ds