/* * Hibernate, Relational Persistence for Idiomatic Java * * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. */ package org.hibernate.cache.jcache.access; import org.hibernate.cache.CacheException; import org.hibernate.cache.internal.DefaultCacheKeysFactory; import org.hibernate.cache.jcache.JCacheEntityRegion; import org.hibernate.cache.spi.access.EntityRegionAccessStrategy; import org.hibernate.cache.spi.access.SoftLock; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.persister.entity.EntityPersister; /** * @author Alex Snaps */ public class ReadOnlyEntityRegionAccessStrategy extends JCacheRegionAccessStrategy<JCacheEntityRegion> implements EntityRegionAccessStrategy { public ReadOnlyEntityRegionAccessStrategy(JCacheEntityRegion jCacheEntityRegion) { super( jCacheEntityRegion ); } @Override public boolean insert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException { return false; } @Override public boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value, Object version) throws CacheException { getRegion().put( key, value ); return true; } @Override public boolean update(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException { throw new UnsupportedOperationException( "This is a ReadOnly strategy!" ); } @Override public boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock) throws CacheException { throw new UnsupportedOperationException( "This is a ReadOnly strategy!" ); } @Override public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) { return DefaultCacheKeysFactory.staticCreateEntityKey( id, persister, factory, tenantIdentifier ); } @Override public Object getCacheKeyId(Object cacheKey) { return DefaultCacheKeysFactory.staticGetEntityId( cacheKey ); } }