Skip to content

Commit b339e33

Browse files
committed
HHH-4022 - Add an actual API contract for querying/managing cache regions (from app code)
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17027 1b8cb986-b30d-0410-93ca-fae66ebed9b2
1 parent cd23a6c commit b339e33

File tree

10 files changed

+608
-173
lines changed

10 files changed

+608
-173
lines changed

annotations/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<dependency>
6363
<groupId>org.hibernate.java-persistence</groupId>
6464
<artifactId>jpa-api</artifactId>
65-
<version>2.0.Beta1</version>
65+
<version>2.0.pfd-SNAPSHOT</version>
6666
</dependency>
6767
<dependency>
6868
<groupId>javassist</groupId>

cache-jbosscache/src/main/java/org/hibernate/cache/jbc/BasicRegionAdapter.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,25 @@ protected void deactivateLocalNode() {
342342
}
343343
}
344344

345+
public boolean contains(Object key) {
346+
if ( !checkValid() ) {
347+
return false;
348+
}
349+
350+
try {
351+
Option opt = new Option();
352+
opt.setLockAcquisitionTimeout(100);
353+
CacheHelper.setInvocationOption( jbcCache, opt );
354+
return CacheHelper.getAllowingTimeout( jbcCache, regionFqn, key ) != null;
355+
}
356+
catch ( CacheException ce ) {
357+
throw ce;
358+
}
359+
catch ( Throwable t ) {
360+
throw new CacheException( t );
361+
}
362+
}
363+
345364
public long getSizeInMemory() {
346365
// not supported
347366
return -1;
@@ -356,7 +375,11 @@ public long getElementCountInMemory() {
356375
size--;
357376
}
358377
return size;
359-
} catch (Exception e) {
378+
}
379+
catch ( CacheException ce ) {
380+
throw ce;
381+
}
382+
catch (Exception e) {
360383
throw new CacheException(e);
361384
}
362385
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
3+
* indicated by the @author tags or express copyright attribution
4+
* statements applied by the authors. All third-party contributions are
5+
* distributed under license by Red Hat Middleware LLC.
6+
*
7+
* This copyrighted material is made available to anyone wishing to use, modify,
8+
* copy, or redistribute it subject to the terms and conditions of the GNU
9+
* Lesser General Public License, as published by the Free Software Foundation.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14+
* for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with this distribution; if not, write to:
18+
* Free Software Foundation, Inc.
19+
* 51 Franklin Street, Fifth Floor
20+
* Boston, MA 02110-1301 USA
21+
*/
22+
package org.hibernate;
23+
24+
import java.io.Serializable;
25+
26+
/**
27+
* Provides an API for querying/managing the second level cache regions.
28+
* <p/>
29+
* CAUTION: None of these methods respect any isolation or transactional
30+
* semantics associated with the underlying caches. Specifically, evictions
31+
* perform an immediate "hard" removal outside any transactions and/or locking
32+
* scheme(s).
33+
*
34+
* @author Steve Ebersole
35+
*/
36+
public interface Cache {
37+
/**
38+
* Determine whether the cache contains data for the given entity "instance".
39+
* <p/>
40+
* The semantic here is whether the cache contains data visible for the
41+
* current call context.
42+
*
43+
* @param entityClass The entity class.
44+
* @param identifier The entity identifier
45+
*
46+
* @return True if the underlying cache contains corresponding data; false
47+
* otherwise.
48+
*/
49+
public boolean containsEntity(Class entityClass, Serializable identifier);
50+
51+
/**
52+
* Determine whether the cache contains data for the given entity "instance".
53+
* <p/>
54+
* The semantic here is whether the cache contains data visible for the
55+
* current call context.
56+
*
57+
* @param entityName The entity name.
58+
* @param identifier The entity identifier
59+
*
60+
* @return True if the underlying cache contains corresponding data; false otherwise.
61+
*/
62+
public boolean containsEntity(String entityName, Serializable identifier);
63+
64+
/**
65+
* Evicts the entity data for a particular entity "instance".
66+
*
67+
* @param entityClass The entity class.
68+
* @param identifier The entity identifier
69+
*/
70+
public void evictEntity(Class entityClass, Serializable identifier);
71+
72+
/**
73+
* Evicts the entity data for a particular entity "instance".
74+
*
75+
* @param entityName The entity name.
76+
* @param identifier The entity identifier
77+
*/
78+
public void evictEntity(String entityName, Serializable identifier);
79+
80+
/**
81+
* Evicts all entity data from the given region (i.e. for all entities of
82+
* type).
83+
*
84+
* @param entityClass The entity class.
85+
*/
86+
public void evictEntityRegion(Class entityClass);
87+
88+
/**
89+
* Evicts all entity data from the given region (i.e. for all entities of
90+
* type).
91+
*
92+
* @param entityName The entity name.
93+
*/
94+
public void evictEntityRegion(String entityName);
95+
96+
/**
97+
* Evict data from all entity regions.
98+
*/
99+
public void evictEntityRegions();
100+
101+
/**
102+
* Determine whether the cache contains data for the given collection.
103+
* <p/>
104+
* The semantic here is whether the cache contains data visible for the
105+
* current call context.
106+
*
107+
* @param role The name of the collection role (in form
108+
* [owner-entity-name].[collection-property-name]) whose regions should be
109+
* evicted.
110+
* @param ownerIdentifier The identifier of the owning entity
111+
*
112+
* @return True if the underlying cache contains corresponding data; false otherwise.
113+
*/
114+
public boolean containsCollection(String role, Serializable ownerIdentifier);
115+
116+
/**
117+
* Evicts the cache data for the given identified collection instance.
118+
*
119+
* @param role The "collection role" (in form [owner-entity-name].[collection-property-name]).
120+
* @param ownerIdentifier The identifier of the owning entity
121+
*/
122+
public void evictCollection(String role, Serializable ownerIdentifier);
123+
124+
/**
125+
* Evicts all entity data from the given region (i.e. evicts cached data
126+
* for all of the specified c9ollection role).
127+
*
128+
* @param role The "collection role" (in form [owner-entity-name].[collection-property-name]).
129+
*/
130+
public void evictCollectionRegion(String role);
131+
132+
/**
133+
* Evict data from all collection regions.
134+
*/
135+
public void evictCollectionRegions();
136+
137+
/**
138+
* Determine whether the cache contains data for the given query.
139+
* <p/>
140+
* The semantic here is whether the cache contains any data for the given
141+
* region name since query result caches are not transactionally isolated.
142+
*
143+
* @param regionName The cache name given to the query.
144+
*
145+
* @return True if the underlying cache contains corresponding data; false otherwise.
146+
*/
147+
public boolean containsQuery(String regionName);
148+
149+
/**
150+
* Evicts all cached query results from the default region.
151+
*/
152+
public void evictDefaultQueryRegion();
153+
154+
/**
155+
* Evicts all cached query results under the given name.
156+
*
157+
* @param regionName The cache name associated to the queries being cached.
158+
*/
159+
public void evictQueryRegion(String regionName);
160+
161+
/**
162+
* Evict data from all query regions.
163+
*/
164+
public void evictQueryRegions();
165+
}

0 commit comments

Comments
 (0)