oracle.cle.persistence
Class ConnectionManager

java.lang.Object
  |
  +--oracle.cle.persistence.ConnectionManager
All Implemented Interfaces:
java.io.Serializable

public class ConnectionManager
extends java.lang.Object
implements java.io.Serializable

Handles a pool of ConnectionProviders in a static fashion. This class is a Singleton. it is a Manager for the disparate datasources. It stores the different ConnectionProviders in a hashtable as name-value pairs with the deployment key as the name. It also stores the different connections as name-value pairs with the ConnectionProvider as the key. A user may have more than one connection to the same or a different data source. If a user wants to use multiple connections to the same data source then he should specify a connection id (*DON'T* specify a connection id for the first connection as this (slightly) impacts the performance).

Attributes can automatically be set and loaded by specifying in an entry in the cle-provider.xml descriptor file. Each entry must have a label or name called the deploymentKey. This is how the ConnectionManager will reference the specific ConnectionProvider instance.

The ConnectionManager is typically used behind the scenes in Handlers through the DeploymentAutoConnector functionality inherent in all Handlers, but it can be used outside of that context:

Typical Usage when not using DeploymentAutoConnecter:

 
    // get the instance and load the properties files if this
    // is the first tiime the ConnectionManager is referenced.
    ConnectionManager cm = ConnectionManager.getInstance();
    // get the connection based on the deployment key specified
    // and your session id.  The oracle.cle.resource.DeploymentManager
    // loads and indexes the deployment keys for the various
    // oracle.cle.resource.Resources (ie. business objects).
    Object aConnection = cm.getConnection("aDeploymentkey", sessionId);
    // Get a second connection of the same type
    Object aConnection2 = cm.getConnection("aDeploymentkey", sessionId, "2");
    // use the connection... whatever it is
    // (EJBHome, Connection, ApplicationModule, JNDIObject, etc...)
    ... use it ...
    // release the first connection
    releaseConnection("aDeploymentkey", sessionId);
    // release the second connection
    releaseConnection("aDeploymentkey", sessionId, "2");
 
 

NOTE: If deploying in JServer and using properties files (old method), you must put your properties file in the same package as the class that is loading them. this applies to jar files, as well. If not in JServer, you can put the properties file in the class' package OR in the top level of your classpath.

See Also:
Serialized Form

Field Summary
protected  boolean dtdValidation
           
static int FAILOVER
           
static java.lang.String LOGIN
           
protected  java.util.Map sessionProviders
          This map contains the dynamic deployment keys of providers that belong to a particular session id.
 
Constructor Summary
protected ConnectionManager()
          Make sure only this class can construct an instance and it's children NOTE: The constructor is protected
 
Method Summary
 ConnectionProvider cloneProvider(ConnectionProvider provider, java.util.Properties dynamicProperties, java.lang.String deploymentKey, java.lang.Object sessionId)
          This method returns a Provider clone with dynamic properties used.
 java.lang.Object getConnection(java.lang.String deploymentKey)
          This method returns a Connection The sessionId is pickedup from the ThreadLocal variable in the cle.util.CLEUtil.sessionId
 java.lang.Object getConnection(java.lang.String deploymentKey, int failover)
          This method returns a Connection The sessionId is pickedup from the ThreadLocal variable in the cle.util.CLEUtil.sessionId
 java.lang.Object getConnection(java.lang.String deploymentKey, java.lang.Object sessionId)
          This method returns a Connection DO NOT USE a sessionId that is not really the session id (e.g.
 java.lang.Object getConnection(java.lang.String deploymentKey, java.lang.Object sessionId, int failover)
          This method returns a Connection DO NOT USE a sessionId that is not really the session id (e.g.
 java.lang.Object getConnection(java.lang.String deploymentKey, java.lang.Object sessionId, java.lang.String connectionId)
          This method returns a Connection Use this method if you want a second, third, etc.
 java.lang.Object getConnection(java.lang.String deploymentKey, java.util.Properties connectionProperties, int failover)
          This method returns a Connection The sessionId is pickedup from the ThreadLocal variable sessionId in CLEUtil DO NOT USE a sessionId that is not really the session id (e.g.
 java.lang.Object getConnection(java.lang.String deploymentKey, java.util.Properties connectionProperties, java.lang.Object sessionId)
          This method returns a Connection DO NOT USE a sessionId that is not really the session id (e.g.
 java.lang.Object getConnection(java.lang.String deploymentKey, java.util.Properties connectionProperties, java.lang.Object sessionId, int failover)
          This method returns a Connection DO NOT USE a sessionId that is not really the session id (e.g.
 java.lang.Object getConnection(java.lang.String deploymentKey, java.util.Properties connectionProperties, java.lang.Object sessionId, java.lang.String connectionId)
          This method returns a Connection Use this method if you want a second, third, etc.
 java.lang.Object getConnection(java.lang.String deploymentKey, java.util.Properties connectionProperties, java.lang.Object sessionId, java.lang.String connectionId, int failover)
          This method returns a failover Connection Use this method if you want a second, third, etc.
 java.lang.Object getConnection(java.lang.String deploymentKey, java.util.Properties connectionProperties, java.lang.String connectionId)
          This method returns a Connection Use this method if you want a second, third, etc.
 java.lang.Object getConnection(java.lang.String deploymentKey, java.util.Properties connectionProperties, java.lang.String connectionId, int failover)
          This method returns a failover Connection Use this method if you want a second, third, etc.
 java.lang.Object getConnection(java.lang.String deploymentKey, java.lang.String connectionId)
          This method returns a Connection Use this method if you want a second, third, etc.
static ConnectionManager getInstance()
          The one public access point for the instance.
 ConnectionProvider getProvider(java.lang.String deploymentKey)
          Returns the Provider with the parameter key
 java.util.Enumeration getProviderKeys()
          Returns the Provider Keys
 void load()
          Loads the ConnectionProvider and adds it to the ConnectionProvider Hashtable
 void releaseConnection(java.lang.String deploymentKey)
          This method will release a connection by getting the appropriate provider and then calling releaseConnection on the provider
 void releaseConnection(java.lang.String deploymentKey, java.lang.Object sessionId)
          This method will release a connection by getting the appropriate provider and then calling releaseConnection on the provider
 void releaseConnection(java.lang.String deploymentKey, java.lang.Object sessionId, java.lang.String connectionId)
          This method will release a connection by getting the appropriate provider and then calling releaseConnection on the provider
 void releaseConnection(java.lang.String deploymentKey, java.lang.String connectionId)
          This method will release a connection by getting the appropriate provider and then calling releaseConnection on the provider
 void releaseConnections()
          This method will release all connections for a session by getting all providers holding a connection for the particular session and then calling releaseConnection on each of those providers sessionId pickup from the CLEUtil.sessionId
 void releaseConnections(java.lang.Object sessionId)
          This method will release all connections for a session by getting all providers holding a connection for the particular session and then calling releaseConnection on each of those providers
 void releaseConnections(java.lang.Object sessionId, java.lang.String scope)
          This method will release either all request scoped connections for a session that were marked as released during the request or releases all connections of a particular session.
 void releaseConnections(java.lang.String scope)
          This method will release either all request scoped connections for a session that were marked as released during the request or releases all connections of a particular session.
 void releaseRequestScopedConnections()
          This method will release all request scoped connections for a session that were marked as released during the request.
 void releaseRequestScopedConnections(java.lang.Object sessionId)
          This method will release all request scoped connections for a session that were marked as released during the request.
 void removeSessionProviders(java.lang.Object sessionId)
          Removes all session specific connection providers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dtdValidation

protected boolean dtdValidation

FAILOVER

public static final int FAILOVER

LOGIN

public static final java.lang.String LOGIN

sessionProviders

protected java.util.Map sessionProviders
This map contains the dynamic deployment keys of providers that belong to a particular session id. Each entry in this map has the session id as a key and a collection of dynamic provider deployment keys as a value.
Constructor Detail

ConnectionManager

protected ConnectionManager()
Make sure only this class can construct an instance and it's children NOTE: The constructor is protected
Method Detail

load

public void load()
Loads the ConnectionProvider and adds it to the ConnectionProvider Hashtable

getInstance

public static ConnectionManager getInstance()
The one public access point for the instance. Most everything can done through public static methods that access the instancevariable, though.

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey,
                                      java.util.Properties connectionProperties,
                                      java.lang.Object sessionId)
                               throws java.lang.Exception
This method returns a Connection DO NOT USE a sessionId that is not really the session id (e.g. sessionId+"1") in order to get multiple connections of the same type. If you do that then connections may not be released correctly. Instead use this method:
 
 getConnection(deploymentKey,connectionProperties,sessionId, "1")
 
 
Parameters:
deploymentKey - : String Deployment Key
connectionProperties - : Properties containing all the stuff needed to connect
sessionId - : Object sessionId

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey)
                               throws java.lang.Exception
This method returns a Connection The sessionId is pickedup from the ThreadLocal variable in the cle.util.CLEUtil.sessionId
 
 getConnection(deploymentKey,sessionId, "1")
 
 
Parameters:
deploymentKey - : String Deployment Key

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey,
                                      java.lang.Object sessionId)
                               throws java.lang.Exception
This method returns a Connection DO NOT USE a sessionId that is not really the session id (e.g. sessionId+"1") in order to get multiple connections of the same type. If you do that then connections may not be released correctly. Instead use this method:
  
    getConnection(deploymentKey,sessionId, "1")
  
 
Parameters:
deploymentKey - : String Deployment Key
sessionId - : Object sessionId

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey,
                                      java.lang.Object sessionId,
                                      java.lang.String connectionId)
                               throws java.lang.Exception
This method returns a Connection Use this method if you want a second, third, etc. connection of the same type. For the first connection, it is recommended to use
  
   getConnection(deploymentKey,sessionId);
  
 
Parameters:
deploymentKey - : String Deployment Key
sessionId - : Object sessionId
connectionId - : String connectionId

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey,
                                      java.lang.String connectionId)
                               throws java.lang.Exception
This method returns a Connection Use this method if you want a second, third, etc. connection of the same type. For the first connection, it is recommended to use SessionId is picked up from the CLEUtil.sessionId ThreadLocal variable.
Parameters:
deploymentKey - : String Deployment Key
sessionId - : Object sessionId
connectionId - : String connectionId

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey,
                                      java.lang.Object sessionId,
                                      int failover)
                               throws java.lang.Exception
This method returns a Connection DO NOT USE a sessionId that is not really the session id (e.g. sessionId+"1") in order to get multiple connections of the same type. If you do that then connections may not be released correctly. Instead use this method:
  
    getConnection(deploymentKey,sessionId,"1",failover)
  
 
Parameters:
deploymentKey - : String Deployment Key

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey,
                                      int failover)
                               throws java.lang.Exception
This method returns a Connection The sessionId is pickedup from the ThreadLocal variable in the cle.util.CLEUtil.sessionId
Parameters:
deploymentKey - : String Deployment Key

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey,
                                      java.util.Properties connectionProperties,
                                      java.lang.Object sessionId,
                                      int failover)
                               throws java.lang.Exception
This method returns a Connection DO NOT USE a sessionId that is not really the session id (e.g. sessionId+"1") in order to get multiple connections of the same type. If you do that then connections may not be released correctly. Instead use this method:
  
   getConnection(deploymentKey,connectionProperties,sessionId,"1",failover)
  
 
Parameters:
deploymentKey - : String Deployment Key
connectionProperties - : Properties contaning all the stuff needed to connect
sessionId - : Object sessionId
failover - : int failover mode

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey,
                                      java.util.Properties connectionProperties,
                                      int failover)
                               throws java.lang.Exception
This method returns a Connection The sessionId is pickedup from the ThreadLocal variable sessionId in CLEUtil DO NOT USE a sessionId that is not really the session id (e.g. sessionId+"1") in order to get multiple connections of the same type. If you do that then connections may not be released correctly. Instead use this method:
  
   getConnection(deploymentKey,connectionProperties,"1",failover)
  
 
Parameters:
deploymentKey - : String Deployment Key
connectionProperties - : Properties contaning all the stuff needed to connect
failover - : int failover mode

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey,
                                      java.util.Properties connectionProperties,
                                      java.lang.Object sessionId,
                                      java.lang.String connectionId,
                                      int failover)
                               throws java.lang.Exception
This method returns a failover Connection Use this method if you want a second, third, etc. connection of the same type. For the first connection, it is recommended to use
  
   getConnection(deploymentKey,connectionProperties,sessionId,failover);
  
 
Parameters:
deploymentKey - : String Deployment Key
connectionProperties - : Properties contaning all the stuff needed to connect
sessionId - : Object sessionId
connectionId - : String connectionId
failover - : int failover mode This method gets a connections and takes care of all different scenarios

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey,
                                      java.util.Properties connectionProperties,
                                      java.lang.String connectionId,
                                      int failover)
                               throws java.lang.Exception
This method returns a failover Connection Use this method if you want a second, third, etc. connection of the same type. For the first connection, it is recommended to use
  
   getConnection(deploymentKey,connectionProperties,sessionId,failover);
  
 
Parameters:
deploymentKey - : String Deployment Key
connectionProperties - : Properties contaning all the stuff needed to connect
connectionId - : String connectionId
failover - : int failover mode This method gets a connections and takes care of all different scenarios

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey,
                                      java.util.Properties connectionProperties,
                                      java.lang.String connectionId)
                               throws java.lang.Exception
This method returns a Connection Use this method if you want a second, third, etc. connection of the same type. For the first connection, it is recommended to use
  
   getConnection(deploymentKey,connectionProperties,sessionId);
  
 
Parameters:
deploymentKey - : String Deployment Key
connectionProperties - : Properties contaning all the stuff needed to connect
connectionId - : String connectionId This method gets a connections and takes care of all different scenarios

getConnection

public java.lang.Object getConnection(java.lang.String deploymentKey,
                                      java.util.Properties connectionProperties,
                                      java.lang.Object sessionId,
                                      java.lang.String connectionId)
                               throws java.lang.Exception
This method returns a Connection Use this method if you want a second, third, etc. connection of the same type. For the first connection, it is recommended to use
  
   getConnection(deploymentKey,connectionProperties,sessionId);
  
 
Parameters:
deploymentKey - : String Deployment Key
connectionProperties - : Properties contaning all the stuff needed to connect
sessionId - : Object sessionId
connectionId - : String connectionId This method gets a connections and takes care of all different scenarios

releaseConnection

public void releaseConnection(java.lang.String deploymentKey,
                              java.lang.Object sessionId)
                       throws java.lang.Exception
This method will release a connection by getting the appropriate provider and then calling releaseConnection on the provider

releaseConnection

public void releaseConnection(java.lang.String deploymentKey)
                       throws java.lang.Exception
This method will release a connection by getting the appropriate provider and then calling releaseConnection on the provider

releaseConnection

public void releaseConnection(java.lang.String deploymentKey,
                              java.lang.Object sessionId,
                              java.lang.String connectionId)
                       throws java.lang.Exception
This method will release a connection by getting the appropriate provider and then calling releaseConnection on the provider

releaseConnection

public void releaseConnection(java.lang.String deploymentKey,
                              java.lang.String connectionId)
                       throws java.lang.Exception
This method will release a connection by getting the appropriate provider and then calling releaseConnection on the provider

releaseConnections

public void releaseConnections(java.lang.Object sessionId)
                        throws CLEException
This method will release all connections for a session by getting all providers holding a connection for the particular session and then calling releaseConnection on each of those providers
Parameters:
sessionId - : Object session id

releaseConnections

public void releaseConnections()
                        throws CLEException
This method will release all connections for a session by getting all providers holding a connection for the particular session and then calling releaseConnection on each of those providers sessionId pickup from the CLEUtil.sessionId
Parameters:
sessionId - : Object session id

releaseRequestScopedConnections

public void releaseRequestScopedConnections(java.lang.Object sessionId)
                                     throws CLEException
This method will release all request scoped connections for a session that were marked as released during the request.
Parameters:
sessionId - : Object session id

releaseRequestScopedConnections

public void releaseRequestScopedConnections()
                                     throws CLEException
This method will release all request scoped connections for a session that were marked as released during the request. SessionId pickedup from the CLEUtil.sessionId

releaseConnections

public void releaseConnections(java.lang.String scope)
                        throws CLEException
This method will release either all request scoped connections for a session that were marked as released during the request or releases all connections of a particular session. SessionId is pickedUp from the CLEUtil.sessionId

releaseConnections

public void releaseConnections(java.lang.Object sessionId,
                               java.lang.String scope)
                        throws CLEException
This method will release either all request scoped connections for a session that were marked as released during the request or releases all connections of a particular session.
Parameters:
sessionId - : Object session id

getProviderKeys

public java.util.Enumeration getProviderKeys()
Returns the Provider Keys

getProvider

public ConnectionProvider getProvider(java.lang.String deploymentKey)
Returns the Provider with the parameter key
Parameters:
deploymentKey - : String , The Deployment Key

cloneProvider

public ConnectionProvider cloneProvider(ConnectionProvider provider,
                                        java.util.Properties dynamicProperties,
                                        java.lang.String deploymentKey,
                                        java.lang.Object sessionId)
                                 throws CLEException
This method returns a Provider clone with dynamic properties used. After the provider is cloned it is also registered with ConnectionManager to ensure the session subsequently gets the same provider and connection.
Parameters:
provider - : ConnectionProvider to be cloned
properties - : Properties the dynamic Property set
deploymentKey - : String the deployment key
sessionId - : Object the sessionid

removeSessionProviders

public void removeSessionProviders(java.lang.Object sessionId)
Removes all session specific connection providers


Copyright © 2003 ORACLE Corp. All Rights Reserved.