Package org.hibernate.cache.spi.access
Interface NaturalIdDataAccess
-
- All Superinterfaces:
CachedDomainDataAccess
- All Known Implementing Classes:
AbstractNaturalIdDataAccess
,NaturalIdNonStrictReadWriteAccess
,NaturalIdReadOnlyAccess
,NaturalIdReadWriteAccess
,NaturalIdTransactionalAccess
public interface NaturalIdDataAccess extends CachedDomainDataAccess
Contract for managing transactional and concurrent access to cached naturalId data. The expected call sequences related to various operations are:- INSERTS :
insert(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object, java.lang.Object)
thenafterInsert(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object, java.lang.Object)
- UPDATES :
CachedDomainDataAccess.lockItem(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object, java.lang.Object)
thenCachedDomainDataAccess.remove(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object)
thenupdate(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object, java.lang.Object)
thenafterUpdate(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object, java.lang.Object, org.hibernate.cache.spi.access.SoftLock)
- DELETES :
CachedDomainDataAccess.lockItem(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object, java.lang.Object)
thenCachedDomainDataAccess.remove(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object)
thenCachedDomainDataAccess.unlockItem(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object, org.hibernate.cache.spi.access.SoftLock)
- LOADS :
CachedDomainDataAccess.putFromLoad(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object, java.lang.Object, java.lang.Object)
Note the special case of UPDATES above. Because the cache key itself has changed here we need to remove the old entry as well
There is another usage pattern that is used to invalidate entries after a query performing "bulk" HQL/SQL operations:
CachedDomainDataAccess.lockRegion()
thenCachedDomainDataAccess.removeAll(org.hibernate.engine.spi.SharedSessionContractImplementor)
thenCachedDomainDataAccess.unlockRegion(org.hibernate.cache.spi.access.SoftLock)
IMPORTANT : NaturalIds are not versioned so
null
will always be passed to the version parameter to:
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
afterInsert(SharedSessionContractImplementor session, Object key, Object value)
Called afterQuery an item has been inserted (afterQuery the transaction completes), instead of calling release().boolean
afterUpdate(SharedSessionContractImplementor session, Object key, Object value, SoftLock lock)
Called afterQuery an item has been updated (afterQuery the transaction completes), instead of calling release().Object
generateCacheKey(Object naturalIdValues, EntityPersister rootEntityDescriptor, SharedSessionContractImplementor session)
To create instances of NaturalIdCacheKey for this region, Hibernate will invoke this method exclusively so that generated implementations can generate optimised keys.Object
getNaturalIdValues(Object cacheKey)
Performs reverse operation togenerateCacheKey(java.lang.Object, org.hibernate.persister.entity.EntityPersister, org.hibernate.engine.spi.SharedSessionContractImplementor)
, returning the original naturalIdValues.boolean
insert(SharedSessionContractImplementor session, Object key, Object value)
Called afterQuery an item has been inserted (beforeQuery the transaction completes), instead of calling evict().boolean
update(SharedSessionContractImplementor session, Object key, Object value)
Called afterQuery an item has been updated (beforeQuery the transaction completes), instead of calling evict().-
Methods inherited from interface org.hibernate.cache.spi.access.CachedDomainDataAccess
contains, evict, evictAll, get, getAccessType, getRegion, lockItem, lockRegion, putFromLoad, putFromLoad, remove, removeAll, unlockItem, unlockRegion
-
-
-
-
Method Detail
-
generateCacheKey
Object generateCacheKey(Object naturalIdValues, EntityPersister rootEntityDescriptor, SharedSessionContractImplementor session)
To create instances of NaturalIdCacheKey for this region, Hibernate will invoke this method exclusively so that generated implementations can generate optimised keys.- Parameters:
naturalIdValues
- the sequence of values which unequivocally identifies a cached element on this regionrootEntityDescriptor
- the persister of the element being cached- Returns:
- a key which can be used to identify an element unequivocally on this same region
-
getNaturalIdValues
Object getNaturalIdValues(Object cacheKey)
Performs reverse operation togenerateCacheKey(java.lang.Object, org.hibernate.persister.entity.EntityPersister, org.hibernate.engine.spi.SharedSessionContractImplementor)
, returning the original naturalIdValues.- Parameters:
cacheKey
- key returned fromgenerateCacheKey(java.lang.Object, org.hibernate.persister.entity.EntityPersister, org.hibernate.engine.spi.SharedSessionContractImplementor)
- Returns:
- the sequence of values which unequivocally identifies a cached element on this region
-
insert
boolean insert(SharedSessionContractImplementor session, Object key, Object value)
Called afterQuery an item has been inserted (beforeQuery the transaction completes), instead of calling evict(). This method is used by "synchronous" concurrency strategies.- Parameters:
session
- Current sessionkey
- The item keyvalue
- The item- Returns:
- Were the contents of the cache actually changed by this operation?
- Throws:
CacheException
- Propagated from underlying cache provider
-
afterInsert
boolean afterInsert(SharedSessionContractImplementor session, Object key, Object value)
Called afterQuery an item has been inserted (afterQuery the transaction completes), instead of calling release(). This method is used by "asynchronous" concurrency strategies.- Parameters:
session
- Current sessionkey
- The item keyvalue
- The item- Returns:
- Were the contents of the cache actually changed by this operation?
- Throws:
CacheException
- Propagated from underlying cache provider
-
update
boolean update(SharedSessionContractImplementor session, Object key, Object value)
Called afterQuery an item has been updated (beforeQuery the transaction completes), instead of calling evict(). This method is used by "synchronous" concurrency strategies.- Parameters:
session
- Current sessionkey
- The item keyvalue
- The item- Returns:
- Were the contents of the cache actually changed by this operation?
- Throws:
CacheException
- Propagated from underlying cache provider
-
afterUpdate
boolean afterUpdate(SharedSessionContractImplementor session, Object key, Object value, SoftLock lock)
Called afterQuery an item has been updated (afterQuery the transaction completes), instead of calling release(). This method is used by "asynchronous" concurrency strategies.- Parameters:
session
- Current sessionkey
- The item keyvalue
- The itemlock
- The lock previously obtained fromCachedDomainDataAccess.lockItem(org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object, java.lang.Object)
- Returns:
- Were the contents of the cache actually changed by this operation?
- Throws:
CacheException
- Propagated from underlying cache provider
-
-