org.objectweb.cjdbc.controller.connection
Class AbstractConnectionManager

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.connection.AbstractConnectionManager
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AbstractPoolConnectionManager, SimpleConnectionManager

public abstract class AbstractConnectionManager
extends java.lang.Object
implements java.io.Serializable

A ConnectionManager object is responsible to talk directly with a database backend.

Version:
1.0
Author:
Emmanuel Cecchet, Mathieu Peltier, Nicolas Modrzyk
See Also:
Serialized Form

Field Summary
protected  java.lang.String backendName
          Name of the DatabaseBackend owning this connection manager.
protected  java.lang.String backendUrl
          URL of the DatabaseBackend owning this connection manager.
private  java.util.Hashtable connectionForTransaction
          Hastable of connections associated to a transaction.
protected  boolean initialized
          true if the connection pool has been initialized.
(package private) static Trace logger
          Logger instance.
protected  java.lang.String rLogin
          Backend connection login to be used by this connection manager.
protected  java.lang.String rPassword
          Backend connection password to be used by this connection manager.
 
Constructor Summary
AbstractConnectionManager(java.lang.String backendUrl, java.lang.String backendName, java.lang.String rLogin, java.lang.String rPassword)
          Creates a new AbstractConnectionManager instance: assigns login/password and instanciates transaction id/connection mapping.
 
Method Summary
protected  void finalize()
          Ensures that the connections are closed when the object is garbage collected.
abstract  void finalizeConnections()
          Releases all the connections to the database.
abstract  java.sql.Connection getConnection()
          Gets a connection from the pool (round-robin).
 java.sql.Connection getConnection(int transactionId)
          Gets a new connection for a transaction.
abstract  java.lang.String getInformation()
          Gets information about this connection manager
 java.lang.String getLogin()
          Returns the login used by this connection manager.
 java.lang.String getPassword()
          Returns the password used by this connection manager.
abstract  java.lang.String getXmlInformation()
          Gets xml formatted information on this connection manager
abstract  void initializeConnections()
          Initializes the connection(s) to the database.
 boolean isInitialized()
          Tests if the connections have been initialized.
abstract  void releaseConnection(java.sql.Connection connection)
          Releases a connection.
 void releaseConnection(int transactionId)
          Releases a connection used for a transaction.
 java.sql.Connection retrieveConnection(int transactionId)
          Retrieves a connection used for a transaction.
 void setLogin(java.lang.String rLogin)
          Sets the login to be used by this connection manager.
 void setPassword(java.lang.String rPassword)
          Sets the password to be used by this connection manager.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static Trace logger
Logger instance.


backendUrl

protected java.lang.String backendUrl
URL of the DatabaseBackend owning this connection manager.


backendName

protected java.lang.String backendName
Name of the DatabaseBackend owning this connection manager.


rLogin

protected java.lang.String rLogin
Backend connection login to be used by this connection manager.


rPassword

protected java.lang.String rPassword
Backend connection password to be used by this connection manager.


initialized

protected boolean initialized
true if the connection pool has been initialized.


connectionForTransaction

private transient java.util.Hashtable connectionForTransaction
Hastable of connections associated to a transaction.

Constructor Detail

AbstractConnectionManager

public AbstractConnectionManager(java.lang.String backendUrl,
                                 java.lang.String backendName,
                                 java.lang.String rLogin,
                                 java.lang.String rPassword)
Creates a new AbstractConnectionManager instance: assigns login/password and instanciates transaction id/connection mapping.

Parameters:
backendUrl - URL of the DatabaseBackend owning this connection manager
backendName - name of the DatabaseBackend owning this connection manager
rLogin - backend connection login to be used by this connection manager
rPassword - backend connection password to be used by this connection manager
Method Detail

initializeConnections

public abstract void initializeConnections()
                                    throws java.sql.SQLException
Initializes the connection(s) to the database. The caller must ensure that the driver has already been loaded else an exception will be thrown.

Throws:
java.sql.SQLException - if an error occurs.

finalizeConnections

public abstract void finalizeConnections()
                                  throws java.sql.SQLException
Releases all the connections to the database.

Throws:
java.sql.SQLException - if an error occurs.

getConnection

public abstract java.sql.Connection getConnection()
Gets a connection from the pool (round-robin).

Returns:
a Connection or null if no connection is available or if the connection has not been initialized.

getConnection

public java.sql.Connection getConnection(int transactionId)
Gets a new connection for a transaction. This function calls getConnection() to get the connection and store the mapping between the connection and the transaction id.

Parameters:
transactionId - the transaction id.
Returns:
a Connection or null if no connection is available .
See Also:
getConnection()

retrieveConnection

public java.sql.Connection retrieveConnection(int transactionId)
Retrieves a connection used for a transaction. This connection must have been allocated by calling getConnection(int).

Parameters:
transactionId - the transaction id.
Returns:
a Connection or null if no connection has been found for this transaction id.
See Also:
getConnection(int)

releaseConnection

public abstract void releaseConnection(java.sql.Connection connection)
Releases a connection.

Parameters:
connection - the connection to release.

releaseConnection

public void releaseConnection(int transactionId)
Releases a connection used for a transaction. The corresponding connection is released by calling releaseConnection(Connection).

Parameters:
transactionId - the transaction id.
See Also:
releaseConnection(Connection)

isInitialized

public boolean isInitialized()
Tests if the connections have been initialized.

Returns:
true if the connections have been initialized.

getLogin

public java.lang.String getLogin()
Returns the login used by this connection manager.

Returns:
a String value.

setLogin

public void setLogin(java.lang.String rLogin)
Sets the login to be used by this connection manager.

Parameters:
rLogin - the login to set.

getPassword

public java.lang.String getPassword()
Returns the password used by this connection manager.

Returns:
a String value.

setPassword

public void setPassword(java.lang.String rPassword)
Sets the password to be used by this connection manager.

Parameters:
rPassword - the password to set.

getXmlInformation

public abstract java.lang.String getXmlInformation()
Gets xml formatted information on this connection manager

Returns:
xml formatted string that conforms to c-jdbc.dtd

getInformation

public abstract java.lang.String getInformation()
Gets information about this connection manager

Returns:
a String value containing information.

finalize

protected void finalize()
                 throws java.lang.Throwable
Ensures that the connections are closed when the object is garbage collected.

Throws:
java.lang.Throwable - if an error occurs.


Copyright © 2002, 2003 - ObjectWeb Consortium - All Rights Reserved.