All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gridgain.grid.cache.hibernate.GridHibernateReadOnlyAccessStrategy Maven / Gradle / Ivy

/* 
 Copyright (C) GridGain Systems. All Rights Reserved.
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

/*  _________        _____ __________________        _____
 *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
 *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
 *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
 *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
 */

package org.gridgain.grid.cache.hibernate;

import org.gridgain.grid.*;
import org.gridgain.grid.cache.*;
import org.hibernate.cache.*;
import org.hibernate.cache.spi.access.*;
import org.jetbrains.annotations.*;

/**
 * Implementation of {@link AccessType#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 GridGain as L2 cache provider. -->
 *     <property name="cache.region.factory_class">org.gridgain.grid.cache.hibernate.GridHibernateRegionFactory</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 { ... }
 * 
* */ public class GridHibernateReadOnlyAccessStrategy extends GridHibernateAccessStrategyAdapter { /** * @param grid Grid. * @param cache Cache. */ public GridHibernateReadOnlyAccessStrategy(Grid grid, GridCache cache) { super(grid, cache); } /** {@inheritDoc} */ @Override protected boolean insert(Object key, Object val) throws CacheException { return false; } /** {@inheritDoc} */ @Override protected boolean afterInsert(Object key, Object val) throws CacheException { try { cache.putx(key, val); return true; } catch (GridException e) { throw new CacheException(e); } } /** {@inheritDoc} */ @Nullable @Override protected SoftLock lock(Object key) throws CacheException { return null; } /** {@inheritDoc} */ @Override protected void unlock(Object key, SoftLock lock) throws CacheException { // No-op. } /** {@inheritDoc} */ @Override protected void remove(Object key) throws CacheException { // No-op. } /** {@inheritDoc} */ @Override protected boolean update(Object key, Object val) throws CacheException { throw new UnsupportedOperationException("Updates are not supported for read-only access strategy."); } /** {@inheritDoc} */ @Override protected boolean afterUpdate(Object key, Object val, SoftLock lock) throws CacheException { throw new UnsupportedOperationException("Updates are not supported for read-only access strategy."); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy