Re: dirty deeds done dirt cheap

Sebastien Bigaret <[email protected]> 25 Mar 2004 01:03:00 +0100
Newsgroups gmane.comp.python.modeling
Message-ID <[email protected]>

Marcos Dione <[email protected]> wrote:
> 
> On Wed, Mar 24, 2004 at 05:19:41PM -0300, Marcos Dione wrote:
> >     flipping the docs I see that EditingContext is capable of tell
> > wether it's dirty or not. but I think it would be better if I could ask
> > the Entity if it's dirty or not; and, being dirty, ask it to ignore any
> > changes not saved (which I think will resort to reload from the db)... 
> 
>     I note two things: first, asking an Entity if it's dirty or not is
> impossible w/o an EC, so is unreasonable to ask for it.

Absolutely, the standard way is to ask the ec for that --even if some of
the CustomObject's methods can be relative to the editingContext(), such
as globalID().

> second, the
> answer seems to be to use nested EC's, but if I do it that way, for
> reseting I would need to discard the dirty EC, take a new one and
> repopulate it with the original values (most probably this two EC's will
> be child of one master EC at different times).
> 
>     what's not clear for me is how to repopulate the second EC.

Repopulating the EC simply consists in fetching the objects, or asking
for a particular object given its globalID (ec.faultForGlobalID()), etc.

Now you may need a simpler way of doing this, esp. if you're dealing
with one object or a few: the nested ECs are very handy when the
modifications of the graph of objects can be very intensive and you do
not want to track which changes occured. But if you know exactly which
object(s) is/are impacted (which is probably the case in any simple
form), you may just ask for forgetting about the changes --what you were
asking for in your 1st post.

I've just submitted patch #922822 with an up-to-date version of one I
posted a year ago (almost: 26 Mar 2003 :/ )
https://sourceforge.net/tracker/index.php?func=detail&aid=922822&group_id=58935&atid=489337

The comments there contain references of the messages talking about
this feature.

  It also contains a test case for that. The idea is that you simply
call ec.refaultObject(obj), and the object is reverted back to a fault,
ready to be retrieved from the database next time one of its
properties' value is needed.

  It's not been extensively tested, and should be used w/ care for the
  moment being; see comments for patch #922822. As noted there, it's
  been asked regularly, but even then I've never heard that it has been
  really tested. Handle w/ care ;) but hopefully it will be of some
  help, and maybe we could finally make it and finally integrate this
  into the main trunk some day. So I'll be happy to hear from you if you
  find some time to experiment!

-- Sébastien.




-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click