[ 
https://issues.apache.org/jira/browse/JDO-548?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12545581
 ] 

Craig Russell commented on JDO-548:
-----------------------------------

After looking at the details of the specification, I'd like to amend the 
proposed interface to return a Set as well as to change the way the ObjectState 
is passed. 

The reason to return a Set is that there cannot be duplicates, and the 
semantics of Set do this well. 

The reason to return a Set<T> is for ease of use in case the classes contain a 
common superclass. This is 

The reason to take EnumSet as a parameter is that it is trivial to have the 
user do it and there is no trivial way for the implementation. Since the states 
parameter needs to efficiently filter results, it's most effective to use 
states.contains(candidate). 

Here's the proposed text for the specification (focus for now on the Java 5 
version):

Set getManagedObjects();
Set getManagedObjects(EnumSet<ObjectState> states);
<T> Set<T> getManagedObjects(Class<T>... classes);
<T> Set<T>Set getManagedObjects(EnumSet<ObjectState> states, Class<T>... 
classes);

These methods return a set of managed instances that pass the criteria of 
states and classes. Managed instances for a specific instance of 
PersistenceManager are defined as those that return the PersistenceManager 
instance in response to JDOHelper.getPersistenceManager(). Instances are 
returned in the set that are both in one of the life cycle states identified in 
the EnumSet, and are assignable to any one or more of the Class instances in 
the classes parameter, including abstract classes and interfaces whether 
persistence-capable or not. 

For example, this returns all managed instances of type Employee, 
FullTimeEmployee, and PartTimeEmployee that are persistent new but not deleted:
Set<Employee> newEmployees = 
pm.getManagedObjects(EnumSet.of(ObjectState.PERSISTENT_NEW), Employee.class);

The Set returned might be lazily instantiated by the implementation. Operations 
performed after the getManagedObjects call that affect the set of instances 
managed by a PersistenceManager might affect the iteration of the result of the 
method call. For example, the effect of evict, makePersistent, or commit might 
or might not be reflected in the iteration of the result. As long as an 
Iterator on the result returns true to hasNext(), the result might change. To 
guarantee stability of the result, the result can be iterated until 
Iterator.hasNext() returns false.

This method can be used at any time, including during life cycle callbacks, 
life cycle event notifications, and Synchronization callbacks. A new set of 
managed instances is returned for each method call.


> PM.getManagedObjects() : access to the objects enlisted in a transaction
> ------------------------------------------------------------------------
>
>                 Key: JDO-548
>                 URL: https://issues.apache.org/jira/browse/JDO-548
>             Project: JDO
>          Issue Type: New Feature
>          Components: api2, api2-legacy, specification
>            Reporter: Andy Jefferson
>             Fix For: JDO 2 maintenance release 1
>
>         Attachments: api2-legacy.managedobjects.patch, 
> api2.managedobjects.patch
>
>
> It would be desirable to provide access to the objects enlisted in the 
> transaction of a PersistenceManager. It is proposed that this be via the 
> following methods on javax.jdo.PersistenceManager.
> api2
> Collection getManagedObjects(); // Return all enlisted objects
> Collection getManagedObjects(ObjectState ... states); // Return enlisted 
> objects in the specified states
> api2-legacy
> Collection getManagedObjects(); // Return all enlisted objects
> The return type could just as easily be Object[].

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to