Class CacheImpl
- java.lang.Object
-
- org.eclipse.persistence.internal.jpa.CacheImpl
-
-
Constructor Summary
Constructors Constructor Description CacheImpl(EntityManagerFactoryDelegate emf)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()ADVANCED: Resets the entire Object cache, and the Query cache.voidclear(java.lang.Class cls)ADVANCED: Resets the cache for only the instances of the given Class type.voidclearQueryCache()Clear all the query results caches.voidclearQueryCache(java.lang.Class entityClass)Clear all named query results cache associated with entity class.voidclearQueryCache(java.lang.String queryName)Clear the named query results cache associated with the query name.booleancontains(java.lang.Class cls, java.lang.Object id)Returns true if the cache contains an Object with the id and Class type, and is valid.booleancontains(java.lang.Object object)Returns true if the cache contains an Object with the same id and Class type of the given object.voidevict(java.lang.Class entityOrMappedSuperclassToEvict)Sets all instances of the class to be invalid.voidevict(java.lang.Class classToEvict, java.lang.Object id)Sets an Object with the id and Class type to be invalid in the cache.voidevict(java.lang.Class classToEvict, java.lang.Object id, boolean invalidateInCluster)Sets an Object with the id and Class type to be invalid in the cache.voidevict(java.lang.Object object)Sets the object to be invalid in the cache.voidevict(java.lang.Object object, boolean invalidateInCluster)Sets an Object to be invalid in the cache.voidevictAll()Sets all instances in the cache to be invalid.protected org.eclipse.persistence.sessions.IdentityMapAccessorgetAccessor()INTERNAL: Return the IdentityMapAccessor associated with the session on the EntityManagerFactory on this CacheImpl.protected EntityManagerFactoryDelegategetEntityManagerFactory()INTERNAL: Return the EntityManagerFactory associated with this CacheImpl.java.lang.ObjectgetId(java.lang.Object object)This method will return the objects's Id.java.lang.ObjectgetObject(java.lang.Class cls, java.lang.Object id)Returns the Object from the cache map with the id and Class type.protected org.eclipse.persistence.sessions.SessiongetSession()INTERNAL: Return the Session associated with the EntityManagerFactory.booleanisValid(java.lang.Class cls, java.lang.Object id)Returns true if the Object with the id and Class type is valid in the cache.booleanisValid(java.lang.Object object)Returns true if the Object with the same id and Class type of the the given Object is valid in the cache.voidprint()Used to print all the Objects in the cache.voidprint(java.lang.Class cls)Used to print all the Objects in the cache of the Class type.voidprintLocks()Used to print all the currently locked cache keys in the cache.java.lang.ObjectputObject(java.lang.Object object)ADVANCED: Puts the given Object into the cache.java.lang.ObjectremoveObject(java.lang.Class cls, java.lang.Object id)ADVANCED: Removes the Object with the id and Class type from the cache.java.lang.ObjectremoveObject(java.lang.Object object)ADVANCED: Removes the Object from the cache.longtimeToLive(java.lang.Object object)Returns the remaining life of the given Object (in milliseconds).<T> Tunwrap(java.lang.Class<T> cls)voidvalidate()This can be used to help debugging an Object identity problem.
-
-
-
Constructor Detail
-
CacheImpl
public CacheImpl(EntityManagerFactoryDelegate emf)
- Parameters:
emf-
-
-
Method Detail
-
contains
public boolean contains(java.lang.Class cls, java.lang.Object id)Returns true if the cache contains an Object with the id and Class type, and is valid.- Specified by:
containsin interfacejavax.persistence.Cache- See Also:
Cache.contains(Class, Object)
-
evict
public void evict(java.lang.Class classToEvict, java.lang.Object id)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
- Specified by:
evictin interfacejavax.persistence.Cache- Parameters:
classToEvict- - class to evict - usually representing an Entity or MappedSuperclassid- - Primary key of the Entity or MappedSuperclass Class A null id means invalidate the class - possibly the entire tree or subtree- See Also:
Cache.evict(Class, Object)
-
evict
public void evict(java.lang.Class classToEvict, java.lang.Object id, boolean invalidateInCluster)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
- Specified by:
evictin interfaceJpaCache- Parameters:
classToEvict- - class to evict - usually representing an Entity or MappedSuperclassid- - Primary key of the Entity or MappedSuperclass Class A null id means invalidate the class - possibly the entire tree or subtreeinvalidateInCluster- - Invalidate the object id in the cluster, this only applies to a non-null id.- See Also:
Cache.evict(Class, Object)
-
evict
public void evict(java.lang.Class entityOrMappedSuperclassToEvict)
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
- Specified by:
evictin interfacejavax.persistence.Cache- Parameters:
entityOrMappedSuperclassToEvict- - Entity or MappedSuperclass Class- See Also:
Cache.evict(Class)
-
evictAll
public void evictAll()
Sets all instances in the cache to be invalid.- Specified by:
evictAllin interfacejavax.persistence.Cache- See Also:
Cache.evictAll()
-
clear
public void 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.
-
clear
public void clear(java.lang.Class cls)
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.
-
clearQueryCache
public void clearQueryCache()
Clear all the query results caches.- Specified by:
clearQueryCachein interfaceJpaCache
-
clearQueryCache
public void clearQueryCache(java.lang.String queryName)
Clear the named query results cache associated with the query name.- Specified by:
clearQueryCachein interfaceJpaCache
-
clearQueryCache
public void clearQueryCache(java.lang.Class entityClass)
Clear all named query results cache associated with entity class.- Specified by:
clearQueryCachein interfaceJpaCache
-
timeToLive
public long timeToLive(java.lang.Object object)
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.- Specified by:
timeToLivein interfaceJpaCache
-
isValid
public boolean isValid(java.lang.Object object)
Returns true if the Object with the same id and Class type of the the given Object is valid in the cache.
-
isValid
public boolean isValid(java.lang.Class cls, java.lang.Object id)Returns true if the Object with the id and Class type is valid in the cache.
-
print
public void print()
Used to print all the Objects in the cache. The output of this method will be logged to this persistence unit's SessionLog at SEVERE level.
-
print
public void print(java.lang.Class cls)
Used to print all the Objects in the cache of the Class type. The output of this method will be logged to this persistence unit's SessionLog at SEVERE level.
-
printLocks
public void 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.- Specified by:
printLocksin interfaceJpaCache
-
validate
public void 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.
-
getObject
public java.lang.Object getObject(java.lang.Class cls, java.lang.Object id)Returns the Object from the cache map with the id and Class type.
-
putObject
public java.lang.Object putObject(java.lang.Object object)
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.
-
removeObject
public java.lang.Object removeObject(java.lang.Object object)
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.
- Specified by:
removeObjectin interfaceJpaCache
-
removeObject
public java.lang.Object removeObject(java.lang.Class cls, java.lang.Object id)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.
- Specified by:
removeObjectin interfaceJpaCache
-
contains
public boolean contains(java.lang.Object object)
Returns true if the cache contains an Object with the same id and Class type of the given object.
-
evict
public void evict(java.lang.Object object)
Sets the object to be invalid in the cache.- Specified by:
evictin interfaceJpaCache- See Also:
JpaCache.evict(Object)
-
evict
public void evict(java.lang.Object object, boolean invalidateInCluster)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.
-
getEntityManagerFactory
protected EntityManagerFactoryDelegate getEntityManagerFactory()
INTERNAL: Return the EntityManagerFactory associated with this CacheImpl.- Returns:
-
getSession
protected org.eclipse.persistence.sessions.Session getSession()
INTERNAL: Return the Session associated with the EntityManagerFactory.- Returns:
-
getAccessor
protected org.eclipse.persistence.sessions.IdentityMapAccessor getAccessor()
INTERNAL: Return the IdentityMapAccessor associated with the session on the EntityManagerFactory on this CacheImpl.- Returns:
-
getId
public java.lang.Object getId(java.lang.Object object)
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.- Specified by:
getIdin interfaceJpaCache- See Also:
JpaCache.getId(Object)
-
unwrap
public <T> T unwrap(java.lang.Class<T> cls)
- Specified by:
unwrapin interfacejavax.persistence.Cache
-
-