Top Description Fields Constructors Methods
org.eclipse.persistence.internal.jpa

public Class CacheImpl

extends Object
implements JpaCache
Class Inheritance
All Implemented Interfaces
org.eclipse.persistence.jpa.JpaCache, jakarta.persistence.Cache
Imports
jakarta.persistence.Cache, .PersistenceException, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.internal.identitymaps.CacheKey, org.eclipse.persistence.internal.localization.ExceptionLocalization, org.eclipse.persistence.internal.sessions.AbstractSession, org.eclipse.persistence.jpa.JpaCache, org.eclipse.persistence.sessions.IdentityMapAccessor, .Session

Implements the JPA Cache interface using the EclipseLink cache API through IdentityMapAccessor.
Author
DaraniY

Field Summary

Modifier and TypeField and Description
private EntityManagerFactoryDelegate
emf

The EntityManagerFactory associated with this Cache

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Implements org.eclipse.persistence.jpa.JpaCache.clear.

ADVANCED: Resets the entire Object cache, and the Query cache.
public void
clear(Class<?> cls)

Implements org.eclipse.persistence.jpa.JpaCache.clear.

ADVANCED: Resets the cache for only the instances of the given Class type.
public void
clearQueryCache()

Implements org.eclipse.persistence.jpa.JpaCache.clearQueryCache.

Clear all the query results caches.
public void
clearQueryCache(String queryName)

Implements org.eclipse.persistence.jpa.JpaCache.clearQueryCache.

Clear the named query results cache associated with the query name.
public void
clearQueryCache(Class<?> entityClass)

Implements org.eclipse.persistence.jpa.JpaCache.clearQueryCache.

Clear all named query results cache associated with entity class.
public boolean
contains(Class<T>
entity class
cls
,
Object
primary key
id
)

Implements jakarta.persistence.Cache.contains.

Returns true if the cache contains an Object with the id and Class type, and is valid.
public boolean
contains(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.contains.

Returns true if the cache contains an Object with the same id and Class type of the given object.
private Object
createPrimaryKeyFromId(Class<?> cls, Object id)

Return the EclipseLink cache key object from the JPA Id object.

public void
evict(Class<T>
- class to evict - usually representing an Entity or MappedSuperclass
classToEvict
,
Object
- Primary key of the Entity or MappedSuperclass Class A null id means invalidate the class - possibly the entire tree or subtree
id
)

Implements jakarta.persistence.Cache.evict.

Sets an Object with the id and Class type to be invalid in the cache.
public void
evict(Class<?>
- class to evict - usually representing an Entity or MappedSuperclass
classToEvict
,
Object
- Primary key of the Entity or MappedSuperclass Class A null id means invalidate the class - possibly the entire tree or subtree
id
,
boolean
- Invalidate the object id in the cluster, this only applies to a non-null id.
invalidateInCluster
)

Implements org.eclipse.persistence.jpa.JpaCache.evict.

Sets an Object with the id and Class type to be invalid in the cache.
public void
evict(Class<T>
- Entity or MappedSuperclass Class
entityOrMappedSuperclassToEvict
)

Implements jakarta.persistence.Cache.evict.

Sets all instances of the class to be invalid.
public void
evict(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.evict.

Sets the object to be invalid in the cache.
public void
evict(Object object, boolean invalidateInCluster)

Implements org.eclipse.persistence.jpa.JpaCache.evict.

Sets an Object to be invalid in the cache.
public void
evictAll()

Implements jakarta.persistence.Cache.evictAll.

Sets all instances in the cache to be invalid.
private void
evictAssignableEntitySuperclass(Class<?> possibleSuperclass, Object id)

INTERNAL: This private method searches the map of descriptors for possible superclasses to the passed in class parameter and invalidates only entities found in the cache.

protected IdentityMapAccessor
getAccessor()

INTERNAL: Return the IdentityMapAccessor associated with the session on the EntityManagerFactory on this CacheImpl.

protected EntityManagerFactoryDelegate
getEntityManagerFactory()

INTERNAL: Return the EntityManagerFactory associated with this CacheImpl.

public Object
getId(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.getId.

This method will return the objects's Id. If the descriptor associated with the domain object is null - an IllegalArgumentException is thrown.
public Object
getObject(Class<?> cls, Object id)

Implements org.eclipse.persistence.jpa.JpaCache.getObject.

Returns the Object from the cache map with the id and Class type.
protected Session
getSession()

INTERNAL: Return the Session associated with the EntityManagerFactory.

public boolean
isValid(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.isValid.

Returns true if the Object with the same id and Class type of the the given Object is valid in the cache.
public boolean
isValid(Class<?> cls, Object id)

Implements org.eclipse.persistence.jpa.JpaCache.isValid.

Returns true if the Object with the id and Class type is valid in the cache.
public void
printLocks()

Implements org.eclipse.persistence.jpa.JpaCache.printLocks.

Used to print all the currently locked cache keys in the cache.
public Object
putObject(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.putObject.

ADVANCED: Puts the given Object into the cache.
public Object
removeObject(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.removeObject.

ADVANCED: Removes the Object from the cache.
public Object
removeObject(Class<?> cls, Object id)

Implements org.eclipse.persistence.jpa.JpaCache.removeObject.

ADVANCED: Removes the Object with the id and Class type from the cache.
public long
timeToLive(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.timeToLive.

Returns the remaining life of the given Object (in milliseconds).
public <T> T
unwrap(Class<T>
the class of the object to be returned. This is normally either the underlying Cache implementation class or an interface that it implements.
cls
)

Implements jakarta.persistence.Cache.unwrap.

Return an object of the specified type to allow access to the provider-specific API.
public void
validate()

Implements org.eclipse.persistence.jpa.JpaCache.validate.

This can be used to help debugging an Object identity problem.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

emfback to summary
private EntityManagerFactoryDelegate emf

The EntityManagerFactory associated with this Cache

Constructor Detail

CacheImplback to summary
public CacheImpl(EntityManagerFactoryDelegate emf)

Method Detail

clearback to summary
public void clear()

Implements org.eclipse.persistence.jpa.JpaCache.clear.

ADVANCED: Resets the entire Object cache, and the Query cache.

Note

Be careful using this method. This method blows away both this session's and its parent's caches. This includes the server cache or any other cache. This throws away any Objects that have been read in. Extreme caution should be used before doing this because Object identity will no longer be maintained for any Objects currently read in. This should only be called if the application knows that it no longer has references to Objects held in the cache.

Annotations
@Override
clearback to summary
public void clear(Class<?> cls)

Implements org.eclipse.persistence.jpa.JpaCache.clear.

ADVANCED: Resets the cache for only the instances of the given Class type. For inheritance the user must make sure that they only use the root class, clearing a subclass cache is not allowed (as they share their parents cache).

Note

Caution must be used in doing this to ensure that the Objects within the cache are not referenced from other Objects of other classes or from the application.

Annotations
@Override
clearQueryCacheback to summary
public void clearQueryCache()

Implements org.eclipse.persistence.jpa.JpaCache.clearQueryCache.

Clear all the query results caches.

Annotations
@Override
clearQueryCacheback to summary
public void clearQueryCache(String queryName)

Implements org.eclipse.persistence.jpa.JpaCache.clearQueryCache.

Clear the named query results cache associated with the query name.

Annotations
@Override
clearQueryCacheback to summary
public void clearQueryCache(Class<?> entityClass)

Implements org.eclipse.persistence.jpa.JpaCache.clearQueryCache.

Clear all named query results cache associated with entity class.

Annotations
@Override
containsback to summary
public boolean contains(Class<T> cls, Object id)

Implements jakarta.persistence.Cache.contains.

Returns true if the cache contains an Object with the id and Class type, and is valid.

Parameters
cls:Class<T>

Doc from jakarta.persistence.Cache.contains.

entity class

id:Object

Doc from jakarta.persistence.Cache.contains.

primary key

Returns:boolean

Doc from jakarta.persistence.Cache.contains.

boolean indicating whether the entity is in the cache

Annotations
@Override
@SuppressWarnings:rawtypes
See Also
Cache#contains(Class, Object)
containsback to summary
public boolean contains(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.contains.

Returns true if the cache contains an Object with the same id and Class type of the given object.

Annotations
@Override
createPrimaryKeyFromIdback to summary
private Object createPrimaryKeyFromId(Class<?> cls, Object id)

Return the EclipseLink cache key object from the JPA Id object.

evictback to summary
public void evict(Class<T> classToEvict, Object id)

Implements jakarta.persistence.Cache.evict.

Sets an Object with the id and Class type to be invalid in the cache. Remove the data for entities of the specified class (and its subclasses) from the cache.

If the class is a MappedSuperclass then the first entity above in the inheritance hierarchy will be evicted along with all implementing subclasses If the class is not an Entity or MappedSuperclass but is the root of an entity inheritance tree then evict the subtree If the class is not an Entity or MappedSuperclass but inherits from one then evict up to root descriptor

Parameters
classToEvict:Class<T>

- class to evict - usually representing an Entity or MappedSuperclass

id:Object

- Primary key of the Entity or MappedSuperclass Class A null id means invalidate the class - possibly the entire tree or subtree

Annotations
@Override
@SuppressWarnings:rawtypes
See Also
Cache#evict(Class, Object)
evictback to summary
public void evict(Class<?> classToEvict, Object id, boolean invalidateInCluster)

Implements org.eclipse.persistence.jpa.JpaCache.evict.

Sets an Object with the id and Class type to be invalid in the cache. Remove the data for entities of the specified class (and its subclasses) from the cache.

If the class is a MappedSuperclass then the first entity above in the inheritance hierarchy will be evicted along with all implementing subclasses If the class is not an Entity or MappedSuperclass but is the root of an entity inheritance tree then evict the subtree If the class is not an Entity or MappedSuperclass but inherits from one then evict up to root descriptor

Parameters
classToEvict:Class<?>

- class to evict - usually representing an Entity or MappedSuperclass

id:Object

- Primary key of the Entity or MappedSuperclass Class A null id means invalidate the class - possibly the entire tree or subtree

invalidateInCluster:boolean

- Invalidate the object id in the cluster, this only applies to a non-null id.

Annotations
@Override
See Also
Cache#evict(Class, Object)
evictback to summary
public void evict(Class<T> entityOrMappedSuperclassToEvict)

Implements jakarta.persistence.Cache.evict.

Sets all instances of the class to be invalid. Remove the data for entities of the specified class (and its subclasses) from the cache.

If the class is a MappedSuperclass then the first entity above in the inheritance hierarchy will be evicted along with all implementing subclasses If the class is not an Entity or MappedSuperclass (such as an Embeddable or plain java class) - nothing will be evicted

Parameters
entityOrMappedSuperclassToEvict:Class<T>

- Entity or MappedSuperclass Class

Annotations
@Override
@SuppressWarnings:rawtypes
See Also
Cache#evict(Class)
evictback to summary
public void evict(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.evict.

Sets the object to be invalid in the cache.

Annotations
@Override
See Also
JpaCache#evict(Object)
evictback to summary
public void evict(Object object, boolean invalidateInCluster)

Implements org.eclipse.persistence.jpa.JpaCache.evict.

Sets an Object to be invalid in the cache. If true is passed, the object is also invalidated across cache coordination. Cache coordination must be enabled for this to have an affect.

Annotations
@Override
evictAllback to summary
public void evictAll()

Implements jakarta.persistence.Cache.evictAll.

Sets all instances in the cache to be invalid.

Annotations
@Override
See Also
Cache#evictAll()
evictAssignableEntitySuperclassback to summary
private void evictAssignableEntitySuperclass(Class<?> possibleSuperclass, Object id)

INTERNAL: This private method searches the map of descriptors for possible superclasses to the passed in class parameter and invalidates only entities found in the cache. If the class is not an Entity or MappedSuperclass (such as an Embeddable or plain java class) - nothing will be evicted

getAccessorback to summary
protected IdentityMapAccessor getAccessor()

INTERNAL: Return the IdentityMapAccessor associated with the session on the EntityManagerFactory on this CacheImpl.

getEntityManagerFactoryback to summary
protected EntityManagerFactoryDelegate getEntityManagerFactory()

INTERNAL: Return the EntityManagerFactory associated with this CacheImpl.

getIdback to summary
public Object getId(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.getId.

This method will return the objects's Id. If the descriptor associated with the domain object is null - an IllegalArgumentException is thrown. If the CMPPolicy associated with the domain object's descriptor is null the Id will be determined using the ObjectBuilder on the descriptor - which may return the Id stored in the weaved _persistence_primaryKey field.

Annotations
@Override
See Also
JpaCache#getId(Object)
getObjectback to summary
public Object getObject(Class<?> cls, Object id)

Implements org.eclipse.persistence.jpa.JpaCache.getObject.

Returns the Object from the cache map with the id and Class type.

Annotations
@Override
getSessionback to summary
protected Session getSession()

INTERNAL: Return the Session associated with the EntityManagerFactory.

isValidback to summary
public boolean isValid(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.isValid.

Returns true if the Object with the same id and Class type of the the given Object is valid in the cache.

Annotations
@Override
isValidback to summary
public boolean isValid(Class<?> cls, Object id)

Implements org.eclipse.persistence.jpa.JpaCache.isValid.

Returns true if the Object with the id and Class type is valid in the cache.

Annotations
@Override
printLocksback to summary
public void printLocks()

Implements org.eclipse.persistence.jpa.JpaCache.printLocks.

Used to print all the currently locked cache keys in the cache. The output of this method will be logged to this persistence unit's SessionLog at SEVERE level.

Annotations
@Override
putObjectback to summary
public Object putObject(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.putObject.

ADVANCED: Puts the given Object into the cache. This is a very advanced method, and caution should be used in adding objects to the cache as other objects may have relationships to previous object, or this object may have relationships to other objects.

Annotations
@Override
removeObjectback to summary
public Object removeObject(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.removeObject.

ADVANCED: Removes the Object from the cache.

Note

Caution should be used when calling to avoid violating Object identity. The application should only call this if its known that no references to the Object exist.

Annotations
@Override
removeObjectback to summary
public Object removeObject(Class<?> cls, Object id)

Implements org.eclipse.persistence.jpa.JpaCache.removeObject.

ADVANCED: Removes the Object with the id and Class type from the cache.

Note

Caution should be used when calling to avoid violating Object identity. The application should only call this if its known that no references to the Object exist.

Annotations
@Override
timeToLiveback to summary
public long timeToLive(Object object)

Implements org.eclipse.persistence.jpa.JpaCache.timeToLive.

Returns the remaining life of the given Object (in milliseconds). This method is associated with use of cache invalidation feature and returns the difference between the next expiry time of the Object and its read time. The method will return 0 for invalidated Objects.

Annotations
@Override
unwrapback to summary
public <T> T unwrap(Class<T> cls)

Implements jakarta.persistence.Cache.unwrap.

Doc from jakarta.persistence.Cache.unwrap.

Return an object of the specified type to allow access to the provider-specific API. If the provider's Cache implementation does not support the specified class, the PersistenceException is thrown.

Parameters
cls:Class<T>

the class of the object to be returned. This is normally either the underlying Cache implementation class or an interface that it implements.

Returns:T

an instance of the specified class

Annotations
@Override
validateback to summary
public void validate()

Implements org.eclipse.persistence.jpa.JpaCache.validate.

This can be used to help debugging an Object identity problem. An Object identity problem is when an Object in the cache references an Object that is not in the cache. This method will validate that all cached Objects are in a correct state.

Annotations
@Override