Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Invalidating session cache programmatically?

Hi Laird,

Assuming you cannot get the correct EntityManagerFactory for an evictAll call, there are a couple of things you can to.

1. Take a look at our JpaHelper class. It provides a number of methods that can unwrap the various JPA constructs. For the shared cache, you will want to get a hold of the ServerSession. It has a method called getIdentityMapAccessor() that has cache manipulation API.

2. SessionManager will hold a list of all the top level sessions. You should be able to call getSessions() on it and then use the same API described above.

-Tom

On 30/11/2011 2:25 PM, Laird Nelson wrote:
In an integration test framework of ours that makes use of embedded Glassfish
and its bundled EclipseLink JPA provider, I am looking to empty the L2 cache in
between tests.  Our test fixtures typically consist of stateless EJBs with
injected persistence contexts (EntityManagers).

I want the JPA L2 cache to be active and normal during each test, so setting it
to isolated, while an option, doesn't really match with what I want to do.

Because the test framework is (partially) under my control, what I've got so far
is a lightweight EJB that I deploy alongside the test fixture that attempts to
grab an EntityManagerFactory's associated Cache.  If I can do that, then I can
call evictAll() and I think that will do the trick.

Of course there might be several persistence contexts in the test fixture, and I
don't know what they are, and--even if I knew what they were--I can't
programmatically look them up.  So my attempts so far to grab the *right*
EntityManagerFactory have failed.  This doesn't surprise me.

Consequently I think I have to start digging into some EclipseLink native APIs.

Here's my question: If I can get my hands on a Session, does that roughly
correspond (or exactly!) to a persistence context?  Is there any way of reaching
the L2 cache from a Session object such that I could evict all objects from it?

One way I saw to get ahold of ALL sessions (which seems to me would be VERY nice
for this (odd) use case) is calling SessionManager.getManager().getSessions()
(which returns a Map of...well, presumably either its keys or values are
Sessions; the Javadocs don't say).

Any pointers gratefully appreciated; I'm using
http://www.eclipse.org/eclipselink/api/2.3/index.html as my EclipseLink reference.

Best,
Laird

--
http://about.me/lairdnelson



_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top