org.apache.ignite.cache.hibernate

## Class HibernateAccessStrategyAdapter

- java.lang.Object
- - org.apache.ignite.cache.hibernate.HibernateAccessStrategyAdapter

- Direct Known Subclasses:
    HibernateNonStrictAccessStrategy, HibernateReadOnlyAccessStrategy, HibernateReadWriteAccessStrategy, HibernateTransactionalAccessStrategy

      public abstract class HibernateAccessStrategyAdapter
      extends Object

  Common interface used to implement Hibernate L2 cache access strategies.

  The expected sequences of steps related to various CRUD operations executed by Hibernate are:

  Insert:

  - Start DB transaction.
  - Execute database insert.
  - Call `insert(java.lang.Object, java.lang.Object)`.
  - Commit DB transaction.
  - Call `afterInsert(java.lang.Object, java.lang.Object)`.
  In case if some step fails and DB transaction is rolled back then `afterInsert(java.lang.Object, java.lang.Object)` is not called.

  Update:

  - Start DB transaction.
  - Call `lock(java.lang.Object)`.
  - Execute database update.
  - Call `update(java.lang.Object, java.lang.Object)`.
  - Commit DB transaction.
  - Call `afterUpdate(java.lang.Object, java.lang.Object)`.
  In case if `lock(java.lang.Object)` was called, but some other step fails and DB transaction is rolled back then `unlock(java.lang.Object)` is called for all locked keys.

  Delete:

  - Start DB transaction.
  - Call `lock(java.lang.Object)` for removing key.
  - Execute database delete.
  - Call `remove(java.lang.Object)`.
  - Commit DB transaction.
  - Call `unlock(java.lang.Object)`.
  In case if `lock(java.lang.Object)` was called, but some other step fails and DB transaction is rolled back then `unlock(java.lang.Object)` is called for all locked keys.

  In case if custom SQL update query is executed Hibernate clears entire cache region, for this case operations sequence is:

  - Start DB transaction.
  - Call `lockRegion()`.
  - Execute database query.
  - Call `removeAll()`.
  - Commit DB transaction.
  - Call `unlockRegion()`.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected HibernateCacheProxy` | `cache`
    `protected Ignite` | `ignite` Grid.
    `protected IgniteLogger` | `log`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `HibernateAccessStrategyAdapter(Ignite ignite, HibernateCacheProxy cache, HibernateExceptionConverter eConverter)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract boolean` | `afterInsert(Object key, Object val)` Called after Hibernate inserted object in the database and transaction successfully completed.
    `abstract boolean` | `afterUpdate(Object key, Object val)` Called after Hibernate updated object in the database and transaction successfully completed.
    `static void` | `evict(Ignite ignite, HibernateCacheProxy cache, Object key)` Called to remove object from cache without regard to transaction.
    `void` | `evict(Object key)` Called to remove object from cache without regard to transaction.
    `void` | `evictAll()` Called to remove all data from cache without regard to transaction.
    `static void` | `evictAll(org.apache.ignite.internal.processors.cache.IgniteInternalCache<Object,Object> cache)` Called to remove all data from cache without regard to transaction.
    `@Nullable Object` | `get(Object key)`
    `abstract boolean` | `insert(Object key, Object val)` Called after Hibernate inserted object in the database but before transaction completed.
    `abstract void` | `lock(Object key)` Called during database transaction execution before Hibernate attempts to update or remove given key.
    `void` | `lockRegion()` Called during database transaction execution before Hibernate executed update operation which should invalidate entire cache region.
    `void` | `putFromLoad(Object key, Object val)` Puts in cache value loaded from the database.
    `void` | `putFromLoad(Object key, Object val, boolean minimalPutOverride)`
    `abstract void` | `remove(Object key)` Called after Hibernate removed object from database but before transaction completed.
    `void` | `removeAll()` Called during database transaction execution to clear entire cache region after Hibernate executed database update, but before transaction completed.
    `abstract void` | `unlock(Object key)` Called after Hibernate failed to update or successfully removed given key.
    `void` | `unlockRegion()` Called after transaction clearing entire cache region completed.
    `abstract boolean` | `update(Object key, Object val)` Called after Hibernate updated object in the database but before transaction completed.

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

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

- - ### Field Detail

    - #### cache

          protected final HibernateCacheProxy cache

    - #### ignite

          protected final Ignite ignite

      Grid.

    - #### log

          protected final IgniteLogger log

  - ### Constructor Detail

    - #### HibernateAccessStrategyAdapter

          protected HibernateAccessStrategyAdapter(Ignite ignite,
                                                   HibernateCacheProxy cache,
                                                   HibernateExceptionConverter eConverter)

      Parameters:
        `ignite` - Node.
        `cache` - Cache.
        `eConverter` - Exception converter.

  - ### Method Detail

    - #### get

          @Nullable
          public @Nullable Object get(Object key)

      Parameters:
        `key` - Key.
      Returns:
        Cached value.

    - #### putFromLoad

          public void putFromLoad(Object key,
                                  Object val,
                                  boolean minimalPutOverride)

      Parameters:
        `key` - Key.
        `val` - Value.
        `minimalPutOverride` - MinimalPut flag

    - #### putFromLoad

          public void putFromLoad(Object key,
                                  Object val)

      Puts in cache value loaded from the database.
      Parameters:
        `key` - Key.
        `val` - Value.

    - #### lock

          public abstract void lock(Object key)

      Called during database transaction execution before Hibernate attempts to update or remove given key.
      Parameters:
        `key` - Key.

    - #### unlock

          public abstract void unlock(Object key)

      Called after Hibernate failed to update or successfully removed given key.
      Parameters:
        `key` - Key.

    - #### update

          public abstract boolean update(Object key,
                                         Object val)

      Called after Hibernate updated object in the database but before transaction completed.
      Parameters:
        `key` - Key.
        `val` - Value.
      Returns:
        `True` if operation updated cache.

    - #### afterUpdate

          public abstract boolean afterUpdate(Object key,
                                              Object val)

      Called after Hibernate updated object in the database and transaction successfully completed.
      Parameters:
        `key` - Key.
        `val` - Value.
      Returns:
        `True` if operation updated cache.

    - #### insert

          public abstract boolean insert(Object key,
                                         Object val)

      Called after Hibernate inserted object in the database but before transaction completed.
      Parameters:
        `key` - Key.
        `val` - Value.
      Returns:
        `True` if operation updated cache.

    - #### afterInsert

          public abstract boolean afterInsert(Object key,
                                              Object val)

      Called after Hibernate inserted object in the database and transaction successfully completed.
      Parameters:
        `key` - Key.
        `val` - Value.
      Returns:
        `True` if operation updated cache.

    - #### remove

          public abstract void remove(Object key)

      Called after Hibernate removed object from database but before transaction completed.
      Parameters:
        `key` - Key,

    - #### evict

          public void evict(Object key)

      Called to remove object from cache without regard to transaction.
      Parameters:
        `key` - Key.

    - #### evictAll

          public void evictAll()

      Called to remove all data from cache without regard to transaction.

    - #### removeAll

          public final void removeAll()

      Called during database transaction execution to clear entire cache region after Hibernate executed database update, but before transaction completed.

    - #### lockRegion

          public void lockRegion()

      Called during database transaction execution before Hibernate executed update operation which should invalidate entire cache region.

    - #### unlockRegion

          public void unlockRegion()

      Called after transaction clearing entire cache region completed.

    - #### evict

          public static void evict(Ignite ignite,
                                   HibernateCacheProxy cache,
                                   Object key)

      Called to remove object from cache without regard to transaction.
      Parameters:
        `ignite` - Grid.
        `cache` - Cache.
        `key` - Key.

    - #### evictAll

          public static void evictAll(org.apache.ignite.internal.processors.cache.IgniteInternalCache<Object,Object> cache)
                               throws IgniteCheckedException

      Called to remove all data from cache without regard to transaction.
      Parameters:
        `cache` - Cache.
      Throws:
        `IgniteCheckedException` - If failed.

2021 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.11.0
Release Date | : September 11 2021