|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.springframework.orm.toplink.LocalSessionFactory
org.springframework.orm.toplink.LocalSessionFactoryBean
public class LocalSessionFactoryBean
FactoryBean that creates a
TopLink SessionFactory. This is the usual way to set up a shared
TopLink SessionFactory in a Spring application context; the SessionFactory
can then be passed to TopLink-based DAOs via dependency injection.
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 as well, 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 object managed by this factory a singleton? |
void |
setBeanClassLoader(ClassLoader classLoader)
Sets the given bean ClassLoader as TopLink Session ClassLoader. |
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, getLoginPropertyMap, getSessionManager, loadDatabaseSession, newSessionFactory, setConfigLocation, setDatabaseLogin, setDatabaseLogin, setDatabasePlatform, setDataSource, setLoginProperties, setLoginPropertyMap, 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.
DatabaseException,
SQLErrorCodeSQLExceptionTranslator,
SQLStateSQLExceptionTranslatorpublic SQLExceptionTranslator getJdbcExceptionTranslator()
public void setBeanClassLoader(ClassLoader classLoader)
setBeanClassLoader in interface BeanClassLoaderAwareclassLoader - the owning class loader; may be null in
which case a default ClassLoader must be used, for example
the ClassLoader obtained via
ClassUtils.getDefaultClassLoader()LocalSessionFactory.setSessionClassLoader(java.lang.ClassLoader)
public void afterPropertiesSet()
throws oracle.toplink.exceptions.TopLinkException
InitializingBeanThis 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 InitializingBeanoracle.toplink.exceptions.TopLinkExceptionpublic Object getObject()
FactoryBeanAs 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 FactoryBeannull)FactoryBeanNotInitializedExceptionpublic Class getObjectType()
FactoryBeannull 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 FactoryBeannull if not known at the time of the callListableBeanFactory.getBeansOfType(java.lang.Class)public boolean isSingleton()
FactoryBeanFactoryBean.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.
NOTE: This method returning false does not
necessarily indicate that returned objects are independent instances.
An implementation of the extended SmartFactoryBean interface
may explicitly indicate independent instances through its
SmartFactoryBean.isPrototype() method. Plain FactoryBean
implementations which do not implement this extended interface are
simply assumed to always return independent instances if the
isSingleton() implementation returns false.
isSingleton in interface FactoryBeanFactoryBean.getObject(),
SmartFactoryBean.isPrototype()public DataAccessException translateExceptionIfPossible(RuntimeException ex)
Converts the exception if it is a TopLinkException;
else returns null to indicate an unknown exception.
translateExceptionIfPossible in interface PersistenceExceptionTranslatorex - 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
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||