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

This is Interesting: Free IT Magazines  
Home > Archive > Apache JDO Project > August 2007 > Re: 2.1 Spec: detached-dirty parameters to makePersistent() when DetachAllOnCommit=tru





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

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

2007-08-07, 7:11 pm


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



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com