Top Description Methods
org.hibernate.cache.spi.access

public Interface CachedDomainDataAccess

Known Direct Subinterfaces
org.hibernate.cache.spi.access.CollectionDataAccess, org.hibernate.cache.spi.access.EntityDataAccess, org.hibernate.cache.spi.access.NaturalIdDataAccess
Known Direct Implementers
org.hibernate.cache.spi.support.AbstractCachedDomainDataAccess
Imports
jakarta.persistence.Cache, org.hibernate.cache.CacheException, org.hibernate.cache.spi.DomainDataRegion, org.hibernate.engine.spi.SharedSessionContractImplementor

Base contract for accessing the underlying cached data for a particular Navigable of the user's domain model in a transactionally ACID manner.

API Note

Note that the following methods are not considered "transactional" in this sense: contains, lockRegion, unlockRegion, evict, evictAll. The semantics of these methods come from JPA's Cache contract.

Implementation Specification

The "non-transactional" methods noted in the @apiNote should be implemented to ignore any locking. That is, when evict is called, the item should be forcibly removed from the cache regardless of whether anything has locked it.

Authors
Steve Ebersole, Gail Badner

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

True if the underlying cache contains corresponding data; false otherwise.
contains
(Object
The cache key
key
)

Determine whether this region contains data for the given key.

public void
evict(Object
The key of the item to remove
key
)

Forcibly evict an item from the cache immediately without regard for transaction isolation and/or locking.

public void
evictAll()

Forcibly evict all items from the cache immediately without regard for transaction isolation.

public Object

Returns:

the cached data or null
get
(SharedSessionContractImplementor
Current session.
session
,
Object
The key of the item to be retrieved.
key
)

Attempt to retrieve an object from the cache.

public AccessType
getAccessType()

The type of access implemented

public DomainDataRegion
getRegion()

The region containing the data being accessed

public SoftLock

Returns:

A representation of our lock on the item; or null.
lockItem
(SharedSessionContractImplementor
Current session.
session
,
Object
The key of the item to lock
key
,
Object
The item's current version value
version
)

We are going to attempt to update/delete the keyed object.

public SoftLock

Returns:

A representation of our lock on the item; or null.
lockRegion
()

Lock the entire region

public boolean

Returns:

true if the object was successfully cached
putFromLoad
(SharedSessionContractImplementor
Current session.
session
,
Object
The item key
key
,
Object
The item
value
,
Object
the item version number
version
)

Attempt to cache an object, afterQuery loading from the database.

public boolean

Returns:

true if the object was successfully cached
putFromLoad
(SharedSessionContractImplementor
Current session.
session
,
Object
The item key
key
,
Object
The item
value
,
Object
the item version number
version
,
boolean
Explicit minimalPut flag
minimalPutOverride
)

Attempt to cache an object, afterQuery loading from the database, explicitly specifying the minimalPut behavior.

public void
remove(SharedSessionContractImplementor
Current session.
session
,
Object
The key of the item to remove
key
)

Called afterQuery an item has become stale (beforeQuery the transaction completes).

public void
removeAll(SharedSessionContractImplementor session)

Remove all data for this accessed type

public void
unlockItem(SharedSessionContractImplementor
Current session.
session
,
Object
The item key
key
,
SoftLock
The lock previously obtained from lockItem
lock
)

Called when we have finished the attempted update/delete (which may or may not have been successful), after transaction completion.

public void
unlockRegion(SoftLock
The lock previously obtained from lockRegion
lock
)

Called after we have finished the attempted invalidation of the entire region

Method Detail

containsback to summary
public boolean contains(Object key)

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.

Parameters
key:Object

The cache key

Returns:boolean

True if the underlying cache contains corresponding data; false otherwise.

evictback to summary
public void evict(Object key)

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 jakarta.persistence.Cache#evict(Class, Object), as well as the Hibernate extension org.hibernate.Cache#evictEntityData(Class, Object) and org.hibernate.Cache#evictEntityData(String, Object)

Parameters
key:Object

The key of the item to remove

Exceptions
CacheException:
Propagated from underlying cache provider
evictAllback to summary
public void evictAll()

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 extensions org.hibernate.Cache#evictEntityData(Class), org.hibernate.Cache#evictEntityData(String) and org.hibernate.Cache#evictEntityData()

Exceptions
CacheException:
Propagated from underlying cache provider
getback to summary
public Object get(SharedSessionContractImplementor session, Object key)

Attempt to retrieve an object from the cache. Mainly used in attempting to resolve entities/collections from the second level cache.

Parameters
session:SharedSessionContractImplementor

Current session.

key:Object

The key of the item to be retrieved.

Returns:Object

the cached data or null

Exceptions
CacheException:
Propagated from underlying cache provider
getAccessTypeback to summary
public AccessType getAccessType()

The type of access implemented

getRegionback to summary
public DomainDataRegion getRegion()

The region containing the data being accessed

lockItemback to summary
public SoftLock lockItem(SharedSessionContractImplementor session, Object key, Object version)

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 unlockItem, to release the lock. Concurrency strategies which do not support client-visible locks may silently return null.

Parameters
session:SharedSessionContractImplementor

Current session.

key:Object

The key of the item to lock

version:Object

The item's current version value

Returns:SoftLock

A representation of our lock on the item; or null.

Exceptions
CacheException:
Propagated from underlying cache provider
lockRegionback to summary
public SoftLock lockRegion()

Lock the entire region

Returns:SoftLock

A representation of our lock on the item; or null.

Exceptions
CacheException:
Propagated from underlying cache provider
putFromLoadback to summary
public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, Object version)

Attempt to cache an object, afterQuery loading from the database.

Parameters
session:SharedSessionContractImplementor

Current session.

key:Object

The item key

value:Object

The item

version:Object

the item version number

Returns:boolean

true if the object was successfully cached

Exceptions
CacheException:
Propagated from underlying cache provider
putFromLoadback to summary
public 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.

Parameters
session:SharedSessionContractImplementor

Current session.

key:Object

The item key

value:Object

The item

version:Object

the item version number

minimalPutOverride:boolean

Explicit minimalPut flag

Returns:boolean

true if the object was successfully cached

Exceptions
CacheException:
Propagated from underlying cache provider
removeback to summary
public void remove(SharedSessionContractImplementor session, Object key)

Called afterQuery an item has become stale (beforeQuery the transaction completes). This method is used by "synchronous" concurrency strategies.

Parameters
session:SharedSessionContractImplementor

Current session.

key:Object

The key of the item to remove

Exceptions
CacheException:
Propagated from underlying cache provider
removeAllback to summary
public void removeAll(SharedSessionContractImplementor session)

Remove all data for this accessed type

Exceptions
CacheException:
Propagated from underlying cache provider
unlockItemback to summary
public void 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. This method is used by "asynchronous" concurrency strategies.

Parameters
session:SharedSessionContractImplementor

Current session.

key:Object

The item key

lock:SoftLock

The lock previously obtained from lockItem

Exceptions
CacheException:
Propagated from underlying cache provider
unlockRegionback to summary
public void unlockRegion(SoftLock lock)

Called after we have finished the attempted invalidation of the entire region

Parameters
lock:SoftLock

The lock previously obtained from lockRegion

Exceptions
CacheException:
Propagated from underlying cache provider