Package org.hibernate.cache.spi.support
Class AbstractReadWriteAccess
- java.lang.Object
-
- org.hibernate.cache.spi.support.AbstractCachedDomainDataAccess
-
- org.hibernate.cache.spi.support.AbstractReadWriteAccess
-
- All Implemented Interfaces:
CachedDomainDataAccess
,AbstractDomainDataRegion.Destructible
- Direct Known Subclasses:
CollectionReadWriteAccess
,EntityReadWriteAccess
,NaturalIdReadWriteAccess
public abstract class AbstractReadWriteAccess extends AbstractCachedDomainDataAccess
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractReadWriteAccess.Item
Wrapper type representing unlocked items.static interface
AbstractReadWriteAccess.Lockable
Interface type implemented by all wrapper objects in the cache.static class
AbstractReadWriteAccess.SoftLockImpl
Wrapper type representing locked items.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractReadWriteAccess(DomainDataRegion domainDataRegion, DomainDataStorageAccess storageAccess)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
decrementLock(SharedSessionContractImplementor session, Object key, AbstractReadWriteAccess.SoftLockImpl lock)
Object
get(SharedSessionContractImplementor session, Object key)
Returnsnull
if the item is not readable.protected abstract AccessedDataClassification
getAccessedDataClassification()
protected abstract Comparator
getVersionComparator()
protected void
handleLockExpiry(SharedSessionContractImplementor session, Object key, AbstractReadWriteAccess.Lockable lock)
SoftLock
lockItem(SharedSessionContractImplementor session, Object key, Object version)
We are going to attempt to update/delete the keyed object.protected long
nextLockId()
boolean
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.protected Lock
readLock()
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
unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock)
Called when we have finished the attempted update/delete (which may or may not have been successful), after transaction completion.protected UUID
uuid()
protected Lock
writeLock()
-
Methods inherited from class org.hibernate.cache.spi.support.AbstractCachedDomainDataAccess
clearCache, contains, destroy, evict, evictAll, getRegion, getStorageAccess, lockRegion, unlockRegion
-
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
-
-
-
-
Constructor Detail
-
AbstractReadWriteAccess
protected AbstractReadWriteAccess(DomainDataRegion domainDataRegion, DomainDataStorageAccess storageAccess)
-
-
Method Detail
-
getVersionComparator
protected abstract Comparator getVersionComparator()
-
uuid
protected UUID uuid()
-
nextLockId
protected long nextLockId()
-
readLock
protected Lock readLock()
-
writeLock
protected Lock writeLock()
-
get
public Object get(SharedSessionContractImplementor session, Object key)
Returnsnull
if the item is not readable. Locked items are not readable, nor are items created afterQuery the start of this transaction.- Specified by:
get
in interfaceCachedDomainDataAccess
- Overrides:
get
in classAbstractCachedDomainDataAccess
- 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
- Overrides:
putFromLoad
in classAbstractCachedDomainDataAccess
- Parameters:
session
- Current session.key
- The item keyvalue
- The itemversion
- the item version number- Returns:
true
if the object was successfully cached
-
getAccessedDataClassification
protected abstract AccessedDataClassification getAccessedDataClassification()
-
putFromLoad
public final 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
- Overrides:
putFromLoad
in classAbstractCachedDomainDataAccess
- 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
-
lockItem
public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version)
Description copied from interface:CachedDomainDataAccess
We are going to attempt to update/delete the keyed object. This method is used by "asynchronous" concurrency strategies.The returned object must be passed back to
CachedDomainDataAccess.unlockItem(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object, org.hibernate.cache.spi.access.SoftLock)
, to release the lock. Concurrency strategies which do not support client-visible locks may silently return null.- Parameters:
session
- Current session.key
- The key of the item to lockversion
- The item's current version value- Returns:
- A representation of our lock on the item; or
null
.
-
unlockItem
public void unlockItem(SharedSessionContractImplementor session, Object key, SoftLock lock)
Description copied from interface:CachedDomainDataAccess
Called when we have finished the attempted update/delete (which may or may not have been successful), after transaction completion. This method is used by "asynchronous" concurrency strategies.- Parameters:
session
- Current session.key
- The item keylock
- The lock previously obtained fromCachedDomainDataAccess.lockItem(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object, java.lang.Object)
-
decrementLock
protected void decrementLock(SharedSessionContractImplementor session, Object key, AbstractReadWriteAccess.SoftLockImpl lock)
-
handleLockExpiry
protected void handleLockExpiry(SharedSessionContractImplementor session, Object key, AbstractReadWriteAccess.Lockable lock)
-
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
- Overrides:
remove
in classAbstractCachedDomainDataAccess
- 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
- Overrides:
removeAll
in classAbstractCachedDomainDataAccess
-
-