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

## org.springframework.orm.toplink.support
Class TopLinkDaoSupport

    java.lang.Object
      org.springframework.dao.support.DaoSupport
          org.springframework.orm.toplink.support.TopLinkDaoSupport

All Implemented Interfaces:
  InitializingBean

    public abstract class TopLinkDaoSupport

extends DaoSupport

Convenient super class for TopLink data access objects.

Requires a SessionFactory to be set, providing a TopLinkTemplate based on it to subclasses. Can alternatively be initialized directly with a TopLinkTemplate, to reuse the latter's settings such as the SessionFactory, exception translator, etc.

This base class is mainly intended for TopLinkTemplate usage but can also be used when working with SessionFactoryUtils directly, for example in combination with TopLinkInterceptor-managed Sessions. Convenience `getSession` and `releaseSession` methods are provided for that usage style.

Since:
  1.2
Author:
  Juergen Hoeller
See Also:
  `setSessionFactory(org.springframework.orm.toplink.SessionFactory)`, `setTopLinkTemplate(org.springframework.orm.toplink.TopLinkTemplate)`, `getSession()`, `releaseSession(oracle.toplink.sessions.Session)`, `TopLinkTemplate`, `TopLinkInterceptor`

Field Summary

Fields inherited from class org.springframework.dao.support.DaoSupport
`logger`

Constructor Summary
`TopLinkDaoSupport()`

Method Summary
`protected void` | `checkDaoConfig()` Abstract subclasses must override this to check their configuration.
`protected DataAccessException` | `convertTopLinkAccessException(oracle.toplink.exceptions.TopLinkException ex)` Convert the given TopLinkException to an appropriate exception from the `org.springframework.dao` hierarchy.
`protected TopLinkTemplate` | `createTopLinkTemplate(SessionFactory sessionFactory)` Create a TopLinkTemplate for the given SessionFactory.
`protected oracle.toplink.sessions.Session` | `getSession()` Get a TopLink Session, either from the current transaction or a new one.
`protected oracle.toplink.sessions.Session` | `getSession(boolean allowCreate)` Get a TopLink Session, either from the current transaction or a new one.
`SessionFactory` | `getSessionFactory()` Return the TopLink SessionFactory used by this DAO.
`TopLinkTemplate` | `getTopLinkTemplate()` Return the TopLinkTemplate for this DAO, pre-initialized with the SessionFactory or set explicitly.
`protected void` | `releaseSession(oracle.toplink.sessions.Session session)` Close the given TopLink Session, created via this DAO's SessionFactory, if it isn't bound to the thread.
`void` | `setSessionFactory(SessionFactory sessionFactory)` Set the TopLink SessionFactory to be used by this DAO.
`void` | `setTopLinkTemplate(TopLinkTemplate topLinkTemplate)` Set the TopLinkTemplate for this DAO explicitly, as an alternative to specifying a SessionFactory.

Methods inherited from class org.springframework.dao.support.DaoSupport
`afterPropertiesSet, initDao`

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

Constructor Detail

### TopLinkDaoSupport

    public TopLinkDaoSupport()

Method Detail

### setSessionFactory

    public final void setSessionFactory(SessionFactory sessionFactory)

  Set the TopLink SessionFactory to be used by this DAO. Will automatically create a TopLinkTemplate for the given SessionFactory.

  See Also:
    `createTopLinkTemplate(org.springframework.orm.toplink.SessionFactory)`, `setTopLinkTemplate(org.springframework.orm.toplink.TopLinkTemplate)`

### createTopLinkTemplate

    protected TopLinkTemplate createTopLinkTemplate(SessionFactory sessionFactory)

  Create a TopLinkTemplate for the given SessionFactory. Only invoked if populating the DAO with a SessionFactory reference!

  Can be overridden in subclasses to provide a TopLinkTemplate instance with different configuration, or a custom TopLinkTemplate subclass.

  Parameters:
    `sessionFactory` - the TopLink SessionFactory to create a TopLinkTemplate for
  Returns:
    the new TopLinkTemplate instance
  See Also:
    `setSessionFactory(org.springframework.orm.toplink.SessionFactory)`

### getSessionFactory

    public final SessionFactory getSessionFactory()

  Return the TopLink SessionFactory used by this DAO.

### setTopLinkTemplate

    public final void setTopLinkTemplate(TopLinkTemplate topLinkTemplate)

  Set the TopLinkTemplate for this DAO explicitly, as an alternative to specifying a SessionFactory.

  See Also:
    `setSessionFactory(org.springframework.orm.toplink.SessionFactory)`

### getTopLinkTemplate

    public final TopLinkTemplate getTopLinkTemplate()

  Return the TopLinkTemplate for this DAO, pre-initialized with the SessionFactory or set explicitly.

### checkDaoConfig

    protected final void checkDaoConfig()

  Description copied from class: `DaoSupport`
  Abstract subclasses must override this to check their configuration.

  Implementors should be marked as `final`

  Specified by:
    `checkDaoConfig` in class `DaoSupport`

### getSession

    protected final oracle.toplink.sessions.Session getSession()
                                                        throws DataAccessResourceFailureException,
                                                               IllegalStateException

  Get a TopLink Session, either from the current transaction or a new one. The latter is only allowed if the "allowCreate" setting of this bean's TopLinkTemplate is true.

  Note that this is not meant to be invoked from TopLinkTemplate code but rather just in plain TopLink code. Either rely on a thread-bound Session (via TopLinkInterceptor), or use it in combination with `releaseSession`.

  In general, it is recommended to use TopLinkTemplate, either with the provided convenience operations or with a custom TopLinkCallback that provides you with a Session to work on. TopLinkTemplate will care for all resource management and for proper exception conversion.

  Returns:
    the TopLink Session
  Throws:
    `DataAccessResourceFailureException` - if the Session couldn't be created
    `IllegalStateException` - if no thread-bound Session found and allowCreate false
  See Also:
    `TopLinkTemplate`, `SessionFactoryUtils.getSession(SessionFactory, boolean)`, `TopLinkInterceptor`, `TopLinkTemplate`, `TopLinkCallback`

### getSession

    protected final oracle.toplink.sessions.Session getSession(boolean allowCreate)
                                                        throws DataAccessResourceFailureException,
                                                               IllegalStateException

  Get a TopLink Session, either from the current transaction or a new one. The latter is only allowed if "allowCreate" is true.

  Note that this is not meant to be invoked from TopLinkTemplate code but rather just in plain TopLink code. Either rely on a thread-bound Session (via TopLinkInterceptor), or use it in combination with `releaseSession`.

  In general, it is recommended to use TopLinkTemplate, either with the provided convenience operations or with a custom TopLinkCallback that provides you with a Session to work on. TopLinkTemplate will care for all resource management and for proper exception conversion.

  Parameters:
    `allowCreate` - if a new Session should be created if no thread-bound found
  Returns:
    the TopLink Session
  Throws:
    `DataAccessResourceFailureException` - if the Session couldn't be created
    `IllegalStateException` - if no thread-bound Session found and allowCreate false
  See Also:
    `SessionFactoryUtils.getSession(SessionFactory, boolean)`, `TopLinkInterceptor`, `TopLinkTemplate`, `TopLinkCallback`

### convertTopLinkAccessException

    protected final DataAccessException convertTopLinkAccessException(oracle.toplink.exceptions.TopLinkException ex)

  Convert the given TopLinkException to an appropriate exception from the `org.springframework.dao` hierarchy. Will automatically detect wrapped SQLExceptions and convert them accordingly.

  Delegates to the convertTopLinkAccessException method of this DAO's TopLinkTemplate.

  Parameters:
    `ex` - TopLinkException that occured
  Returns:
    the corresponding DataAccessException instance
  See Also:
    `setTopLinkTemplate(org.springframework.orm.toplink.TopLinkTemplate)`, `TopLinkAccessor.convertTopLinkAccessException(oracle.toplink.exceptions.TopLinkException)`

### releaseSession

    protected final void releaseSession(oracle.toplink.sessions.Session session)

  Close the given TopLink Session, created via this DAO's SessionFactory, if it isn't bound to the thread.

  Parameters:
    `session` - the TopLink Session to close
  See Also:
    `SessionFactoryUtils.releaseSession(oracle.toplink.sessions.Session, org.springframework.orm.toplink.SessionFactory)`

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

Copyright © 2002-2008 The Spring Framework.