users@glassfish.java.net

Re: reset entity cache but...

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Thu, 13 Mar 2008 08:31:30 +0100

I had same problem as you. Later I had to add some JDBC data
manipulation (JPA really SUCKS when it comes to batch inserts/updates)
and now I use it not only to invalidate cache when we change something
in DB directly, but some of my DAOs do have to invalidate is as well.
Part of my UtilityServiceBean is below. I must admit I am not sure why
 have I to put my primary key into Vector for #invalidateObject to
work. What, on Earth, anyone is using Vector at all?

If you (I mean anyone who does read it) find something wrong here I
would be glad to hear suggestions :)
-------------------------
    public void invalidateCache(Class<?> entityClass, Collection<?> ids) {
        Vector<Object> vector = new Vector<Object>(1);
        vector.add(null);
        IdentityMapAccessor identityMapAccessor = getIdentityMapAccessor();
        for (Object id : ids) {
            vector.set(0, id);
            identityMapAccessor.invalidateObject(vector, entityClass);
        }
    }

    public void invalidateCache(Class<?> entityClass) {
        IdentityMapAccessor identityMapAccessor = getIdentityMapAccessor();
        identityMapAccessor.invalidateClass(entityClass);
    }

    public void invalidateCache() {
        IdentityMapAccessor identityMapAccessor = getIdentityMapAccessor();
        identityMapAccessor.invalidateAll();
    }

    private IdentityMapAccessor getIdentityMapAccessor() {
        oracle.toplink.essentials.ejb.cmp3.EntityManager toplinkEm =
                (oracle.toplink.essentials.ejb.cmp3.EntityManager)
em.getDelegate();
        return toplinkEm.getServerSession().getIdentityMapAccessor();
    }
-------------------------

Witold Szczerba


2008/3/12, glassfish_at_javadesktop.org <glassfish_at_javadesktop.org>:
> I have a java Enterprise application on Glassfish + Toplink.
> I use servlet and ejb (sessionbean and entity bean).
>
> I need rarely to change database value outside the container and I want to reflect the changes immediately on the container.
>
> I know about toplink.refresh hint but since I need to make database change rarely I don't want to opt out cache performance.
>
> Exist a solution to make refresh only when I want it?
> (for example by calling a session bean method thru a servlet when I update the db outside the container..)
> [Message sent by forum member 'peppeme' (peppeme)]
>
> http://forums.java.net/jive/thread.jspa?messageID=263607
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>