This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 248780 - JPA 2.0 Cache interface
Summary: JPA 2.0 Cache interface
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL: http://wiki.eclipse.org/EclipseLink/D...
Whiteboard:
Keywords:
Depends on: 312503 315287
Blocks: 315591 315714
  Show dependency tree
 
Reported: 2008-09-26 16:20 EDT by Gordon Yorke CLA
Modified: 2022-06-09 10:26 EDT (History)
7 users (show)

See Also:
douglas.clarke: review?


Attachments
svn diff (3.87 KB, patch)
2008-12-01 19:36 EST, Darani Yallapragada CLA
no flags Details | Diff
Implementation of Cache interface (2.24 KB, patch)
2008-12-01 19:37 EST, Darani Yallapragada CLA
no flags Details | Diff
Cache Interface (1.40 KB, patch)
2008-12-01 19:39 EST, Darani Yallapragada CLA
no flags Details | Diff
CacheImpl Junit test (7.14 KB, patch)
2008-12-01 19:40 EST, Darani Yallapragada CLA
no flags Details | Diff
patch file of svn diff (15.99 KB, patch)
2008-12-02 17:34 EST, Darani Yallapragada CLA
no flags Details | Diff
bug-248780.patch (15.99 KB, patch)
2008-12-02 18:17 EST, Darani Yallapragada CLA
no flags Details | Diff
updated patch for bug-248780 (15.93 KB, patch)
2008-12-03 12:03 EST, Darani Yallapragada CLA
no flags Details | Diff
updated patch for bug-248780 (16.06 KB, patch)
2008-12-03 17:52 EST, Darani Yallapragada CLA
no flags Details | Diff
updated patch of Bug#248780 (16.06 KB, patch)
2008-12-04 12:46 EST, Darani Yallapragada CLA
no flags Details | Diff
Proposed Solution (5.26 KB, application/octet-stream)
2009-04-06 22:21 EDT, Doug Clarke CLA
no flags Details
248780 CacheImpl refactor for MappedSuperclass support (based on Doug's analysis) (38.42 KB, patch)
2010-04-05 18:04 EDT, Michael OBrien CLA
no flags Details | Diff
CacheImpl refactor for MappedSuperclass support including test suite modifications (70.53 KB, patch)
2010-04-13 09:58 EDT, Michael OBrien CLA
no flags Details | Diff
CacheImpl refactor for MappedSuperclass support including test suite modifications 2 (56.28 KB, patch)
2010-04-22 09:54 EDT, Michael OBrien CLA
no flags Details | Diff
CacheImpl refactor for MappedSuperclass support including test suite modifications 3 (68.84 KB, patch)
2010-06-02 14:22 EDT, Michael OBrien CLA
no flags Details | Diff
CacheImpl refactor for MappedSuperclass support including test suite modifications 3 (71.78 KB, patch)
2010-06-02 22:36 EDT, Michael OBrien CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gordon Yorke CLA 2008-09-26 16:20:17 EDT
JPA 2.0 has added a simplistic Cache interface to allow developers to interrogate the cache and invalidate entities that exist there.
Comment 1 Darani Yallapragada CLA 2008-12-01 19:36:00 EST
Created attachment 119224 [details]
svn diff 

The above attachment shows the changes that are made in EntityManagerFactoryImpl and EntityManagerFactory interface.
Comment 2 Darani Yallapragada CLA 2008-12-01 19:37:58 EST
Created attachment 119225 [details]
Implementation of Cache interface

This is a class that implements the methods of Cache interface.
Comment 3 Darani Yallapragada CLA 2008-12-01 19:39:07 EST
Created attachment 119226 [details]
Cache Interface

This is a Cache interface that defines the methods
Comment 4 Darani Yallapragada CLA 2008-12-01 19:40:47 EST
Created attachment 119227 [details]
CacheImpl Junit test

This class tests the methods of CacheImpl.java.
Comment 5 Darani Yallapragada CLA 2008-12-02 17:34:17 EST
Created attachment 119334 [details]
patch file of svn diff

This is a updated patch of the svn diff. Please do ignore the previous files.
Comment 6 Darani Yallapragada CLA 2008-12-02 18:17:28 EST
Created attachment 119345 [details]
bug-248780.patch
Comment 7 Darani Yallapragada CLA 2008-12-03 12:03:52 EST
Created attachment 119399 [details]
updated patch for bug-248780

patch updated with the changes suggested by Gordon.
Comment 8 Darani Yallapragada CLA 2008-12-03 17:52:43 EST
Created attachment 119443 [details]
updated patch for bug-248780
Comment 9 Darani Yallapragada CLA 2008-12-04 12:46:02 EST
Created attachment 119532 [details]
updated patch of Bug#248780

updated patch with the changes suggested by Andrei.
Comment 10 Mitesh Meswani CLA 2008-12-04 20:00:55 EST
Checked in patch provided by Darani (Revision 2896)
Comment 11 Samba Kolusu CLA 2009-02-09 14:08:42 EST
Is there a possibility of a relation between JPA 2.0 Cache API and the JCACHE API(JSR 107)?
How about making the JPA 2.0 API a subset of JCACHE API ? May be eventually it may result in fully implementing the JCACHE spec ?
Comment 12 Doug Clarke CLA 2009-04-05 07:29:05 EDT
I was reviewing some of the JPA 2.0 features and have a few issues we should address in the implementation of Cache.

http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/CacheImpl.java

1. Unsure if we need to hold all of this state or just hold the EMF and access the necessary IdentityMapAccessor through this access.

2. We will need to support more then just ServerSession so we need to have impls such as this just rely on more general interfaces for the shared session such as Session or DatabaseSession interfaces.

3. The createPKVector does not handle the case where the descriptor does not have a CMPPolicy. This occurs when bootstrapping from native metadata. Also does not properly handle the case where the cls provided is not associated with a descriptor.

4. Should we support passing in MappedSuperclass or general types from the entity inheritance tree? I believe we should.
Comment 13 Doug Clarke CLA 2009-04-05 11:11:23 EDT
Changed target from 1.1 to 2.0
Comment 14 Gordon Yorke CLA 2009-04-06 11:59:47 EDT
Supporting MappedSuperClass would be very strange as a MappedSuperClass is not really a cached type nor is it a mapped hierarchy member.  In many cases supporting evicting a MappedSuperClass and interpreting that to mean evict all extenders would mean the whole cache gets evicted.  
I recommend throwing an IllegalArgumentException if a class type other than an entity is passed in to this code.

Supporting evicting all subclasses of an Inheritance hierarchy also requires some tweaking as the current call would remove all members of the hierarchy and not just subclasses.
Comment 15 Doug Clarke CLA 2009-04-06 22:19:12 EDT
The comment on javax.persistence.Cache states:

    /**
     * Remove the data for entities of the specified class (and its subclasses)
     * from the cache.
     */
    public void evict(Class cls);

Trying this class as a mapped entity first is simple enough. If it is mapped it will follow the implied subclasses requirement. Even if it is the root of an inheritance tree no additional work is required.

The only tough part is when a developer passes in a non-entity class that may be a mapped superclass or may simply be a class or interface shared by mapped entity classes. I believe we can solve this using something like:

    /**
     * Invalidate all cached entities of the provided class. Since classes in
     * inheritance hierarchies share a cache the only additional inheritance
     * support is for classes which don't correspond to entities.
     * 
     * @see Cache#evict(Class)
     */
    public void evict(Class cls) {
        getEntityManagerFactory().verifyOpen();
        ClassDescriptor descriptor = getEntityManagerFactory().getSession().getClassDescriptor(cls);

        if (descriptor != null) {
            getEntityManagerFactory().getSession().getIdentityMapAccessor().invalidateClass(cls);
            return;
        }

        // Since no specific descriptor was found iterate over all descriptors
        // and initialize the cache of those types that can be assigned to the
        // provided class/interface
        Iterator descI = getEntityManagerFactory().getSession().getDescriptors().values().iterator();
        while (descI.hasNext()) {
            ClassDescriptor desc = (ClassDescriptor) descI.next();

            if (!desc.isChildDescriptor() && !desc.isAggregateDescriptor() && cls.isAssignableFrom(desc.getJavaClass())) {
                getEntityManagerFactory().getSession().getIdentityMapAccessor().invalidateClass(cls);
            }
        }
    }


I am attaching my impl that I believe will work but needs to be reviewed and verified.

Doug
Comment 16 Doug Clarke CLA 2009-04-06 22:21:08 EDT
Created attachment 131077 [details]
Proposed Solution
Comment 17 Doug Clarke CLA 2009-04-08 15:09:44 EDT
Changing priority to P@ since JPA 2.0 features are required for the 2.0 release
Comment 18 Gordon Yorke CLA 2009-10-30 13:45:15 EDT
This issue is complete as required for JPA 2.0 functionality. so it no longer blocks bug 24891 .
Comment 19 Michael OBrien CLA 2010-03-22 14:00:12 EDT
>starting investigation for updates to original SVN Rev# 2896 based on feedback by Doug C.
http://fisheye2.atlassian.com/changelog/~author=mmeswani/eclipselink/?cs=2896
>Does not block parent JPA 2.0 bug# 248291
Comment 20 Michael OBrien CLA 2010-03-22 17:19:04 EDT
The implementation was modified on the following dates as follows that will affect the refactor diff... 
20100201: Rev# 6463 - bug# 301063 : Refactor CacheImpl to implement the EclipseLink API interface JpaCache (which implements Cache from JPA 2.0 via the new functions - clear(), clear(Class), clearQueryCache(), clearQueryCache(queryName), timeToLive(Object), isValid(Object), isValid(Class, id), print(), print(Class), printLocks(), validate(), getObject(Class, id), getObject(Object), putObject(Object), removeObject(Class), removeObject(Class, id), containsObject(Object), evictObject(Object), getId(Object) 
http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/CacheImpl.java?r=6463

20100126: Rev# 6406 - bug# 298985 : Refactor Vector usage to Id or CacheId 
http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/CacheImpl.java?r=6406

20091124: Rev# 5875 - bug# 272895 : Check invalidation during contains() 
http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/CacheImpl.java?r=5875

20090513: Rev# 4170 - bug# 275953 : Bootstrap performance and compatibility
http://fisheye2.atlassian.com/browse/eclipselink/trunk/jpa/org.eclipse.persistence.jpa/src/org/eclipse/persistence/internal/jpa/CacheImpl.java?r=4170

>Analysis page discussion at
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/cache_api#Refactor_20100322
Comment 21 Michael OBrien CLA 2010-04-05 18:04:33 EDT
Created attachment 163846 [details]
248780 CacheImpl refactor for MappedSuperclass support (based on Doug's analysis)

>CacheImpl refactor based on Doug's analysis
http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/cache_api#Analysis
Comment 22 Michael OBrien CLA 2010-04-06 10:40:03 EDT
>The following bugs are for reference interest and are not blocking
Bug# 298985 , Bug# 308114, Bug# 272895, Bug# 275953, Bug# 301063
Comment 23 Michael OBrien CLA 2010-04-12 22:50:01 EDT
>see related bug# 308950
JPA2: Merge EntityManagerFactoryImpl.getIdentifier() as subset of CacheImpl.getId() functionality
Comment 24 Michael OBrien CLA 2010-04-13 09:58:09 EDT
Created attachment 164715 [details]
CacheImpl refactor for MappedSuperclass support including test suite modifications

License headers are reverted to original SUN
Comment 25 Michael OBrien CLA 2010-04-22 09:54:05 EDT
Created attachment 165763 [details]
CacheImpl refactor for MappedSuperclass support including test suite modifications 2
Comment 26 Michael OBrien CLA 2010-05-12 09:31:01 EDT
>The following model is used to to illustrate use case behavior when invalidating non-entity classes 
like MappedSuperclasses or plain java classes at the root or leaf level 
(extended functionality beyond the JPA specification) in an inheritance hierarchy.

Class1 (non-persistable java class)
  +---Entity2 (abstract entity)
        +--- MappedSuperclass3 (MappedSuperclass)
               +-----Entity4a (concrete entity)
                       +--- Class5 (non-persistable java class)
               +-----Entity4b (concrete entity)

Entity4a and Entity4b are in the cache to start.
>Here is the current behavior (all evict operations evict the entire tree)
- This is because getIdentityMap(Class5 or any other) will return the identityMap for the root entity (Entity2) in all cases - by design
evict(Class1)            --> evicts E4a and E4b
evict(Entity2)           --> evicts E4a and E4b
evict(MappedSuperclass3) --> evicts E4a and E4b
evict(Entity4a)          --> evicts E4a and E4b
evict(Class5)            --> evicts E4a and E4b
evict(Entity4b)          --> evicts E4a and E4b

>I propose that we introduce more granular eviction behavior by not always evicting the root
- but by evicting the subtree
evict(Class1)            --> evicts E4a and E4b
evict(Entity2)           --> evicts E4a and E4b
evict(MappedSuperclass3) --> evicts E4a and E4b
evict(Entity4a)          --> evicts E4a only
evict(Class5)            --> evicts E4a only
evict(Entity4b)          --> evicts E4b only

>Part of the change to enable this behavior is fixing the invalidateClass() function for cases where recurse=false
See bug# 312503
- we may add a 2nd flag [recurseSubTree) to make the invalidateClass(Class) function (tri/quad state)
recurse recurseSubtree behavior
-------------------------------
false   false          :invalidate only class parameter - existing equals functionality
false   true           :invalidate subtree from Class parameter - new isAssignableFrom functionality
true    false(x)       :invalidate entire tree from root
true    true(x)        :invalidate entire tree from root
Comment 27 Michael OBrien CLA 2010-06-02 14:22:09 EDT
Created attachment 170855 [details]
CacheImpl refactor for MappedSuperclass support including test suite modifications 3
Comment 28 Michael OBrien CLA 2010-06-02 22:36:03 EDT
Created attachment 170908 [details]
CacheImpl refactor for MappedSuperclass support including test suite modifications 3
Comment 30 Eclipse Webmaster CLA 2022-06-09 10:26:40 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink