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@17186 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
1f98fc9ed6
commit
577024e7aa
|
@ -184,9 +184,8 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
|
||||||
private final transient SQLFunctionRegistry sqlFunctionRegistry;
|
private final transient SQLFunctionRegistry sqlFunctionRegistry;
|
||||||
private final transient SessionFactoryObserver observer;
|
private final transient SessionFactoryObserver observer;
|
||||||
private final transient HashMap entityNameResolvers = new HashMap();
|
private final transient HashMap entityNameResolvers = new HashMap();
|
||||||
|
private final transient QueryPlanCache queryPlanCache = new QueryPlanCache( this );
|
||||||
private final QueryPlanCache queryPlanCache = new QueryPlanCache( this );
|
private final transient Cache cacheAccess = new CacheImpl();
|
||||||
|
|
||||||
private transient boolean isClosed = false;
|
private transient boolean isClosed = false;
|
||||||
|
|
||||||
public SessionFactoryImpl(
|
public SessionFactoryImpl(
|
||||||
|
@ -195,9 +194,7 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
|
||||||
Settings settings,
|
Settings settings,
|
||||||
EventListeners listeners,
|
EventListeners listeners,
|
||||||
SessionFactoryObserver observer) throws HibernateException {
|
SessionFactoryObserver observer) throws HibernateException {
|
||||||
|
|
||||||
log.info("building session factory");
|
log.info("building session factory");
|
||||||
|
|
||||||
this.properties = new Properties();
|
this.properties = new Properties();
|
||||||
this.properties.putAll( cfg.getProperties() );
|
this.properties.putAll( cfg.getProperties() );
|
||||||
this.interceptor = cfg.getInterceptor();
|
this.interceptor = cfg.getInterceptor();
|
||||||
|
@ -956,16 +953,15 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
|
||||||
eventListeners.destroyListeners();
|
eventListeners.destroyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Cache cacheAccess = new CacheImpl();
|
private class CacheImpl implements Cache {
|
||||||
|
|
||||||
private class CacheImpl implements Cache, Serializable {
|
|
||||||
public boolean containsEntity(Class entityClass, Serializable identifier) {
|
public boolean containsEntity(Class entityClass, Serializable identifier) {
|
||||||
return containsEntity( entityClass.getName(), identifier );
|
return containsEntity( entityClass.getName(), identifier );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsEntity(String entityName, Serializable identifier) {
|
public boolean containsEntity(String entityName, Serializable identifier) {
|
||||||
// todo : need a contains() method on the underlying regions
|
EntityPersister p = getEntityPersister( entityName );
|
||||||
throw new UnsupportedOperationException( "not yet implemented - HHH-4021" );
|
return p.hasCache() &&
|
||||||
|
p.getCacheAccessStrategy().getRegion().contains( buildCacheKey( identifier, p ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void evictEntity(Class entityClass, Serializable identifier) {
|
public void evictEntity(Class entityClass, Serializable identifier) {
|
||||||
|
@ -981,17 +977,20 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
|
||||||
MessageHelper.infoString( p, identifier, SessionFactoryImpl.this )
|
MessageHelper.infoString( p, identifier, SessionFactoryImpl.this )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
CacheKey cacheKey = new CacheKey(
|
p.getCacheAccessStrategy().evict( buildCacheKey( identifier, p ) );
|
||||||
identifier,
|
|
||||||
p.getIdentifierType(),
|
|
||||||
p.getRootEntityName(),
|
|
||||||
EntityMode.POJO,
|
|
||||||
SessionFactoryImpl.this
|
|
||||||
);
|
|
||||||
p.getCacheAccessStrategy().evict( cacheKey );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CacheKey buildCacheKey(Serializable identifier, EntityPersister p) {
|
||||||
|
return new CacheKey(
|
||||||
|
identifier,
|
||||||
|
p.getIdentifierType(),
|
||||||
|
p.getRootEntityName(),
|
||||||
|
EntityMode.POJO,
|
||||||
|
SessionFactoryImpl.this
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public void evictEntityRegion(Class entityClass) {
|
public void evictEntityRegion(Class entityClass) {
|
||||||
evictEntityRegion( entityClass.getName() );
|
evictEntityRegion( entityClass.getName() );
|
||||||
}
|
}
|
||||||
|
@ -1014,8 +1013,9 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsCollection(String role, Serializable ownerIdentifier) {
|
public boolean containsCollection(String role, Serializable ownerIdentifier) {
|
||||||
// todo : need a contains() method on the underlying regions
|
CollectionPersister p = getCollectionPersister( role );
|
||||||
return false;
|
return p.hasCache() &&
|
||||||
|
p.getCacheAccessStrategy().getRegion().contains( buildCacheKey( ownerIdentifier, p ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void evictCollection(String role, Serializable ownerIdentifier) {
|
public void evictCollection(String role, Serializable ownerIdentifier) {
|
||||||
|
@ -1027,17 +1027,21 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
|
||||||
MessageHelper.collectionInfoString(p, ownerIdentifier, SessionFactoryImpl.this)
|
MessageHelper.collectionInfoString(p, ownerIdentifier, SessionFactoryImpl.this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
CacheKey cacheKey = new CacheKey(
|
CacheKey cacheKey = buildCacheKey( ownerIdentifier, p );
|
||||||
ownerIdentifier,
|
|
||||||
p.getKeyType(),
|
|
||||||
p.getRole(),
|
|
||||||
EntityMode.POJO,
|
|
||||||
SessionFactoryImpl.this
|
|
||||||
);
|
|
||||||
p.getCacheAccessStrategy().evict( cacheKey );
|
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) {
|
public void evictCollectionRegion(String role) {
|
||||||
CollectionPersister p = getCollectionPersister( role );
|
CollectionPersister p = getCollectionPersister( role );
|
||||||
if ( p.hasCache() ) {
|
if ( p.hasCache() ) {
|
||||||
|
@ -1056,8 +1060,7 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsQuery(String regionName) {
|
public boolean containsQuery(String regionName) {
|
||||||
// todo : need a contains() method on the underlying regions
|
return queryCaches.get( regionName ) != null;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void evictDefaultQueryRegion() {
|
public void evictDefaultQueryRegion() {
|
||||||
|
|
Loading…
Reference in New Issue