sf logo

sf.qof.session
Class SessionContextFactory

java.lang.Object
  extended by sf.qof.session.SessionContextFactory

public class SessionContextFactory
extends Object

Implementation of a session context factory. SessionContextFactory provides factory methods to create and cache SessionContext objects.

The SessionContextFactory can be used in the following way:

 DataSource ds = ... // get the data source from somewhere
 // register the data source with the default session context 
 SessionContextFactory.setDataSource(ds);
 ...
 // 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:
SessionContext, UserTransaction

Nested Class Summary
protected static class SessionContextFactory.DefaultSessionContext
          Internal implementation of SessionContext.
protected static class SessionContextFactory.DefaultUserTransaction
          Internal implementation of UserTransaction.
 
Method Summary
static SessionContext getContext()
          Creates and returns the default SessionContext.
static SessionContext getContext(String contextName)
          Creates and returns the SessionContext for a given context name.
static void setDataSource(DataSource dataSource)
          Registers a DataSource with the default session context.
static void setDataSource(String contextName, DataSource dataSource)
          Registers a DataSource with the specified session context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getContext

public static SessionContext getContext()
Creates and returns the default SessionContext.

Returns:
the session context

getContext

public static SessionContext getContext(String contextName)
Creates and returns the SessionContext for a given context name.

Parameters:
contextName - the context name
Returns:
the session context

setDataSource

public static void setDataSource(DataSource dataSource)
Registers a DataSource with the default session context.

Parameters:
dataSource - the data source

setDataSource

public static void setDataSource(String contextName,
                                 DataSource dataSource)
Registers a DataSource with the specified session context.

Parameters:
contextName - the session context name
dataSource - the data source

sf logo

Copyright © 2007 brunella ltd. All Rights Reserved.