jsr338-experts@jpa-spec.java.net

[jsr338-experts] Re: Standardized Access to ChangeSet

From: Pinaki Poddar <ppoddar_at_us.ibm.com>
Date: Mon, 20 Jun 2011 11:33:22 -0700

Hi Gordon/Adam and all,

  I should have clarified
   a) the returned Sets be immutable. The elements of the set are live.
   b) returned set reflects the state of the member entities at the time
of invocation.
      Set<Object> deleted = em.getEntities(LifeCycleState.DELETED); // say
return a set with 2 entities
      em.remove(another); // another is not a member of deleted set
      assertFalse(deleted.contains(another));
      Set<Object> deleted2 = em.getEntities(LifeCycleState.DELETED);
      assertTrue(deleted.contains(another));

   c) Other possibility is to return an Iterator<> instead which is always
'live'.

   d) the methods return empty set if EntityManager is not in an active
transaction.

   Access to managed entities for any active persistence context is an
useful feature at any point of time.
   Why would you like to restrict only at flush() via callback?

   Regards --


Pinaki








From: Gordon Yorke <gordon.yorke_at_oracle.com>
To: jsr338-experts_at_jpa-spec.java.net
Date: 06/20/11 11:13 AM
Subject: [jsr338-experts] Re: Standardized Access to ChangeSet



Hello Adam,
    Would the "dirty" set include unsynchronized persisted and removed
Entities? It would likely be better to have separate sets for these.
Without configuration these sets would have to be cleared as the
EntityManager is cleared. What effect do you see EntityManager.clear()
having on these sets?
    As an alternative to the sets an EntityManager lifecycle listener
could be notified of the sets on EntityManager.flush() and the
application could track the same sets as need across flushes.

--Gordon


Adam Bien wrote:
> HI All,
>
> I would like to propose additional EntityManager methods:
>
> Set<Class> updated = EntityManager#getUpdatedEntities(Class<T>.class);
> Set<Class> deleted = EntityManager#getDeletedEntities(Class<T>.class);
> Set<Class> created = EntityManager#getCreatedEntities(Class<T>.class);
> Set<Class> dirty = EntityManager#getDirty(Class<T>.class);
>
> We had to use provider-specific EntityManager extensions to access the
dirty entities for the implementation of replication or historization.
>
> Such methods would be also useful for debugging purposes,
>
> thanks in advance,
>
> adam
>
>
>