diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheCollectionRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheCollectionRegionAccessStrategy.java index 8ef7f4a5c1..449f1b40c7 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheCollectionRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheCollectionRegionAccessStrategy.java @@ -75,19 +75,13 @@ public class ReadOnlyEhcacheCollectionRegionAccessStrategy } } - /** - * Throws UnsupportedOperationException since this cache is read-only - * - * @throws UnsupportedOperationException always - */ public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException { - throw new UnsupportedOperationException( "Can't write to a readonly object" ); + return null; } /** * A no-op since this cache is read-only */ public void unlockItem(Object key, SoftLock lock) throws CacheException { - //throw new UnsupportedOperationException("Can't write to a readonly object"); } } diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheEntityRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheEntityRegionAccessStrategy.java index 0f0cf166f3..acd8fc2c5f 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheEntityRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheEntityRegionAccessStrategy.java @@ -78,20 +78,15 @@ public class ReadOnlyEhcacheEntityRegionAccessStrategy extends AbstractEhcacheAc } } - /** - * Throws UnsupportedOperationException since this cache is read-only - * - * @throws UnsupportedOperationException always - */ public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException { - throw new UnsupportedOperationException( "Can't write to a readonly object" ); + return null; } /** * A no-op since this cache is read-only */ public void unlockItem(Object key, SoftLock lock) throws CacheException { - //throw new UnsupportedOperationException("Can't write to a readonly object"); + evict( key ); } /** diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheNaturalIdRegionAccessStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheNaturalIdRegionAccessStrategy.java index 993932943a..78d8839266 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheNaturalIdRegionAccessStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheNaturalIdRegionAccessStrategy.java @@ -75,20 +75,15 @@ public class ReadOnlyEhcacheNaturalIdRegionAccessStrategy } } - /** - * Throws UnsupportedOperationException since this cache is read-only - * - * @throws UnsupportedOperationException always - */ public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException { - throw new UnsupportedOperationException( "Can't write to a readonly object" ); + return null; } /** * A no-op since this cache is read-only */ public void unlockItem(Object key, SoftLock lock) throws CacheException { - //throw new UnsupportedOperationException("Can't write to a readonly object"); + region.remove( key ); } /** diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/ReadOnlyAccess.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/ReadOnlyAccess.java index 2c7085fc12..f2ca29e713 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/ReadOnlyAccess.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/ReadOnlyAccess.java @@ -16,25 +16,6 @@ class ReadOnlyAccess extends TransactionalAccess { super( naturalIdRegion ); } - @Override - public SoftLock lockItem(Object key, Object version) throws CacheException { - throw new UnsupportedOperationException( "Illegal attempt to edit read only item" ); - } - - @Override - public SoftLock lockRegion() throws CacheException { - throw new UnsupportedOperationException( "Illegal attempt to edit read only item" ); - } - - @Override - public void unlockItem(Object key, SoftLock lock) throws CacheException { - log.error( "Illegal attempt to edit read only item" ); - } - - @Override - public void unlockRegion(SoftLock lock) throws CacheException { - log.error( "Illegal attempt to edit read only item" ); - } @Override public boolean update(Object key, Object value) throws CacheException { diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/BaseCollectionRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/BaseCollectionRegionAccessStrategy.java index dd9488d47b..7e0702a3d8 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/BaseCollectionRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/BaseCollectionRegionAccessStrategy.java @@ -31,7 +31,9 @@ import org.hibernate.cache.spi.access.CollectionRegionAccessStrategy; */ class BaseCollectionRegionAccessStrategy extends BaseRegionAccessStrategy implements CollectionRegionAccessStrategy { private final CollectionRegionImpl region; - + BaseCollectionRegionAccessStrategy(CollectionRegionImpl region) { + this.region = region; + } @Override protected BaseGeneralDataRegion getInternalRegion() { return region; @@ -46,8 +48,4 @@ class BaseCollectionRegionAccessStrategy extends BaseRegionAccessStrategy implem public CollectionRegion getRegion() { return region; } - - BaseCollectionRegionAccessStrategy(CollectionRegionImpl region) { - this.region = region; - } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyCollectionRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyCollectionRegionAccessStrategy.java index 5d314cd9a6..6a8382e9ee 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyCollectionRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyCollectionRegionAccessStrategy.java @@ -33,25 +33,7 @@ import org.hibernate.internal.CoreMessageLogger; * @author Strong Liu */ class ReadOnlyCollectionRegionAccessStrategy extends BaseCollectionRegionAccessStrategy { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( - CoreMessageLogger.class, ReadOnlyCollectionRegionAccessStrategy.class.getName() - ); - ReadOnlyCollectionRegionAccessStrategy(CollectionRegionImpl region) { super( region ); } - - @Override - public void unlockItem(Object key, SoftLock lock) throws CacheException { - LOG.invalidEditOfReadOnlyItem( key ); - } - - @Override - public SoftLock lockItem(Object key, Object version) throws CacheException { - LOG.invalidEditOfReadOnlyItem( key ); - throw new UnsupportedOperationException( "Can't write to a readonly object" ); - } - - - } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyEntityRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyEntityRegionAccessStrategy.java index 57c1b7c41d..872807443f 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyEntityRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyEntityRegionAccessStrategy.java @@ -54,18 +54,9 @@ class ReadOnlyEntityRegionAccessStrategy extends BaseEntityRegionAccessStrategy return true; } - /** - * This cache is asynchronous hence a no-op - */ @Override public void unlockItem(Object key, SoftLock lock) throws CacheException { - LOG.invalidEditOfReadOnlyItem( key ); - } - - @Override - public SoftLock lockItem(Object key, Object version) throws CacheException { - LOG.invalidEditOfReadOnlyItem( key ); - throw new UnsupportedOperationException( "Can't write to a readonly object" ); + evict( key ); } /** diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyNaturalIdRegionAccessStrategy.java b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyNaturalIdRegionAccessStrategy.java index d8268e5260..45d4063517 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyNaturalIdRegionAccessStrategy.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyNaturalIdRegionAccessStrategy.java @@ -43,15 +43,6 @@ class ReadOnlyNaturalIdRegionAccessStrategy extends BaseNaturalIdRegionAccessStr @Override public void unlockItem(Object key, SoftLock lock) throws CacheException { - LOG.invalidEditOfReadOnlyItem( key ); + evict( key ); } - - @Override - public SoftLock lockItem(Object key, Object version) throws CacheException { - LOG.invalidEditOfReadOnlyItem( key ); - throw new UnsupportedOperationException( "Can't write to a readonly object" ); - } - - - }