public interface CacheStoreSessionListener
The most common use case for session listeners is database connection and transaction management. Store can be invoked one or several times during one session, depending on whether it's executed within cache transaction or not. In any case, you have to create a connection when session is started and commit it or rollback when session is finished.
Cache store session listener allows to implement this and other scenarios providing two callback methods:
onSessionStart(CacheStoreSession)- called when a session is created prior to all operations within his session.
onSessionEnd(CacheStoreSession, boolean)- called after all operations within a session are invoked.
CacheJdbcStoreSessionListener- JDBC-based session listener. For each session it gets a new JDBC connection from provided
DataSourceand commits (or rolls back) it when session ends.
org.apache.ignite.cache.store.spring.CacheSpringStoreSessionListener- session listener based on Spring transaction management. It starts a new DB transaction for each session and commits (or rolls back) it when session ends. If there is no ongoing cache transaction, this listener is no-op.
org.apache.ignite.cache.store.hibernate.CacheHibernateStoreSessionListener- Hibernate-based session listener. It creates a new Hibernate session for each Ignite session. If there is an ongoing cache transaction, a corresponding Hibernate transaction is created as well.
IgniteConfiguration.setCacheStoreSessionListenerFactories(Factory)configuration property. This will we called for any store session, not depending on what caches participate in transaction.
CacheConfiguration.setCacheStoreSessionListenerFactories(Factory)configuration property. This will be called only if the cache participates in transaction.
CacheJdbcStoreSessionListenercan be configured in Spring XML configuration file:
<bean class="org.apache.ignite.configuration.IgniteConfiguration"> ... <property name="CacheStoreSessionListenerFactories"> <list> <bean class="javax.cache.configuration.FactoryBuilder$SingletonFactory"> <constructor-arg> <bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener"> <!-- Inject external data source. --> <property name="dataSource" ref="jdbc-data-source"/> </bean> </constructor-arg> </bean> </list> </property> </bean>
|Modifier and Type||Method and Description|
On session end callback.
On session start callback.
void onSessionStart(CacheStoreSession ses)
Called before any store operation within a session is invoked.
ses- Current session.
void onSessionEnd(CacheStoreSession ses, boolean commit)
Called after all operations within a session are invoked.
ses- Current session.
Trueif persistence store transaction should commit,
Follow @ApacheIgnite Ignite Database and Caching Platform : ver. 2.15.0 Release Date : April 25 2023