db-jdo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig Russell (JIRA)" <j...@apache.org>
Subject [jira] Commented: (JDO-282) Add convenience methods to get persistent instance and detached instance from InstanceLifecycleEvent
Date Sun, 22 Jan 2006 05:25:42 GMT
    [ http://issues.apache.org/jira/browse/JDO-282?page=comments#action_12363558 ] 

Craig Russell commented on JDO-282:
-----------------------------------

I'd prefer to avoid the isPreCallback argumment entirely. I think if we add a line to the
specification that the target is only allowed on the postAttach and postDetach events, then
the existence of the target tells you what you need to know. So the code doesn't need the
argument, but can simply return either the source or target depending on whether target is
null.

For example,

+    public Object getDetachedInstance() {
boolean isPreCallback = (target == null);
+        switch (getEventType()) {
+            case DETACH:
+                return isPreCallback
+                        ? null          // preDetach:  no detached instance yet
+                        : getSource();  // postDetach:  source is detached instance
+            case ATTACH:
+                return isPreCallback
+                        ? getSource()   // preAttach:  source is detached instance
+                        : target  // postAttach:  target is detached instance
+        }
+
+        // for all other events, there is no detached instance
+        return null;
+    }


> Add convenience methods to get persistent instance and detached instance from InstanceLifecycleEvent
> ----------------------------------------------------------------------------------------------------
>
>          Key: JDO-282
>          URL: http://issues.apache.org/jira/browse/JDO-282
>      Project: JDO
>         Type: Improvement
>   Components: api20
>     Reporter: Matthew T. Adams
>     Assignee: Matthew T. Adams
>  Attachments: InstanceLifecycleEvent.patch
>
> The source and target object differ as to whether they are the persistent or detached
instance in class InstanceLifecycleEvent depending upon whether the event object is given
in the preDetach, postDetach, preAttach, or postAttach callbacks.  I propose adding two convenience
methods that makes it obvious from the API which object the user is getting.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Mime
View raw message