Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] how to handle data used by multiple applications

In our RCP thick clients we face the same problem. Here's an excerpt
from my blog post
(http://www.weheartcode.com/2008/08/27/eclipselink-in-j2se-rcp-applications/)
on the subject:


Caching in a Thick Client

Traditionally one of the major benefits you get when using an ORM
library and with EclipseLink especially is the ability to have a
shared in memory cache. The benefits in a server side web application
are immense, when we're dealing with a client side thick application.
Caching just gets in our way in most cases. The reason for this is
obvious: In a web application EntityManagers across users sessions can
all easily share the same cache, since they all reside on the same
server (usually).

However in a thick client each user is an island. When I make an
update to the database, I update my very own Shared Cache, however
Mary who is sitting 2 cubes over still has her own cache that's
oblivious to my changes. It's imperative that she receive fresh data
all the time!

Fresh data from a find call
Calling find on the EntityManager is the easiest way to get a handle
on an Entity. However, you're not gauranteed to hit the database on
this call. After our find we just need to call refresh to refresh the
Entity from the database. I created a method called findFresh that I
put in my Base Model class, here's how it looks:
public <T> T findFresh(Class<T> entityClass, Object primaryKey) {
        T result =  getEntityManager().find(entityClass, primaryKey);
        if(result == null)
            return null;

        getEntityManager().refresh(result);
        return result;
    }

In EntityManager Setup
You can turn off the Shared Cache EntityManager wide, to stop regular
JPQL queries from hitting the shared cache, this is called putting
your EntityManager in "Isolated Mode", just set it in the properties
map you pass to the createEntityManagerFactory method.

I just set the property like this:
properties.put(PersistenceUnitProperties.CACHE_SHARED_DEFAULT, "false");

Fresh results from Queries
Just to be sure when I execute any Query - Native or otherwise I set
the Query Hint to not use the cache, I created a little helper method
I through in a util class like this:
public static void setNoCacheHints(Query q)
    {
        q.setHint(QueryHints.REFRESH, HintValues.TRUE);
    }

When dealing with NamedQueries you can use the @CacheHint annotation
to set the hint.


./tch



On Thu, Sep 4, 2008 at 7:04 AM, Yannick Majoros
<yannick.majoros@xxxxxxxxxxxx> wrote:
> (alsp posted on toplink forums)
>
> Hello,
>
> Many of our applications share the same data model. What should we use to
> make sure that, when we access some data, it is really up-to-date?
>
> We used to work with a shared server session between multiple applications.
> It doesn't seem to be an easy thing on j2ee 5, nor did I see this anywhere
> in official toplink or eclipselink docs.
>
> We could use cache coordination... but it seems that it is designed for use
> within a single application with multiple persistence units (as I found in
> the docs, see "when to use cache coordination").
>
> Cache invalidation doesn't look sufficient to me (I could be wrong).
>
> So, what is the recommanded way of solving this?
>
> We are working for a university. Our applications manage students,
> curriculum, grades... Many times, different applications share some common
> data (e.g.: a course, student records, ...).
>
> --
> Yannick Majoros
>
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>


Back to the top