Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

HHH-7350 readonly entity can't be deleted from 2LC #341

Closed
wants to merge 3 commits into from

3 participants

Strong Liu Galder Zamarreño andrigtmiller
Strong Liu
Collaborator
stliu commented May 24, 2012

No description provided.

and others added some commits May 24, 2012
andrigtmiller HHH-7350 - removed overridden methods in ReadOnlyAccess lock/unlock a…
…n instance and/or region of the cache, since inserts and deletes are allowed with a CacheConcurrencyStrategy of READ_ONLY.
9dcdc83
andrigtmiller HHH-7350 - Fixed up the unit tests, to allow the lock of the cache re…
…gion for an access strategy of READ_ONLY.
5496ca0
Strong Liu HHH-7350 read-only entities can not be deleted from 2LC d6a63db
Galder Zamarreño
Collaborator
galderz commented May 25, 2012

Hmm, the Infinispan part is already solved: 61a8416

I don't know about the rest.

Strong Liu stliu closed this June 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 2 authors.

May 24, 2012
andrigtmiller HHH-7350 - removed overridden methods in ReadOnlyAccess lock/unlock a…
…n instance and/or region of the cache, since inserts and deletes are allowed with a CacheConcurrencyStrategy of READ_ONLY.
9dcdc83
andrigtmiller HHH-7350 - Fixed up the unit tests, to allow the lock of the cache re…
…gion for an access strategy of READ_ONLY.
5496ca0
May 25, 2012
Strong Liu HHH-7350 read-only entities can not be deleted from 2LC d6a63db
This page is out of date. Refresh to see the latest.

Showing 12 changed files with 13 additions and 142 deletions. Show diff stats Hide diff stats

  1. 8  .../main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheCollectionRegionAccessStrategy.java
  2. 9  .../src/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheEntityRegionAccessStrategy.java
  3. 9  ...c/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheNaturalIdRegionAccessStrategy.java
  4. 17  hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java
  5. 18  hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java
  6. 19  hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/ReadOnlyAccess.java
  7. 7  hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/EntityRegionImplTestCase.java
  8. 20  hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/ReadOnlyExtraAPITestCase.java
  9. 8  hibernate-testing/src/main/java/org/hibernate/testing/cache/BaseCollectionRegionAccessStrategy.java
  10. 18  hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyCollectionRegionAccessStrategy.java
  11. 11  hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyEntityRegionAccessStrategy.java
  12. 11  hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyNaturalIdRegionAccessStrategy.java
8  ...in/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheCollectionRegionAccessStrategy.java
@@ -75,19 +75,13 @@ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object ve
75 75
 		}
76 76
 	}
77 77
 
78  
-	/**
79  
-	 * Throws UnsupportedOperationException since this cache is read-only
80  
-	 *
81  
-	 * @throws UnsupportedOperationException always
82  
-	 */
83 78
 	public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException {
84  
-		throw new UnsupportedOperationException( "Can't write to a readonly object" );
  79
+		return null;
85 80
 	}
86 81
 
87 82
 	/**
88 83
 	 * A no-op since this cache is read-only
89 84
 	 */
90 85
 	public void unlockItem(Object key, SoftLock lock) throws CacheException {
91  
-		//throw new UnsupportedOperationException("Can't write to a readonly object");
92 86
 	}
93 87
 }
9  ...c/main/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheEntityRegionAccessStrategy.java
@@ -78,20 +78,15 @@ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object ve
78 78
 		}
79 79
 	}
80 80
 
81  
-	/**
82  
-	 * Throws UnsupportedOperationException since this cache is read-only
83  
-	 *
84  
-	 * @throws UnsupportedOperationException always
85  
-	 */
86 81
 	public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException {
87  
-		throw new UnsupportedOperationException( "Can't write to a readonly object" );
  82
+		return null;
88 83
 	}
89 84
 
90 85
 	/**
91 86
 	 * A no-op since this cache is read-only
92 87
 	 */
93 88
 	public void unlockItem(Object key, SoftLock lock) throws CacheException {
94  
-		//throw new UnsupportedOperationException("Can't write to a readonly object");
  89
+		evict( key );
95 90
 	}
96 91
 
97 92
 	/**
9  ...ain/java/org/hibernate/cache/ehcache/internal/strategy/ReadOnlyEhcacheNaturalIdRegionAccessStrategy.java
@@ -75,20 +75,15 @@ public boolean putFromLoad(Object key, Object value, long txTimestamp, Object ve
75 75
 		}
76 76
 	}
77 77
 
78  
-	/**
79  
-	 * Throws UnsupportedOperationException since this cache is read-only
80  
-	 *
81  
-	 * @throws UnsupportedOperationException always
82  
-	 */
83 78
 	public SoftLock lockItem(Object key, Object version) throws UnsupportedOperationException {
84  
-		throw new UnsupportedOperationException( "Can't write to a readonly object" );
  79
+		return null;
85 80
 	}
86 81
 
87 82
 	/**
88 83
 	 * A no-op since this cache is read-only
89 84
 	 */
90 85
 	public void unlockItem(Object key, SoftLock lock) throws CacheException {
91  
-		//throw new UnsupportedOperationException("Can't write to a readonly object");
  86
+		region.remove( key );
92 87
 	}
93 88
 
94 89
 	/**
17  hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/collection/ReadOnlyAccess.java
@@ -18,25 +18,8 @@
18 18
  * @since 3.5
19 19
  */
20 20
 class ReadOnlyAccess extends TransactionalAccess {
21  
-   private static final Log log = LogFactory.getLog(ReadOnlyAccess.class);
22  
-
23 21
    ReadOnlyAccess(CollectionRegionImpl region) {
24 22
       super(region);
25 23
    }
26  
-   public SoftLock lockItem(Object key, Object version) throws CacheException {
27  
-      throw new UnsupportedOperationException("Illegal attempt to edit read only item");
28  
-   }
29  
-
30  
-   public SoftLock lockRegion() throws CacheException {
31  
-      throw new UnsupportedOperationException("Illegal attempt to edit read only region");
32  
-   }
33  
-
34  
-   public void unlockItem(Object key, SoftLock lock) throws CacheException {
35  
-      log.error("Illegal attempt to edit read only item");
36  
-   }
37  
-
38  
-   public void unlockRegion(SoftLock lock) throws CacheException {
39  
-      log.error("Illegal attempt to edit read only item");
40  
-   }
41 24
 
42 25
 }
18  hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/entity/ReadOnlyAccess.java
@@ -21,22 +21,6 @@
21 21
       super(region);
22 22
    }
23 23
 
24  
-   public SoftLock lockItem(Object key, Object version) throws CacheException {
25  
-      throw new UnsupportedOperationException("Illegal attempt to edit read only item");
26  
-   }
27  
-
28  
-   public SoftLock lockRegion() throws CacheException {
29  
-      throw new UnsupportedOperationException("Illegal attempt to edit read only item");
30  
-   }
31  
-
32  
-   public void unlockItem(Object key, SoftLock lock) throws CacheException {
33  
-      log.error("Illegal attempt to edit read only item");
34  
-   }
35  
-
36  
-   public void unlockRegion(SoftLock lock) throws CacheException {
37  
-      log.error("Illegal attempt to edit read only item");
38  
-   }
39  
-
40 24
    @Override
41 25
    public boolean update(Object key, Object value, Object currentVersion, Object previousVersion) throws CacheException {
42 26
       throw new UnsupportedOperationException("Illegal attempt to edit read only item");
@@ -47,4 +31,4 @@ public boolean afterUpdate(Object key, Object value, Object currentVersion, Obje
47 31
             throws CacheException {
48 32
       throw new UnsupportedOperationException("Illegal attempt to edit read only item");
49 33
    }
50  
-}
  34
+}
19  hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/naturalid/ReadOnlyAccess.java
@@ -16,25 +16,6 @@
16 16
 		super( naturalIdRegion );
17 17
 	}
18 18
 
19  
-	@Override
20  
-	public SoftLock lockItem(Object key, Object version) throws CacheException {
21  
-		throw new UnsupportedOperationException( "Illegal attempt to edit read only item" );
22  
-	}
23  
-
24  
-	@Override
25  
-	public SoftLock lockRegion() throws CacheException {
26  
-		throw new UnsupportedOperationException( "Illegal attempt to edit read only item" );
27  
-	}
28  
-
29  
-	@Override
30  
-	public void unlockItem(Object key, SoftLock lock) throws CacheException {
31  
-		log.error( "Illegal attempt to edit read only item" );
32  
-	}
33  
-
34  
-	@Override
35  
-	public void unlockRegion(SoftLock lock) throws CacheException {
36  
-		log.error( "Illegal attempt to edit read only item" );
37  
-	}
38 19
 
39 20
 	@Override
40 21
 	public boolean update(Object key, Object value) throws CacheException {
7  hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/EntityRegionImplTestCase.java
@@ -52,11 +52,8 @@ protected void supportedAccessTypeTest(RegionFactory regionFactory, Properties p
52 52
       EntityRegion region = regionFactory.buildEntityRegion("test", properties, null);
53 53
       assertNull("Got TRANSACTIONAL", region.buildAccessStrategy(AccessType.TRANSACTIONAL)
54 54
                .lockRegion());
55  
-      try {
56  
-         region.buildAccessStrategy(AccessType.READ_ONLY).lockRegion();
57  
-         fail("Did not get READ_ONLY");
58  
-      } catch (UnsupportedOperationException good) {
59  
-      }
  55
+
  56
+      assertNull("Got READ_ONLY", region.buildAccessStrategy(AccessType.READ_ONLY).lockRegion());
60 57
 
61 58
       try {
62 59
          region.buildAccessStrategy(AccessType.NONSTRICT_READ_WRITE);
20  hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/entity/ReadOnlyExtraAPITestCase.java
@@ -41,26 +41,6 @@ protected AccessType getAccessType() {
41 41
 	}
42 42
 
43 43
 	@Override
44  
-	public void testLockItem() {
45  
-		try {
46  
-			getEntityAccessStrategy().lockItem( KEY, Integer.valueOf( 1 ) );
47  
-			fail( "Call to lockItem did not throw exception" );
48  
-		}
49  
-		catch (UnsupportedOperationException expected) {
50  
-		}
51  
-	}
52  
-
53  
-	@Override
54  
-	public void testLockRegion() {
55  
-		try {
56  
-			getEntityAccessStrategy().lockRegion();
57  
-			fail( "Call to lockRegion did not throw exception" );
58  
-		}
59  
-		catch (UnsupportedOperationException expected) {
60  
-		}
61  
-	}
62  
-
63  
-	@Override
64 44
 	public void testAfterUpdate() {
65 45
 		try {
66 46
 			getEntityAccessStrategy().afterUpdate(
8  hibernate-testing/src/main/java/org/hibernate/testing/cache/BaseCollectionRegionAccessStrategy.java
@@ -31,7 +31,9 @@
31 31
  */
32 32
 class BaseCollectionRegionAccessStrategy extends BaseRegionAccessStrategy implements CollectionRegionAccessStrategy {
33 33
 	private final CollectionRegionImpl region;
34  
-
  34
+	BaseCollectionRegionAccessStrategy(CollectionRegionImpl region) {
  35
+		this.region = region;
  36
+	}
35 37
 	@Override
36 38
 	protected BaseGeneralDataRegion getInternalRegion() {
37 39
 		return region;
@@ -46,8 +48,4 @@ protected boolean isDefaultMinimalPutOverride() {
46 48
 	public CollectionRegion getRegion() {
47 49
 		return region;
48 50
 	}
49  
-
50  
-	BaseCollectionRegionAccessStrategy(CollectionRegionImpl region) {
51  
-		this.region = region;
52  
-	}
53 51
 }
18  hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyCollectionRegionAccessStrategy.java
@@ -33,25 +33,7 @@
33 33
  * @author Strong Liu
34 34
  */
35 35
 class ReadOnlyCollectionRegionAccessStrategy extends BaseCollectionRegionAccessStrategy {
36  
-	private static final CoreMessageLogger LOG = Logger.getMessageLogger(
37  
-			CoreMessageLogger.class, ReadOnlyCollectionRegionAccessStrategy.class.getName()
38  
-	);
39  
-
40 36
 	ReadOnlyCollectionRegionAccessStrategy(CollectionRegionImpl region) {
41 37
 		super( region );
42 38
 	}
43  
-
44  
-	@Override
45  
-	public void unlockItem(Object key, SoftLock lock) throws CacheException {
46  
-		LOG.invalidEditOfReadOnlyItem( key );
47  
-	}
48  
-
49  
-	@Override
50  
-	public SoftLock lockItem(Object key, Object version) throws CacheException {
51  
-		LOG.invalidEditOfReadOnlyItem( key );
52  
-		throw new UnsupportedOperationException( "Can't write to a readonly object" );
53  
-	}
54  
-
55  
-
56  
-
57 39
 }
11  hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyEntityRegionAccessStrategy.java
@@ -54,18 +54,9 @@ public boolean afterInsert(Object key, Object value, Object version) throws Cach
54 54
 		return true;
55 55
 	}
56 56
 
57  
-	/**
58  
-	 * This cache is asynchronous hence a no-op
59  
-	 */
60 57
 	@Override
61 58
 	public void unlockItem(Object key, SoftLock lock) throws CacheException {
62  
-		LOG.invalidEditOfReadOnlyItem( key );
63  
-	}
64  
-
65  
-	@Override
66  
-	public SoftLock lockItem(Object key, Object version) throws CacheException {
67  
-		LOG.invalidEditOfReadOnlyItem( key );
68  
-		throw new UnsupportedOperationException( "Can't write to a readonly object" );
  59
+		evict( key );
69 60
 	}
70 61
 
71 62
 	/**
11  hibernate-testing/src/main/java/org/hibernate/testing/cache/ReadOnlyNaturalIdRegionAccessStrategy.java
@@ -43,15 +43,6 @@
43 43
 
44 44
 	@Override
45 45
 	public void unlockItem(Object key, SoftLock lock) throws CacheException {
46  
-		LOG.invalidEditOfReadOnlyItem( key );
  46
+		evict( key );
47 47
 	}
48  
-
49  
-	@Override
50  
-	public SoftLock lockItem(Object key, Object version) throws CacheException {
51  
-		LOG.invalidEditOfReadOnlyItem( key );
52  
-		throw new UnsupportedOperationException( "Can't write to a readonly object" );
53  
-	}
54  
-
55  
-
56  
-
57 48
 }
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.