ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Munat <b...@munat.com>
Subject Re: Dirty checking
Date Fri, 07 Oct 2005 00:46:44 GMT
Just have your DAO set the entity's dirty flag to false before handing back the created 
object.

My co-worker wrote a little DTO generator and it creates setter methods like this:

public void setFoo(Object foo)
{
     if(((this.foo != null) && !this.foo.equals(foo))
             || ((this.foo == null) && (foo != null))) {
         dirty = true;
         this.foo = foo;
     }
}

The base class for all DTOs also has a setDirty(boolean) method. So, the DAO creates the 
object, sets all the values, and then sets dirty to false. Then, after that, any call to a

setter that actually changes a non-null value sets the dirty flag.

There might be a better way out there, but that's what we've done on several projects and

it works ok.

b


Dan Bradley wrote:
> I'm interested in implementing a dirty-checking system. I know that
> iBATIS doesn't directly do that, but I'm wondering if anyone else has
> developed or thought of a successful approach.
> 
> It would be possible of course to add a dirty flag to an entity, then
> cause each mutator to set that flag to true. The problem, however, is
> that when iBATIS constructs an object (as I understand it) it calls
> the mutators. So any object freshly pulled from the database would be
> incorrectly marked as dirty.
> 
> If iBATIS guarantees the order it calls on setters based on the order
> they appear in the mapping, then it seems it would be possible to
> effectively add a setDirty(false) in the result map as the last result
> map property. But does iBATIS make this guarantee?
> 
> If not, another approach would be to use some sort of listener or hook
> into an event system so that after iBATIS loads an object, I could tie
> in some code that reset the dirty flag on the object. Does iBATIS have
> any such hooks?
> 
> Or is there yet another way to make dirty checking work on top of
> iBATIS? Thanks for any ideas.

Mime
View raw message