Skip to main content

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

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


Back to the top