|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object 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.
Field Summary | |
---|---|
protected Log |
logger
|
Constructor Summary | |
---|---|
TopLinkDaoSupport()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware). |
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 |
initDao()
Subclasses can override this for custom initialization behavior. |
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 java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Log logger
Constructor Detail |
---|
public TopLinkDaoSupport()
Method Detail |
---|
public final void setSessionFactory(SessionFactory sessionFactory)
createTopLinkTemplate(org.springframework.orm.toplink.SessionFactory)
,
setTopLinkTemplate(org.springframework.orm.toplink.TopLinkTemplate)
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)
setSessionFactory(org.springframework.orm.toplink.SessionFactory)
public final TopLinkTemplate getTopLinkTemplate()
public final void afterPropertiesSet() throws Exception
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
Exception
- in the event of misconfiguration (such
as failure to set an essential property) or if initialization fails.protected void initDao() throws Exception
Exception
- if initialization failsprotected 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 |