org.apache.ignite.cache.store.spring

## Class CacheSpringStoreSessionListener

- java.lang.Object
- - org.apache.ignite.cache.store.spring.CacheSpringStoreSessionListener

- All Implemented Interfaces:
    CacheStoreSessionListener, LifecycleAware

      public class CacheSpringStoreSessionListener
      extends Object
      implements CacheStoreSessionListener, LifecycleAware

  Cache store session listener based on Spring transaction management.

  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 Summary

    Constructors
    Constructor and Description
    `CacheSpringStoreSessionListener()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CacheSpringStoreSessionListener

          public CacheSpringStoreSessionListener()

  - ### Method Detail

    - #### setTransactionManager

          public void setTransactionManager(org.springframework.transaction.PlatformTransactionManager txMgr)

      Sets transaction manager.

      Either transaction manager or data source is required. If none is provided, exception will be thrown on startup.

      Parameters:
        `txMgr` - Transaction manager.

    - #### getTransactionManager

          public org.springframework.transaction.PlatformTransactionManager getTransactionManager()

      Gets transaction manager.
      Returns:
        Transaction manager.

    - #### setDataSource

          public void setDataSource(DataSource dataSrc)

      Sets data source.

      Either transaction manager or data source is required. If none is provided, exception will be thrown on startup.

      Parameters:
        `dataSrc` - Data source.

    - #### getDataSource

          public DataSource getDataSource()

      Gets data source.
      Returns:
        Data source.

    - #### start

          public void start()
                     throws IgniteException

      Starts grid component, called on grid start.
      Specified by:
        `start` in interface `LifecycleAware`
      Throws:
        `IgniteException` - If failed.

    - #### stop

          public void stop()
                    throws IgniteException

      Stops grid component, called on grid shutdown.
      Specified by:
        `stop` in interface `LifecycleAware`
      Throws:
        `IgniteException` - If failed.

    - #### onSessionStart

          public void onSessionStart(CacheStoreSession ses)

      On session start callback.

      Called before any store operation within a session is invoked.

      Specified by:
        `onSessionStart` in interface `CacheStoreSessionListener`
      Parameters:
        `ses` - Current session.

    - #### onSessionEnd

          public void onSessionEnd(CacheStoreSession ses,
                                   boolean commit)

      On session end callback.

      Called after all operations within a session are invoked.

      Specified by:
        `onSessionEnd` in interface `CacheStoreSessionListener`
      Parameters:
        `ses` - Current session.
        `commit` - `True` if persistence store transaction should commit, `false` for rollback.

2020 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.9.1
Release Date | : December 9 2020