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.6, 2.1.5    
 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