ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Perry Nguyen <pfngu...@hanhuy.com>
Subject Re: ResultMap, N+1
Date Tue, 17 Jan 2006 17:38:32 GMT
Gareth Moorst wrote:
> I know EXACTLY what you mean.
> I'd prefer not to allow anything to have direct access to any of the 
> Lists inside my data objects, but iBatis has so many other good features 
> that it was worth changing my data objects slightly.
> 
> I always use a public interface for my data objects so that I can 
> restrict access to methods like setSublist(List list), and then add 
> extra methods like setThings(Thing[] things) where I copy the array into 
> the List. This way, the only part of the system that knows about and 
> uses the setList(List list) method is iBatis.
> 
> It can add a fair bit more unnecessary crap to what should be very 
> simple objects though.

I follow a similar approach, except my base domain objects remain 
"pure", instead I create /custom/ subclasses for ibatis.

e.g.

Product {
     Attribute[] getAttributes()
     void setAttributes(Attribute[])
}

IbatisProduct extends Product {
     List getAttributeList()
     void setAttributeList(List) // sets dirty flag
     Attribute[] getAttributes() {
         if (dirty && getAttributeList() != null) {
             setAttributes((Attribute[])
                     getAttributeList().toArray(new Attribute[0]));
         }
         return super.getAttributes();
     }
}

Everyone uses Product, but the sqlmap uses IbatisProduct.

Mime
View raw message