[hibernate-commits] Hibernate SVN: r17186 - core/trunk/core/src/main/java/org/hibernate/impl.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Jul 21 11:57:58 EDT 2009


Author: steve.ebersole at jboss.com
Date: 2009-07-21 11:57:57 -0400 (Tue, 21 Jul 2009)
New Revision: 17186

Modified:
   core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java
Log:
HHH-4022 : Add an actual API contract for querying/managing cache regions (from app code)

Modified: core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java	2009-07-21 14:54:45 UTC (rev 17185)
+++ core/trunk/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java	2009-07-21 15:57:57 UTC (rev 17186)
@@ -184,9 +184,8 @@
 	private final transient SQLFunctionRegistry sqlFunctionRegistry;
 	private final transient SessionFactoryObserver observer;
 	private final transient HashMap entityNameResolvers = new HashMap();
-
-	private final QueryPlanCache queryPlanCache = new QueryPlanCache( this );
-
+	private final transient QueryPlanCache queryPlanCache = new QueryPlanCache( this );
+	private final transient Cache cacheAccess = new CacheImpl();
 	private transient boolean isClosed = false;
 
 	public SessionFactoryImpl(
@@ -195,9 +194,7 @@
 	        Settings settings,
 	        EventListeners listeners,
 			SessionFactoryObserver observer) throws HibernateException {
-
 		log.info("building session factory");
-
 		this.properties = new Properties();
 		this.properties.putAll( cfg.getProperties() );
 		this.interceptor = cfg.getInterceptor();
@@ -956,16 +953,15 @@
 		eventListeners.destroyListeners();
 	}
 
-	private final Cache cacheAccess = new CacheImpl();
-
-	private class CacheImpl implements Cache, Serializable {
+	private class CacheImpl implements Cache {
 		public boolean containsEntity(Class entityClass, Serializable identifier) {
 			return containsEntity( entityClass.getName(), identifier );
 		}
 
 		public boolean containsEntity(String entityName, Serializable identifier) {
-			// todo : need a contains() method on the underlying regions
-			throw new UnsupportedOperationException( "not yet implemented - HHH-4021" );
+			EntityPersister p = getEntityPersister( entityName );
+			return p.hasCache() &&
+					p.getCacheAccessStrategy().getRegion().contains( buildCacheKey( identifier, p ) );
 		}
 
 		public void evictEntity(Class entityClass, Serializable identifier) {
@@ -981,17 +977,20 @@
 									MessageHelper.infoString( p, identifier, SessionFactoryImpl.this )
 					);
 				}
-				CacheKey cacheKey = new CacheKey(
-						identifier,
-						p.getIdentifierType(),
-						p.getRootEntityName(),
-						EntityMode.POJO,
-						SessionFactoryImpl.this
-				);
-				p.getCacheAccessStrategy().evict( cacheKey );
+				p.getCacheAccessStrategy().evict( buildCacheKey( identifier, p ) );
 			}
 		}
 
+		private CacheKey buildCacheKey(Serializable identifier, EntityPersister p) {
+			return new CacheKey(
+					identifier,
+					p.getIdentifierType(),
+					p.getRootEntityName(),
+					EntityMode.POJO,
+					SessionFactoryImpl.this
+			);
+		}
+
 		public void evictEntityRegion(Class entityClass) {
 			evictEntityRegion( entityClass.getName() );
 		}
@@ -1014,8 +1013,9 @@
 		}
 
 		public boolean containsCollection(String role, Serializable ownerIdentifier) {
-			// todo : need a contains() method on the underlying regions
-			return false;
+			CollectionPersister p = getCollectionPersister( role );
+			return p.hasCache() &&
+					p.getCacheAccessStrategy().getRegion().contains( buildCacheKey( ownerIdentifier, p ) );
 		}
 
 		public void evictCollection(String role, Serializable ownerIdentifier) {
@@ -1027,17 +1027,21 @@
 									MessageHelper.collectionInfoString(p, ownerIdentifier, SessionFactoryImpl.this)
 					);
 				}
-				CacheKey cacheKey = new CacheKey(
-						ownerIdentifier,
-						p.getKeyType(),
-						p.getRole(),
-						EntityMode.POJO,
-						SessionFactoryImpl.this
-				);
+				CacheKey cacheKey = buildCacheKey( ownerIdentifier, p );
 				p.getCacheAccessStrategy().evict( cacheKey );
 			}
 		}
 
+		private CacheKey buildCacheKey(Serializable ownerIdentifier, CollectionPersister p) {
+			return new CacheKey(
+					ownerIdentifier,
+					p.getKeyType(),
+					p.getRole(),
+					EntityMode.POJO,
+					SessionFactoryImpl.this
+			);
+		}
+
 		public void evictCollectionRegion(String role) {
 			CollectionPersister p = getCollectionPersister( role );
 			if ( p.hasCache() ) {
@@ -1056,8 +1060,7 @@
 		}
 
 		public boolean containsQuery(String regionName) {
-			// todo : need a contains() method on the underlying regions
-			return false;
+			return queryCaches.get( regionName ) != null;
 		}
 
 		public void evictDefaultQueryRegion() {



More information about the hibernate-commits mailing list