org.objectweb.cjdbc.controller.connection
Class AbstractConnectionManager

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

public abstract class AbstractConnectionManager
extends java.lang.Object
implements XmlComponent, java.lang.Cloneable

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

Version:
1.0
Author:
Emmanuel Cecchet , Mathieu Peltier , Nicolas Modrzyk

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  java.lang.String driverClassName
          The class name of the driver
protected  java.lang.String driverPath
          The path to the driver if null the default directory is used
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.
private  java.lang.String vLogin
          Virtual Login to be that use this connection manager
 
Fields inherited from interface org.objectweb.cjdbc.common.xml.XmlComponent
DOCTYPE_CONTROLLER, DOCTYPE_DB, XML_VERSION
 
Constructor Summary
AbstractConnectionManager(java.lang.String backendUrl, java.lang.String backendName, java.lang.String rLogin, java.lang.String rPassword, java.lang.String driverPath, java.lang.String driverClassName)
          Creates a new AbstractConnectionManager instance: assigns login/password and instanciates transaction id/connection mapping.
 
Method Summary
protected abstract  java.lang.Object clone()
           
 AbstractConnectionManager copy(java.lang.String url, java.lang.String name)
          Copy this connection manager and replace the name of the backend and its url Every other parameter is the same
abstract  void deleteConnection(java.sql.Connection connection)
          Delete a connection that is no more valid.
 void deleteConnection(long transactionId)
          Delete a bad connection that was used for a transaction.
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(long transactionId)
          Gets a new connection for a transaction.
 java.sql.Connection getConnectionFromDriver()
          Get a connection from DriverManager.
abstract  int getCurrentNumberOfConnections()
          Get the current number of connections open for this connection manager.
 java.lang.String getDriverClassName()
          Returns the driverClassName value.
 java.lang.String getDriverPath()
          Returns the driverPath value.
 java.lang.String getLogin()
          Returns the login used by this connection manager.
 java.lang.String getPassword()
          Returns the password used by this connection manager.
 java.lang.String getVLogin()
           
 java.lang.String getXml()
          Get xml formatted representation of this cjdbc component
abstract  java.lang.String getXmlImpl()
          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(long transactionId)
          Releases a connection used for a transaction.
 java.sql.Connection retrieveConnection(long transactionId)
          Retrieves a connection used for a transaction.
 void setDriverClassName(java.lang.String driverClassName)
          Sets the driverClassName value.
 void setDriverPath(java.lang.String driverPath)
          Sets the driverPath value.
 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.
 void setVLogin(java.lang.String login)
           
 
Methods inherited from class java.lang.Object
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.


driverClassName

protected java.lang.String driverClassName
The class name of the driver


driverPath

protected java.lang.String driverPath
The path to the driver if null the default directory is used


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.


vLogin

private java.lang.String vLogin
Virtual Login to be that use this connection manager

Constructor Detail

AbstractConnectionManager

public AbstractConnectionManager(java.lang.String backendUrl,
                                 java.lang.String backendName,
                                 java.lang.String rLogin,
                                 java.lang.String rPassword,
                                 java.lang.String driverPath,
                                 java.lang.String driverClassName)
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
driverPath - path for driver
driverClassName - class name for driver
Method Detail

copy

public AbstractConnectionManager copy(java.lang.String url,
                                      java.lang.String name)
                               throws java.lang.Exception
Copy this connection manager and replace the name of the backend and its url Every other parameter is the same

Parameters:
url - the url to the backend associated to this ConnectionManager
name - the name of the backend
Returns:
AbstractConnectionManager
Throws:
java.lang.Exception - if clone fails

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.

getConnectionFromDriver

public java.sql.Connection getConnectionFromDriver()
Get a connection from DriverManager.

Returns:
a new connection or null if Driver.getConnection() failed.
See Also:
DriverManager.getConnection(String, String, String, String, String)

getConnection

public abstract java.sql.Connection getConnection()
                                           throws UnreachableBackendException
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.
Throws:
UnreachableBackendException - if the backend must be disabled

getConnection

public java.sql.Connection getConnection(long transactionId)
                                  throws UnreachableBackendException
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 .
Throws:
UnreachableBackendException - if the backend must be disabled
See Also:
getConnection()

retrieveConnection

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

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

releaseConnection

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

Parameters:
connection - the connection to release.

releaseConnection

public void releaseConnection(long 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)

deleteConnection

public abstract void deleteConnection(java.sql.Connection connection)
Delete a connection that is no more valid.

Parameters:
connection - the connection to delete.

deleteConnection

public void deleteConnection(long transactionId)
Delete a bad connection that was used for a transaction. The corresponding connection is deleted by calling deleteConnection(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.

getXmlImpl

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

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

getXml

public java.lang.String getXml()
Description copied from interface: XmlComponent
Get xml formatted representation of this cjdbc component

Specified by:
getXml in interface XmlComponent
Returns:
xml formatted fragment
See Also:
XmlComponent.getXml()

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.

getVLogin

public java.lang.String getVLogin()
Returns:
Returns the vLogin.

setVLogin

public void setVLogin(java.lang.String login)
Parameters:
login - The vLogin to set.

getCurrentNumberOfConnections

public abstract int getCurrentNumberOfConnections()
Get the current number of connections open for this connection manager.

Returns:
the current number of open connections

getDriverClassName

public java.lang.String getDriverClassName()
Returns the driverClassName value.

Returns:
Returns the driverClassName.

setDriverClassName

public void setDriverClassName(java.lang.String driverClassName)
Sets the driverClassName value.

Parameters:
driverClassName - The driverClassName to set.

getDriverPath

public java.lang.String getDriverPath()
Returns the driverPath value.

Returns:
Returns the driverPath.

setDriverPath

public void setDriverPath(java.lang.String driverPath)
Sets the driverPath value.

Parameters:
driverPath - The driverPath to set.

clone

protected abstract java.lang.Object clone()
                                   throws java.lang.CloneNotSupportedException
Throws:
java.lang.CloneNotSupportedException


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