I think this is an excellent idea.
I'd be happy to remove the copy semantic on transient instances in order
to eliminate the need for a separate method. My feeling is that
transient instances are likely to be retained as references, and it's
actually less confusing if those references become persistent-new.
Wes
Matthew T. Adams wrote:
I like the convergence in the api, and I also like the suggestion to return
the root object(s) from makePersistent, as it increases symmetry.
Could attachCopy and makePersistent become one, just makePersistent? The
only difference in the proposal as you suggest, Craig, is the handling of
transient instances. attachCopy copies instances and makes the copies
persistent-new, whereas makePersistent just makes them persistent-new; all
other behavior is the same. If we got rid of attachCopy, in favor of
makePersistent, and changed makePersistent such that it returns the root
object(s) given, then the behavior is covered, except for attachCopy's copy
semantic for transient instances. The only difference in the API if we keep
attachCopy is the copy semantic for transient instances, which I don't think
is all that important.
Thoughts?
--matthew
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Sunday, October 16, 2005 12:26 PM
To: JDO Expert Group; [email protected]
Subject: Re: RETRY: Transient instance referencing a detached
instance? (was: Question about attachCopy, transient &
detached instances)
Javadogs,
I've reviewed this material and agree with the general conclusion,
that we can add the ability to include detached objects in the
closure of instances for both makePersistent and attachCopy.
The spec as of today requires treating these three types of objects
in the closure differently:
persistent instances
attachCopy throws an exception; makePersistent ignores them
transient instances
attachCopy copies them and creates persistent-new instances;
makePersistent makes them persistent-new
detached instances
attachCopy copies them; makePersistent throws an exception
Here's the change as I would propose it:
persistent instances
attachCopy ignores them; makePersistent ignores them
transient instances
attachCopy copies them and creates persistent-new instances;
makePersistent makes them persistent-new
detached instances
attachCopy copies them; makePersistent copies them
If we make this change, the behavior of makePersistent and attachCopy
are more similar than today. The differences are in the treatment of
transient instances and whether or not the root objects are returned.
If we like, we can have makePersistent also return the root objects
by making a source-compatible change to the signatures of
makePersistent.
Craig
On Oct 5, 2005, at 11:59 AM, Matthew T. Adams wrote:
"Wes Biggs" <[EMAIL PROTECTED]> wrote in message
news:<[EMAIL PROTECTED]>...
Would it be cleaner to not allow transient instances to be
included in
attachCopy() graphs at all? Sounds that way to me.
No, I'd like to continue to allow transient instances to be
included in
attachCopy graphs. I'd like to **add** the ability for detached
objects to
be included in makePersistent graphs.
This use case fell out very naturally for me while working on a
website that
uses detached objects. I ended up with a transient User object
referencing
a detached Country object, and, of course, when I called
pm.makePersistent(user), I got an JDOUserException as I should
have, per the
spec as it stands right now.
--matthew