Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.orm.toplink
Class SessionFactoryUtils

    java.lang.Object
      org.springframework.orm.toplink.SessionFactoryUtils

    public abstract class SessionFactoryUtils

extends Object

Helper class featuring methods for TopLink Session handling, allowing for reuse of TopLink Session instances within transactions. Also provides support for exception translation.

Mainly intended for internal use within the framework.

Since:
  1.2
Author:
  Juergen Hoeller, James Clark

Constructor Summary
`SessionFactoryUtils()`

Method Summary
`static DataAccessException` | `convertTopLinkAccessException(oracle.toplink.exceptions.TopLinkException ex)` Convert the given TopLinkException to an appropriate exception from the `org.springframework.dao` hierarchy.
`static oracle.toplink.sessions.Session` | `doGetSession(SessionFactory sessionFactory, boolean allowCreate)` Get a TopLink Session for the given SessionFactory.
`static oracle.toplink.sessions.Session` | `getSession(SessionFactory sessionFactory, boolean allowCreate)` Get a TopLink Session for the given SessionFactory.
`static boolean` | `isSessionTransactional(oracle.toplink.sessions.Session session, SessionFactory sessionFactory)` Return whether the given TopLink Session is transactional, that is, bound to the current thread by Spring's transaction facilities.
`static void` | `releaseSession(oracle.toplink.sessions.Session session, SessionFactory sessionFactory)` Close the given Session, created via the given factory, if it is not managed externally (i.e. not bound to the thread).

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

Constructor Detail

### SessionFactoryUtils

    public SessionFactoryUtils()

Method Detail

### getSession

    public static oracle.toplink.sessions.Session getSession(SessionFactory sessionFactory,
                                                             boolean allowCreate)
                                                      throws DataAccessResourceFailureException,
                                                             IllegalStateException

  Get a TopLink Session for the given SessionFactory. Is aware of and will return any existing corresponding Session bound to the current thread, for example when using TopLinkTransactionManager. Will create a new Session otherwise, if "allowCreate" is `true`.

  This is the `getSession` method used by typical data access code, in combination with `releaseSession` called when done with the Session. Note that TopLinkTemplate allows to write data access code without caring about such resource handling.

  Parameters:
    `sessionFactory` - TopLink SessionFactory to create the session with
    `allowCreate` - if a non-transactional Session should be created when no transactional Session can be found for the current thread
  Returns:
    the TopLink Session
  Throws:
    `DataAccessResourceFailureException` - if the Session couldn't be created
    `IllegalStateException` - if no thread-bound Session found and "allowCreate" is `false`
  See Also:
    `releaseSession(oracle.toplink.sessions.Session, org.springframework.orm.toplink.SessionFactory)`, `TopLinkTemplate`

### doGetSession

    public static oracle.toplink.sessions.Session doGetSession(SessionFactory sessionFactory,
                                                               boolean allowCreate)
                                                        throws oracle.toplink.exceptions.TopLinkException,
                                                               IllegalStateException

  Get a TopLink Session for the given SessionFactory. Is aware of and will return any existing corresponding Session bound to the current thread, for example when using TopLinkTransactionManager. Will create a new Session otherwise, if "allowCreate" is `true`.

  Same as `getSession`, but throwing the original TopLinkException.

  Parameters:
    `sessionFactory` - TopLink SessionFactory to create the session with
    `allowCreate` - if a non-transactional Session should be created when no transactional Session can be found for the current thread
  Returns:
    the TopLink Session
  Throws:
    `oracle.toplink.exceptions.TopLinkException` - if the Session couldn't be created
    `IllegalStateException` - if no thread-bound Session found and "allowCreate" is `false`
  See Also:
    `releaseSession(oracle.toplink.sessions.Session, org.springframework.orm.toplink.SessionFactory)`, `TopLinkTemplate`

### isSessionTransactional

    public static boolean isSessionTransactional(oracle.toplink.sessions.Session session,
                                                 SessionFactory sessionFactory)

  Return whether the given TopLink Session is transactional, that is, bound to the current thread by Spring's transaction facilities.

  Parameters:
    `session` - the TopLink Session to check
    `sessionFactory` - TopLink SessionFactory that the Session was created with (can be `null`)
  Returns:
    whether the Session is transactional

### convertTopLinkAccessException

    public static DataAccessException convertTopLinkAccessException(oracle.toplink.exceptions.TopLinkException ex)

  Convert the given TopLinkException to an appropriate exception from the `org.springframework.dao` hierarchy.

  Parameters:
    `ex` - TopLinkException that occured
  Returns:
    the corresponding DataAccessException instance

### releaseSession

    public static void releaseSession(oracle.toplink.sessions.Session session,
                                      SessionFactory sessionFactory)

  Close the given Session, created via the given factory, if it is not managed externally (i.e. not bound to the thread).

  Parameters:
    `session` - the TopLink Session to close
    `sessionFactory` - TopLink SessionFactory that the Session was created with (can be `null`)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| The Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2008 The Spring Framework.