public class CacheHibernateStoreSessionListener extends Object implements CacheStoreSessionListener, LifecycleAware
This listener creates a new Hibernate session for each store session. If there is an ongoing cache transaction, a corresponding Hibernate transaction is created as well.
The Hibernate session is saved as a store session
attachment
.
The listener guarantees that the session will be
available for any store operation. If there is an
ongoing cache transaction, all operations within this
transaction will share a DB transaction.
As an example, here is how the CacheWriter.write(javax.cache.Cache.Entry)
method can be implemented if CacheHibernateStoreSessionListener
is configured:
private static class Store extends CacheStoreAdapter<Integer, Integer> { @CacheStoreSessionResource private CacheStoreSession ses; @Override public void write(Cache.Entry<? extends Integer, ? extends Integer> entry) throws CacheWriterException { // Get Hibernate session from the current store session. Session hibSes = ses.attachment(); // Persist the value. hibSes.persist(entry.getValue()); } }Hibernate session will be automatically created by the listener at the start of the session and closed when it ends.
CacheHibernateStoreSessionListener
requires that either
setSessionFactory(SessionFactory)
session factory}
or Hibernate configuration file
is provided. If non of them is set, exception is thrown. Is both are provided,
session factory will be used.
构造器和说明 |
---|
CacheHibernateStoreSessionListener() |
限定符和类型 | 方法和说明 |
---|---|
String |
getHibernateConfigurationPath()
Gets hibernate configuration path.
|
org.hibernate.SessionFactory |
getSessionFactory()
Gets Hibernate session factory.
|
void |
onSessionEnd(CacheStoreSession ses,
boolean commit) |
void |
onSessionStart(CacheStoreSession ses) |
void |
setHibernateConfigurationPath(String hibernateCfgPath)
Sets hibernate configuration path.
|
void |
setSessionFactory(org.hibernate.SessionFactory sesFactory)
Sets Hibernate session factory.
|
void |
start() |
void |
stop() |
public void setSessionFactory(org.hibernate.SessionFactory sesFactory)
Either session factory or configuration file is required. If none is provided, exception will be thrown on startup.
sesFactory
- Session factory.public org.hibernate.SessionFactory getSessionFactory()
public void setHibernateConfigurationPath(String hibernateCfgPath)
Either session factory or configuration file is required. If none is provided, exception will be thrown on startup.
hibernateCfgPath
- Hibernate configuration path.public String getHibernateConfigurationPath()
public void start() throws IgniteException
start
在接口中 LifecycleAware
IgniteException
public void stop() throws IgniteException
stop
在接口中 LifecycleAware
IgniteException
public void onSessionStart(CacheStoreSession ses)
onSessionStart
在接口中 CacheStoreSessionListener
public void onSessionEnd(CacheStoreSession ses, boolean commit)
onSessionEnd
在接口中 CacheStoreSessionListener
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.8.0-SNAPSHOT Release Date : 四月 9 2019