|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.orm.toplink.LocalSessionFactory org.springframework.orm.toplink.LocalSessionFactoryBean
public class LocalSessionFactoryBean
Factory bean that configures a TopLink SessionFactory and provides it as bean reference. This is the usual way to define a TopLink SessionFactory in a Spring application context, allowing to pass it to TopLink DAOs as bean reference.
See the base class LocalSessionFactory for configuration details.
This class also implements the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor, for AOP-based translation of native exceptions to Spring DataAccessExceptions. Hence, the presence of a LocalSessionFactoryBean automatically enables a PersistenceExceptionTranslationPostProcessor to translate TopLink exceptions.
If your DAOs expect to receive a raw TopLink Session, consider defining a
TransactionAwareSessionAdapter in front of this bean. This adapter will provide
a TopLink Session rather than a SessionFactory as bean reference. Your DAOs can
then, for example, access the currently active Session and UnitOfWork via
Session.getActiveSession()
and Session.getActiveUnitOfWork()
,
respectively. Note that you can still access the SessionFactory too, by defining
a bean reference that points directly at the LocalSessionFactoryBean.
LocalSessionFactory
,
TransactionAwareSessionAdapter
,
PersistenceExceptionTranslationPostProcessor
Field Summary |
---|
Fields inherited from class org.springframework.orm.toplink.LocalSessionFactory |
---|
DEFAULT_SESSION_NAME, DEFAULT_SESSIONS_XML, logger |
Constructor Summary | |
---|---|
LocalSessionFactoryBean()
|
Method Summary | |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware). |
DataAccessException |
convertTopLinkAccessException(oracle.toplink.exceptions.TopLinkException ex)
Convert the given TopLinkException to an appropriate exception from the org.springframework.dao hierarchy. |
void |
destroy()
Invoked by a BeanFactory on destruction of a singleton. |
SQLExceptionTranslator |
getJdbcExceptionTranslator()
Return the JDBC exception translator for this instance, if any. |
Object |
getObject()
Return an instance (possibly shared or independent) of the object managed by this factory. |
Class |
getObjectType()
Return the type of object that this FactoryBean creates, or null
if not known in advance. |
boolean |
isSingleton()
Is the bean managed by this factory a singleton or a prototype? |
void |
setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
Set the JDBC exception translator for this SessionFactory. |
DataAccessException |
translateExceptionIfPossible(RuntimeException ex)
Implementation of the PersistenceExceptionTranslator interface, as autodetected by Spring's PersistenceExceptionTranslationPostProcessor. |
Methods inherited from class org.springframework.orm.toplink.LocalSessionFactory |
---|
createSessionFactory, getSessionManager, loadDatabaseSession, newSessionFactory, reflectivelySetDatabaseLogin, setConfigLocation, setDatabaseLogin, setDatabasePlatform, setDataSource, setSessionClassLoader, setSessionLog, setSessionName |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LocalSessionFactoryBean()
Method Detail |
---|
public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator)
Applied to any SQLException root cause of a TopLink DatabaseException, within Spring's PersistenceExceptionTranslator mechanism. The default is to rely on TopLink's native exception translation.
jdbcExceptionTranslator
- the exception translatorDatabaseException
,
SQLErrorCodeSQLExceptionTranslator
,
SQLStateSQLExceptionTranslator
public SQLExceptionTranslator getJdbcExceptionTranslator()
public void afterPropertiesSet() throws oracle.toplink.exceptions.TopLinkException
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
oracle.toplink.exceptions.TopLinkException
public Object getObject()
FactoryBean
As with a BeanFactory
, this allows support for both the
Singleton and Prototype design pattern.
If this FactoryBean is not fully initialized yet at the time of
the call (for example because it is involved in a circular reference),
throw a corresponding FactoryBeanNotInitializedException
.
As of Spring 2.0, FactoryBeans are allowed to return null
objects. The factory will consider this as normal value to be used; it
will not throw a FactoryBeanNotInitializedException in this case anymore.
FactoryBean implementations are encouraged to throw
FactoryBeanNotInitializedException themselves now, as appropriate.
getObject
in interface FactoryBean
null
)FactoryBeanNotInitializedException
public Class getObjectType()
FactoryBean
null
if not known in advance.
This allows one to check for specific types of beans without instantiating objects, for example on autowiring.
In the case of implementations that are creating a singleton object, this method should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too.
This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available.
NOTE: Autowiring will simply ignore FactoryBeans that return
null
here. Therefore it is highly recommended to implement
this method properly, using the current state of the FactoryBean.
getObjectType
in interface FactoryBean
null
if not known at the time of the callListableBeanFactory.getBeansOfType(java.lang.Class)
public boolean isSingleton()
FactoryBean
getObject()
always return the same object
(a reference that can be cached)?
NOTE: If a FactoryBean indicates to hold a singleton object,
the object returned from getObject()
might get cached
by the owning BeanFactory. Hence, do not return true
unless the FactoryBean always exposes the same reference.
The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there.
isSingleton
in interface FactoryBean
FactoryBean.getObject()
public DataAccessException translateExceptionIfPossible(RuntimeException ex)
Converts the exception if it is a TopLinkException;
else returns null
to indicate an unknown exception.
translateExceptionIfPossible
in interface PersistenceExceptionTranslator
ex
- a RuntimeException thrown
null
if the
exception could not be translated, as in this case it may result from
user code rather than an actual persistence problem)PersistenceExceptionTranslationPostProcessor
,
convertTopLinkAccessException(oracle.toplink.exceptions.TopLinkException)
public DataAccessException convertTopLinkAccessException(oracle.toplink.exceptions.TopLinkException ex)
org.springframework.dao
hierarchy.
Will automatically apply a specified SQLExceptionTranslator to a TopLink DatabaseException, else rely on TopLink's default translation.
ex
- TopLinkException that occured
SessionFactoryUtils.convertTopLinkAccessException(oracle.toplink.exceptions.TopLinkException)
,
setJdbcExceptionTranslator(org.springframework.jdbc.support.SQLExceptionTranslator)
public void destroy()
DisposableBean
destroy
in interface DisposableBean
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |