|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.dao.support.DaoSupport org.springframework.orm.toplink.support.TopLinkDaoSupport
public abstract class TopLinkDaoSupport
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 via a TopLinkTemplate, to reuse the latter's settings like SessionFactory, exception translator, etc.
This base class is mainly intended for TopLinkTemplate usage
but can also be used when working with SessionFactoryUtils directly,
e.g. in combination with TopLinkInterceptor-managed Sessions.
Convenience getSession
and releaseSession
methods are provided for that usage style.
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 |
---|
public TopLinkDaoSupport()
Method Detail |
---|
public final void setSessionFactory(SessionFactory sessionFactory)
protected TopLinkTemplate createTopLinkTemplate(SessionFactory sessionFactory)
Can be overridden in subclasses to provide a TopLinkTemplate instance with different configuration, or a custom TopLinkTemplate subclass.
sessionFactory
- the TopLink SessionFactory to create a TopLinkTemplate for
setSessionFactory(org.springframework.orm.toplink.SessionFactory)
public final SessionFactory getSessionFactory()
public final void setTopLinkTemplate(TopLinkTemplate topLinkTemplate)
public final TopLinkTemplate getTopLinkTemplate()
protected final void checkDaoConfig()
DaoSupport
Implementors should be marked as final
, to make it clear that
concrete subclasses are not supposed to override this template method themselves.
checkDaoConfig
in class DaoSupport
protected final oracle.toplink.sessions.Session getSession() throws DataAccessResourceFailureException, IllegalStateException
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.
DataAccessResourceFailureException
- if the Session couldn't be created
IllegalStateException
- if no thread-bound Session found and allowCreate falseTopLinkTemplate
,
SessionFactoryUtils.getSession(SessionFactory, boolean)
,
TopLinkInterceptor
,
TopLinkTemplate
,
TopLinkCallback
protected final oracle.toplink.sessions.Session getSession(boolean allowCreate) throws DataAccessResourceFailureException, IllegalStateException
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.
allowCreate
- if a new Session should be created if no thread-bound found
DataAccessResourceFailureException
- if the Session couldn't be created
IllegalStateException
- if no thread-bound Session found and allowCreate falseSessionFactoryUtils.getSession(SessionFactory, boolean)
,
TopLinkInterceptor
,
TopLinkTemplate
,
TopLinkCallback
protected final DataAccessException convertTopLinkAccessException(oracle.toplink.exceptions.TopLinkException ex)
org.springframework.dao
hierarchy. Will automatically detect
wrapped SQLExceptions and convert them accordingly.
Delegates to the convertTopLinkAccessException method of this DAO's TopLinkTemplate.
ex
- TopLinkException that occured
setTopLinkTemplate(org.springframework.orm.toplink.TopLinkTemplate)
,
TopLinkAccessor.convertTopLinkAccessException(oracle.toplink.exceptions.TopLinkException)
protected final void releaseSession(oracle.toplink.sessions.Session session)
session
- the TopLink Session to closeSessionFactoryUtils.releaseSession(oracle.toplink.sessions.Session, org.springframework.orm.toplink.SessionFactory)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |