sf logo

sf.qof.session
Interface SessionContext

All Known Implementing Classes:
SessionContextFactory.DefaultSessionContext

public interface SessionContext

Defines methods for session handling. This includes methods to start and stop a session as well as retrieving the current database connection and user transaction.

A session context is created by a session context factory.

A session context creates a separate session for each calling thread. Therefore session can not be shared between sessions.

A SessionContext can be used in the following way:

 // get the default session context
 SessionContext ctx = SessionContextFactory.getContext();
 
 // start a new session 
 ctx.startSession();
 
 // start a new transaction
 ctx.getUserTransaction().begin();
 
 // get the database connection for the current session
 Connection con = ctx.getConnection();
 
 // do something with the connection
 ...
 
 // commit and end the current transaction
 ctx.getUserTransaction().commit();
 
 // stop the session
 ctx.stopSession();
 

See Also:
SessionContextFactory, UserTransaction

Field Summary
static String DEFAULT_CONTEXT_NAME
          Name of the default session context.
 
Method Summary
 Connection getConnection()
          Returns the database connection of the session belonging to the calling thread.
 UserTransaction getUserTransaction()
          Returns the user transaction of the session belonging to the calling thread.
 void startSession()
          This method starts a session.
 void stopSession()
          This method stops a session.
 

Field Detail

DEFAULT_CONTEXT_NAME

static final String DEFAULT_CONTEXT_NAME
Name of the default session context.

See Also:
Constant Field Values
Method Detail

startSession

void startSession()
                  throws SystemException
This method starts a session. It creates a new session for the calling thread and assigns a database connection to it and it creates a new transaction. It must be called by the calling thread before any other method of this session context can be called.

Throws:
SystemException - Thrown if an unexpected error condition occurs
IllegalStateException - Thrown if the session is already started

stopSession

void stopSession()
                 throws SystemException
This method stops a session. It closes the database connection of the session owned by the calling thread.

Throws:
SystemException - Thrown if an unexpected error condition occurs
IllegalStateException - Thrown if the session is already stopped

getUserTransaction

UserTransaction getUserTransaction()
Returns the user transaction of the session belonging to the calling thread.

Returns:
the current user transaction
Throws:
IllegalStateException - Thrown if the session is not started

getConnection

Connection getConnection()
Returns the database connection of the session belonging to the calling thread.

Returns:
the current connection
Throws:
IllegalStateException - Thrown if the session is not started

sf logo

Copyright © 2007 brunella ltd. All Rights Reserved.