Oracle TopLink API Reference
10g Release 3 (10.1.3)

B13698-01


oracle.toplink.util
Class SessionFactory

java.lang.Object
  extended byoracle.toplink.util.SessionFactory


public class SessionFactory
extends java.lang.Object

Factory class to simplify the development and generation of code that accesses a TopLink Session and UnitOfWork. This class supports creating a Session or UnitOfWork for the following 2-tier and 3-tier Session usage models: -> DatabaseSession -> Server/ClientSession -> SessionBroker -> Server/ClientSessionBroker -> JTA TX Session This factory class is useful in a stateless system such as a SessionBean where transactional resources (namely the Session and UnitOfWork) do not need to be maintained by the factory. The Session accessed in the class must be defined and configured in a sessions configuration xml.


Constructor Summary
SessionFactory(java.lang.String sessionName)
          Constructor for creating a new TopLinkSessionHelper instance.
SessionFactory(java.lang.String sessionsXMLPath, java.lang.String sessionName)
          Constructor for creating a new TopLinkSessionHelper instance.

 

Method Summary
 Session acquireSession()
          Returns the Session active for this specified helper.
 UnitOfWork acquireUnitOfWork()
          Looks up the active UnitOfWork using either the global JTA TX or acquires a new one from the active session.
 UnitOfWork acquireUnitOfWork(Session session)
          Looks up the active UnitOfWork using either the global JTA TX or acquires a new one from the active session.
 java.util.Collection detach(java.util.Collection entities)
          Build a detached copy using a one-off UnitOfWork.
 java.lang.Object detach(java.lang.Object entity)
          Build a detached copy using a one-off UnitOfWork.
 java.lang.String getSessionName()
          Returns the name of the Session used by this factory.
 java.lang.String getSessionXMLPath()
          Returns the path of the sessions configuration xml used by this factory.
 Session getSharedSession()
          Helper method that looks up the session and ensure that if the application has been hot-deployed it gets a fresh version of the Session.
 Session getSharedSession(boolean login, boolean refresh)
          Helper method that looks up the session and ensure that if the application has been hot-deployed it gets a fresh version of the Session.

 

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Constructor Detail

SessionFactory

public SessionFactory(java.lang.String sessionsXMLPath,
                      java.lang.String sessionName)
Constructor for creating a new TopLinkSessionHelper instance.
Parameters:
sessionsXMLPath - - resource path of the sessions configuration xml.
sessionName - - name of the session to use.

SessionFactory

public SessionFactory(java.lang.String sessionName)
Constructor for creating a new TopLinkSessionHelper instance. Assumes that the resource path of the sessions configuration xml is "META-INF/session.xml".
Parameters:
sessionName - - name of the session to use.

Method Detail

getSessionName

public java.lang.String getSessionName()
Returns the name of the Session used by this factory.

getSessionXMLPath

public java.lang.String getSessionXMLPath()
Returns the path of the sessions configuration xml used by this factory.

getSharedSession

public Session getSharedSession()
Helper method that looks up the session and ensure that if the application has been hot-deployed it gets a fresh version of the Session.

getSharedSession

public Session getSharedSession(boolean login,
                                boolean refresh)
Helper method that looks up the session and ensure that if the application has been hot-deployed it gets a fresh version of the Session.
Parameters:
login - - Indicates whether the Session should be logged in.
refresh - - Causes the SessionManager to create a new Session.
Returns:
Shared Session.

acquireSession

public Session acquireSession()
Returns the Session active for this specified helper. If the application is not running with an external transaction controller then a new session is returned and it is up to the applicaion to manage it.

acquireUnitOfWork

public UnitOfWork acquireUnitOfWork()
Looks up the active UnitOfWork using either the global JTA TX or acquires a new one from the active session.

acquireUnitOfWork

public UnitOfWork acquireUnitOfWork(Session session)
Looks up the active UnitOfWork using either the global JTA TX or acquires a new one from the active session. THis method should be used if a session has already been acquired.

detach

public java.lang.Object detach(java.lang.Object entity)
Build a detached copy using a one-off UnitOfWork. This simulates creation of a copy through serialization when using a remote session bean if this copy process is not done the user of this helper would return the shared copy from the cache that should not be modified. These detachment methods *MUST* be used for local session beans if the objects are to be edited.
Parameters:
entity - an existing persistent entity
Returns:
a copy of the entity for use in a local client that may make changes to it

detach

public java.util.Collection detach(java.util.Collection entities)
Build a detached copy using a one-off UnitOfWork. This simulates creation of a copy through serialization when using a remote session bean if this copy process is not done the user of this helper would return the shared copy from the cache that should not be modified. These detachment methods *MUST* be used for local session beans if the objects are to be edited.
Parameters:
entities - - Collection of entities to create detached copies from.
Returns:
Copies of the entities for use in a local client that may make changes to these entities.

Copyright © 1998, 2006, Oracle. All Rights Reserved.