Re: 2.1 Spec: detached-dirty parameters to makePersistent() when DetachAllOnCommit=tru
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Apache Server configuration support > Apache JDO Project > Re: 2.1 Spec: detached-dirty parameters to makePersistent() when DetachAllOnCommit=tru




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Re: 2.1 Spec: detached-dirty parameters to makePersistent() when DetachAllOnCommit=tru  
cbeams


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
08-08-07 12:11 AM


On Aug 7, 2007, at 11:35 AM, Andy Jefferson wrote:

> You could allow something of this form by imposing a restriction
> that if an
> object needs attaching, and that "AttachOnPersist" flag is set, and
> the PM
> already has a persistent object with that id then throw a
> JDOUserException.
> Clearly the primary use-case is where the user detaches a single
> object, and
> then wants to attach the same thing, so they typically never hit the
> duplicate detached object issue.

You're right about the primary use case.  With this restriction in
place, however, would I be able to do the following?

import static javax.jdo.JDOHelper.*;

assert pm.getAttachOnPersist() == true;
assert pm.getDetachAllOnCommit() == true;

// fetch a detched object
Query q = pm.newQuery(Foo.class);
q.setUnique(true);
Foo foo = (Foo) q.execute();

// my foo object is now detached-clean
assert isDetached(foo) && !isDirty(foo);

// make it dirty:
foo.setBar("bar");

// attach
pm.currentTransaction().begin();
pm.makePersistent(foo);
pm.currentTransaction().commit();

// should be transitioned back to detached-clean
assert isDetached(foo) && !isDirty(foo);

// dirty it once more
foo.addBaz("baz");

// and attach it a second time - wouldn't this cause the
JDOUserException you mention above?  The pm is already managing (by
ID, I assume) this object, so how would it know the difference
between the application 'detaching and attaching two separate
instances of the same object' and simply 'attaching twice the same
instance of an object'?  Hopefully I'm missing something, because I
like the proposed solution.
pm.currentTransaction().begin();
pm.makePersistent(foo);
pm.currentTransaction().commit();

// again, should now be detached-clean
assert isDetached(foo) && !isDirty(foo);

- Chris








[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:07 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register