org.hydrateframework
Class RequestContext

java.lang.Object
  extended by org.hydrateframework.RequestContext

public class RequestContext
extends java.lang.Object

A request context keeps track of those resources that will be held within the scope of a single activity. What delimits an activity is dependent on application design, but may be the lifetime of an application, servicing a single request from a client, starting and completing a transaction, etc.

Version:
@(#)$Revision: 1.4 $
Author:
David Chamberlin

Constructor Summary
RequestContext(ObjectContext ctx)
          Create the request context.
 
Method Summary
 void addConnection(java.lang.String service, java.sql.Connection conn)
          Make a connection available to the request context.
protected  void finalize()
          Clean-up releases resources as a last resort.
 java.sql.Connection getConnection(java.lang.String service)
          Get a connection from the request context by name.
 java.lang.String getDataSourceName(java.sql.Connection conn)
          Returns the name of the service for which a connection was supplied
 NamedParameterStatement getStatement(ObjectContext ctx, java.lang.Class cls, java.lang.String dsName)
          Retrieve a cached SQL statement for requesting or updating objects.
 void releaseConnections(ObjectContext ctx)
          Release the connections acquired by this context back for reuse by other application code.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestContext

public RequestContext(ObjectContext ctx)
Create the request context. Following creation, it becomes the current request context of the ObjectContext given as a parameter

Parameters:
ctx - the given object context will subsequently treat this request context as its current context.
Method Detail

addConnection

public void addConnection(java.lang.String service,
                          java.sql.Connection conn)
Make a connection available to the request context. You must call this method at the start of the request once for each service you will be using


finalize

protected void finalize()
                 throws java.lang.Throwable
Clean-up releases resources as a last resort.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

releaseConnections

public void releaseConnections(ObjectContext ctx)
Release the connections acquired by this context back for reuse by other application code. This must be called in a finally block that surrounds the request code.


getDataSourceName

public java.lang.String getDataSourceName(java.sql.Connection conn)
Returns the name of the service for which a connection was supplied

Parameters:
conn - the connection whose service is to be known
Returns:
the name of the service.

getConnection

public java.sql.Connection getConnection(java.lang.String service)
Get a connection from the request context by name. You must set connections up calling addConnection, before this method will work. This method is called by the ObjectFactory class to get the appropriate connection for reading and writing objects from a database.

Parameters:
service - the name of the service e.g. jdbc/MYDB
Returns:
the connection.

getStatement

public NamedParameterStatement getStatement(ObjectContext ctx,
                                            java.lang.Class cls,
                                            java.lang.String dsName)
                                     throws SaveException
Retrieve a cached SQL statement for requesting or updating objects.

Parameters:
ctx - the object context which the statement will be associated with.
cls - the class of statement to create
dsName - the service name for the connection
Returns:
a statement from the statement cache.
Throws:
SaveException


Copyright © 2000 The Hydrate Project. All Rights Reserved.