Package org.hibernate.cache.spi.support
Class AbstractCachedDomainDataAccess
- java.lang.Object
-
- org.hibernate.cache.spi.support.AbstractCachedDomainDataAccess
-
- All Implemented Interfaces:
CachedDomainDataAccess
,AbstractDomainDataRegion.Destructible
- Direct Known Subclasses:
AbstractCollectionDataAccess
,AbstractEntityDataAccess
,AbstractNaturalIdDataAccess
,AbstractReadWriteAccess
public abstract class AbstractCachedDomainDataAccess extends Object implements CachedDomainDataAccess, AbstractDomainDataRegion.Destructible
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractCachedDomainDataAccess(DomainDataRegion region, DomainDataStorageAccess storageAccess)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
clearCache()
boolean
contains(Object key)
Determine whether this region contains data for the given key.void
destroy()
void
evict(Object key)
Forcibly evict an item from the cache immediately without regard for transaction isolation and/or locking.void
evictAll()
Forcibly evict all items from the cache immediately without regard for transaction isolation.Object
get(SharedSessionContractImplementor session, Object key)
Attempt to retrieve an object from the cache.DomainDataRegion
getRegion()
The region containing the data being accessedprotected DomainDataStorageAccess
getStorageAccess()
SoftLock
lockRegion()
Lock the entire regionboolean
putFromLoad(SharedSessionContractImplementor session, Object key, Object value, Object version)
Attempt to cache an object, afterQuery loading from the database.boolean
putFromLoad(SharedSessionContractImplementor session, Object key, Object value, Object version, boolean minimalPutOverride)
Attempt to cache an object, afterQuery loading from the database, explicitly specifying the minimalPut behavior.void
remove(SharedSessionContractImplementor session, Object key)
Called afterQuery an item has become stale (beforeQuery the transaction completes).void
removeAll(SharedSessionContractImplementor session)
Remove all data for this accessed typevoid
unlockRegion(SoftLock lock)
Called after we have finished the attempted invalidation of the entire region-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.hibernate.cache.spi.access.CachedDomainDataAccess
getAccessType, lockItem, unlockItem
-
-
-
-
Constructor Detail
-
AbstractCachedDomainDataAccess
protected AbstractCachedDomainDataAccess(DomainDataRegion region, DomainDataStorageAccess storageAccess)
-
-
Method Detail
-
getRegion
public DomainDataRegion getRegion()
Description copied from interface:CachedDomainDataAccess
The region containing the data being accessed- Specified by:
getRegion
in interfaceCachedDomainDataAccess
-
getStorageAccess
protected DomainDataStorageAccess getStorageAccess()
-
clearCache
protected void clearCache()
-
contains
public boolean contains(Object key)
Description copied from interface:CachedDomainDataAccess
Determine whether this region contains data for the given key.The semantic here is whether the cache contains data visible for the current call context. This should be viewed as a "best effort", meaning blocking should be avoided if possible.
- Specified by:
contains
in interfaceCachedDomainDataAccess
- Parameters:
key
- The cache key- Returns:
- True if the underlying cache contains corresponding data; false otherwise.
-
get
public Object get(SharedSessionContractImplementor session, Object key)
Description copied from interface:CachedDomainDataAccess
Attempt to retrieve an object from the cache. Mainly used in attempting to resolve entities/collections from the second level cache.- Specified by:
get
in interfaceCachedDomainDataAccess
- Parameters:
session
- Current session.key
- The key of the item to be retrieved.- Returns:
- the cached data or
null
-
putFromLoad
public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, Object version)
Description copied from interface:CachedDomainDataAccess
Attempt to cache an object, afterQuery loading from the database.- Specified by:
putFromLoad
in interfaceCachedDomainDataAccess
- Parameters:
session
- Current session.key
- The item keyvalue
- The itemversion
- the item version number- Returns:
true
if the object was successfully cached
-
putFromLoad
public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, Object version, boolean minimalPutOverride)
Description copied from interface:CachedDomainDataAccess
Attempt to cache an object, afterQuery loading from the database, explicitly specifying the minimalPut behavior.- Specified by:
putFromLoad
in interfaceCachedDomainDataAccess
- Parameters:
session
- Current session.key
- The item keyvalue
- The itemversion
- the item version numberminimalPutOverride
- Explicit minimalPut flag- Returns:
true
if the object was successfully cached
-
lockRegion
public SoftLock lockRegion()
Description copied from interface:CachedDomainDataAccess
Lock the entire region- Specified by:
lockRegion
in interfaceCachedDomainDataAccess
- Returns:
- A representation of our lock on the item; or
null
.
-
unlockRegion
public void unlockRegion(SoftLock lock)
Description copied from interface:CachedDomainDataAccess
Called after we have finished the attempted invalidation of the entire region- Specified by:
unlockRegion
in interfaceCachedDomainDataAccess
- Parameters:
lock
- The lock previously obtained fromCachedDomainDataAccess.lockRegion()
-
remove
public void remove(SharedSessionContractImplementor session, Object key)
Description copied from interface:CachedDomainDataAccess
Called afterQuery an item has become stale (beforeQuery the transaction completes). This method is used by "synchronous" concurrency strategies.- Specified by:
remove
in interfaceCachedDomainDataAccess
- Parameters:
session
- Current session.key
- The key of the item to remove
-
removeAll
public void removeAll(SharedSessionContractImplementor session)
Description copied from interface:CachedDomainDataAccess
Remove all data for this accessed type- Specified by:
removeAll
in interfaceCachedDomainDataAccess
-
evict
public void evict(Object key)
Description copied from interface:CachedDomainDataAccess
Forcibly evict an item from the cache immediately without regard for transaction isolation and/or locking. This behavior is exactly Hibernate legacy behavior, but it is also required by JPA - so we cannot remove it.Used from JPA's
Cache.evict(Class, Object)
, as well as the Hibernate extensionCache.evictEntityData(Class, Object)
andCache.evictEntityData(String, Object)
- Specified by:
evict
in interfaceCachedDomainDataAccess
- Parameters:
key
- The key of the item to remove
-
evictAll
public void evictAll()
Description copied from interface:CachedDomainDataAccess
Forcibly evict all items from the cache immediately without regard for transaction isolation. This behavior is exactly Hibernate legacy behavior, but it is also required by JPA - so we cannot remove it.Used from our JPA impl of
Cache.evictAll()
as well as the Hibernate extensionsCache.evictEntityData(Class)
,Cache.evictEntityData(String)
andCache.evictEntityData()
- Specified by:
evictAll
in interfaceCachedDomainDataAccess
-
destroy
public void destroy()
- Specified by:
destroy
in interfaceAbstractDomainDataRegion.Destructible
-
-