[ 
http://issues.apache.org/jira/browse/IBATIS-246?page=comments#action_12367082 ] 

Sven Boden commented on IBATIS-246:
-----------------------------------

As originally requested by Stephane Bailliez in IBATIS-161:

"Following my post in the dev list.

It would probably be interesting to have fine-grained control over the 
lazy-loading.
For instance, having a per-statement lazy-loading flag where dependent requests 
(like in the case of n+1 selects) would inherit this flag.

I came over it after discovering that cglib-enhanced classes are not 
serializable, which make sense due to lazy-loading.

You could need it for the following case:

You may know, that your relationships are not in the form 1:bazillion but more 
like 1:4 (replace 4 by your favorite 'less than 10' number) with very 
lightweights objects , thus the need to potentially be able to disable cglib 
enhanced relations.

To workaround this, you can:

1) disable application-wide lazy loading via <settings/> (big side-effect)
2) implements your own serialization mechanism by basically cloning the 
relations. (code clutter) 
"

> Lazy Load per Result
> --------------------
>
>          Key: IBATIS-246
>          URL: http://issues.apache.org/jira/browse/IBATIS-246
>      Project: iBatis for Java
>         Type: New Feature
>   Components: SQL Maps
>     Versions: 2.1.5, 2.1.6
>  Environment: Any
>     Reporter: S Boyd

>
> I have a need for LazyLoad on a per result basis.  Since I saw this feature 
> listed in the wish list for 2.1.5, I attempted to add it to this version's 
> source.  The lazy load global setting should be the default setting assigned 
> for all results in the sqlmaps.  If this is not desired for a particular 
> result, then it can be overrided by the lazyLoad="true|false" on the affected 
> result.  In adding this feature, I had to modify the sqlmap dtd and three 
> java classes:  SqlMapParser, BasicResultMap, and BasicResultMapping.
> In the SqlMapParser, I retrieved the lazy load property from the result 
> element at the beginning of the code block.  If the lazyLoad property is not 
> specified in the result, then the global setting is used.  This logic is 
> inserted on line 416.
> Lines: 407-414
> 407:        BasicResultMapping mapping = new BasicResultMapping();
> /* code omitted here */
> 414:        mapping.setNestedResultMapName(resultMapName);
>               
>               if(lazyLoad != null && lazyLoad.length() > 0){
>                       mapping.setLazyLoad("true".equals(lazyLoad));
>               }
>               else{ // use global lazy load setting
>                       
> mapping.setLazyLoad(vars.client.getDelegate().isLazyLoadingEnabled());
>               }
> In the BasicResultMap, I temporarily override the global lazy load setting 
> with the BasicResultMapping's lazyload value. The reason for this was to 
> avoid changing the ResultLoader.loadResult signature.  Maybe this can be 
> improved upon.
> Line 442 was modifed to this:
>                /* Set global lazy load setting to mapping's lazy load */
>               boolean globalLazyLoad = client.isLazyLoadingEnabled();
>               
> client.getDelegate().setLazyLoadingEnabled(mapping.isLazyLoad());
>       
>               result = ResultLoader.loadResult(client, statementName, 
> parameterObject, targetType);
>       
>               /* Reset global lazy load to original value */
>               client.getDelegate().setLazyLoadingEnabled(globalLazyLoad);
> In the BasicResultMapping, I simply added a new property (lazyLoad:boolean) 
> with set/getters.
> Please let me know if this can be reviewed/refined and possibly added to the 
> next release.  Or if you want the modifed java files and dtd.
> Regards,
> Stephen

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to