public class CacheSpringStoreSessionListener extends Object implements CacheStoreSessionListener, LifecycleAware
This listener starts a new DB transaction for each session and commits or rolls it back when session ends. If there is no ongoing cache transaction, this listener is no-op.
Store implementation can use any Spring APIs like JdbcTemplate
and others. The listener will guarantee that if there is an
ongoing cache transaction, all store operations within this
transaction will be automatically enlisted in the same database
transaction.
CacheSpringStoreSessionListener
requires that either
transaction manager
or data source
is configured. If non of them is
provided, exception is thrown. Is both are provided, data source will be
ignored.
If there is a transaction, a TransactionStatus
object will be saved
as a store session attachment
. It
can be used to acquire current DB transaction status.
Constructor and Description |
---|
CacheSpringStoreSessionListener() |
Modifier and Type | Method and Description |
---|---|
DataSource |
getDataSource()
Gets data source.
|
org.springframework.transaction.PlatformTransactionManager |
getTransactionManager()
Gets transaction manager.
|
void |
onSessionEnd(CacheStoreSession ses,
boolean commit)
On session end callback.
|
void |
onSessionStart(CacheStoreSession ses)
On session start callback.
|
void |
setDataSource(DataSource dataSrc)
Sets data source.
|
void |
setTransactionManager(org.springframework.transaction.PlatformTransactionManager txMgr)
Sets transaction manager.
|
void |
start()
Starts grid component, called on grid start.
|
void |
stop()
Stops grid component, called on grid shutdown.
|
public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager txMgr)
Either transaction manager or data source is required. If none is provided, exception will be thrown on startup.
txMgr
- Transaction manager.public org.springframework.transaction.PlatformTransactionManager getTransactionManager()
public void setDataSource(DataSource dataSrc)
Either transaction manager or data source is required. If none is provided, exception will be thrown on startup.
dataSrc
- Data source.public DataSource getDataSource()
public void start() throws IgniteException
start
in interface LifecycleAware
IgniteException
- If failed.public void stop() throws IgniteException
stop
in interface LifecycleAware
IgniteException
- If failed.public void onSessionStart(CacheStoreSession ses)
Called before any store operation within a session is invoked.
onSessionStart
in interface CacheStoreSessionListener
ses
- Current session.public void onSessionEnd(CacheStoreSession ses, boolean commit)
Called after all operations within a session are invoked.
onSessionEnd
in interface CacheStoreSessionListener
ses
- Current session.commit
- True
if persistence store transaction
should commit, false
for rollback.
GridGain In-Memory Computing Platform : ver. 8.9.19 Release Date : April 10 2025