org.springframework.orm.toplink
Class SessionReadCallback

java.lang.Object
  extended by org.springframework.orm.toplink.SessionReadCallback
All Implemented Interfaces:
TopLinkCallback

public abstract class SessionReadCallback
extends Object
implements TopLinkCallback

Convenient abstract implementation of the TopLinkCallback interface, exposing either the plain TopLink Session or the TopLink UnitOfWork (which extends the Session interface) to code that reads persistent objects.

Exposes the UnitOfWork if there is an active one (that is, if we're running within a non-read-only transaction); else exposes the Session itself. This allows to modify returned objects within a transaction, which is often desired, while the same code will return shared cache objects if running outside a transaction.

If "enforceReadOnly" is demanded, the callback will always expose the Session itself, avoiding the UnitOfWork overhead in any case.

Since:
1.2
Author:
Juergen Hoeller
See Also:
Session.getActiveUnitOfWork(), readFromSession(oracle.toplink.sessions.Session)

Constructor Summary
SessionReadCallback()
          Create a new SessionReadCallback, not enforcing read-only objects.
SessionReadCallback(boolean enforceReadOnly)
          Create a new SessionReadCallback, enforcing read-only objects if demanded.
 
Method Summary
 Object doInTopLink(oracle.toplink.sessions.Session session)
          Determines the Session to work on (either the active UnitOfWork or the plain Session) and delegates to readFromSession.
protected abstract  Object readFromSession(oracle.toplink.sessions.Session session)
          Called with a Session to work on, either the active UnitOfWork or the plain Session (as determined by the transaction status).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionReadCallback

public SessionReadCallback()
Create a new SessionReadCallback, not enforcing read-only objects.


SessionReadCallback

public SessionReadCallback(boolean enforceReadOnly)
Create a new SessionReadCallback, enforcing read-only objects if demanded.

Parameters:
enforceReadOnly - whether to enforce returning read-only objects, even if running within a non-read-only transaction
Method Detail

doInTopLink

public final Object doInTopLink(oracle.toplink.sessions.Session session)
                         throws oracle.toplink.exceptions.TopLinkException
Determines the Session to work on (either the active UnitOfWork or the plain Session) and delegates to readFromSession.

Specified by:
doInTopLink in interface TopLinkCallback
Parameters:
session - active TopLink Session
Returns:
a result object, or null if none
Throws:
oracle.toplink.exceptions.TopLinkException - in case of TopLink errors
See Also:
readFromSession(oracle.toplink.sessions.Session)

readFromSession

protected abstract Object readFromSession(oracle.toplink.sessions.Session session)
                                   throws oracle.toplink.exceptions.TopLinkException
Called with a Session to work on, either the active UnitOfWork or the plain Session (as determined by the transaction status).

Parameters:
session - the TopLink Session to perform read operations on
Returns:
a result object, or null if none
Throws:
oracle.toplink.exceptions.TopLinkException - in case of TopLink errors


Copyright (c) 2002-2007 The Spring Framework Project.