org.apache.ignite.cache.hibernate

## Class HibernateReadOnlyAccessStrategy

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

-     public class HibernateReadOnlyAccessStrategy
      extends HibernateAccessStrategyAdapter

  Implementation of READ_ONLY cache access strategy.

  Configuration of L2 cache and per-entity cache access strategy can be set in the Hibernate configuration file:

       <hibernate-configuration>
           <!-- Enable L2 cache. -->
           <property name="cache.use_second_level_cache">true</property>

           <!-- Use Ignite as L2 cache provider. -->
           <property name="cache.region.factory_class">org.apache.ignite.cache.hibernate.HibernateRegionFactory</property>

           <!-- Specify entity. -->
           <mapping class="com.example.Entity"/>

           <!-- Enable L2 cache with read-only access strategy for entity. -->
           <class-cache class="com.example.Entity" usage="read-only"/>
       </hibernate-configuration>

  Also cache access strategy can be set using annotations:

       @javax.persistence.Entity
       @javax.persistence.Cacheable
       @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
       public class Entity { ... }

- - ### Field Summary

    - ### Fields inherited from class org.apache.ignite.cache.hibernate.HibernateAccessStrategyAdapter

      `cache, ignite, log`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HibernateReadOnlyAccessStrategy(Ignite ignite, HibernateCacheProxy cache, HibernateExceptionConverter eConverter)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `afterInsert(Object key, Object val)` Called after Hibernate inserted object in the database and transaction successfully completed.
    `boolean` | `afterUpdate(Object key, Object val)` Called after Hibernate updated object in the database and transaction successfully completed.
    `boolean` | `insert(Object key, Object val)` Called after Hibernate inserted object in the database but before transaction completed.
    `void` | `lock(Object key)` Called during database transaction execution before Hibernate attempts to update or remove given key.
    `void` | `remove(Object key)` Called after Hibernate removed object from database but before transaction completed.
    `void` | `unlock(Object key)` Called after Hibernate failed to update or successfully removed given key.
    `boolean` | `update(Object key, Object val)` Called after Hibernate updated object in the database but before transaction completed.

    - ### Methods inherited from class org.apache.ignite.cache.hibernate.HibernateAccessStrategyAdapter

      `evict, evict, evictAll, evictAll, get, lockRegion, putFromLoad, putFromLoad, removeAll, unlockRegion`

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

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

- - ### Constructor Detail

    - #### HibernateReadOnlyAccessStrategy

          public HibernateReadOnlyAccessStrategy(Ignite ignite,
                                                 HibernateCacheProxy cache,
                                                 HibernateExceptionConverter eConverter)

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

  - ### Method Detail

    - #### insert

          public boolean insert(Object key,
                                Object val)

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

    - #### afterInsert

          public boolean afterInsert(Object key,
                                     Object val)

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

    - #### lock

          public void lock(Object key)

      Called during database transaction execution before Hibernate attempts to update or remove given key.
      Specified by:
        `lock` in class `HibernateAccessStrategyAdapter`
      Parameters:
        `key` - Key.

    - #### unlock

          public void unlock(Object key)

      Called after Hibernate failed to update or successfully removed given key.
      Specified by:
        `unlock` in class `HibernateAccessStrategyAdapter`
      Parameters:
        `key` - Key.

    - #### remove

          public void remove(Object key)

      Called after Hibernate removed object from database but before transaction completed.
      Specified by:
        `remove` in class `HibernateAccessStrategyAdapter`
      Parameters:
        `key` - Key,

    - #### update

          public boolean update(Object key,
                                Object val)

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

    - #### afterUpdate

          public boolean afterUpdate(Object key,
                                     Object val)

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

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