ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bangarum <bangaru...@yahoo.com>
Subject Re: RowHandler for multiple resultsets
Date Mon, 22 Sep 2008 13:44:02 GMT


Bangarum wrote:
> 
> Is there way that I can use RowHandler for multiple resultsets.?
> 
> Description of the problem:
> 
> my storedprocedure returns multiple resultset. I want to use RowHandler
> for those multiple resultset.
> 
> Please provide me some code examples to get understand if any.
> 
> Thanks
> Bangarum
> 
> 

Hi here is the solution that we tried, can it put into the latest release ?

We have MS-SQL store proc which returns mutiple result sets. The results
sets are big and it will not be a good idea to put them in ArraList. The
current iBatis version do not support multiple external RowHandler (external
means, provided by iBatis user). By defualt iBatis uses DefaultRowHandler to
process multiple resultsets, the current code which handles multiple
resultset is as below 

Class: com.ibatis.sqlmap.engine.execution.SqlExecutor 
in method private ResultSet handleMultipleResults(.... 

// Multiple ResultSet handling 
if (callback.getRowHandler() instanceof DefaultRowHandler) { 
MappedStatement statement = statementScope.getStatement(); 
DefaultRowHandler defaultRowHandler = ((DefaultRowHandler)
callback.getRowHandler()); 
if (statement.hasMultipleResultMaps()) { 
List multipleResults = new ArrayList(); 
multipleResults.add(defaultRowHandler.getList()); 
ResultMap[] resultMaps = statement.getAdditionalResultMaps(); 
int i = 0; 
while (moveToNextResultsSafely(statementScope, ps)) { 
if (i >= resultMaps.length) break; 
ResultMap rm = resultMaps[i]; 
statementScope.setResultMap(rm); 
rs = ps.getResultSet(); 
DefaultRowHandler rh = new DefaultRowHandler(); 
handleResults(statementScope, rs, skipResults, maxResults, new
RowHandlerCallback(rm, null, rh)); 
multipleResults.add(rh.getList()); 
i++; 
} 
defaultRowHandler.setList(multipleResults); 
statementScope.setResultMap(statement.getResultMap()); 
} else { 
while (moveToNextResultsSafely(statementScope, ps)) ; 
} 
} 
// End additional ResultSet handling 


The fix which was put to solve this was as below, please let me know your
suggestions. 

1. A new interface as below 

package com.ibatis.sqlmap.client.event; 

import com.ibatis.sqlmap.client.event.RowHandler; 
public interface MultiRowHandler extends RowHandler{ 
public MultiRowHandler getNextRowHandler(); 
} 

2. Changes to com.ibatis.sqlmap.engine.execution.SqlExecutor 

if (callback.getRowHandler() instanceof MultiRowHandler) { 
MappedStatement statement = statementScope.getStatement(); 
MultiRowHandler multipleRowHandler =
(MultiRowHandler)callback.getRowHandler(); 
if (statement.hasMultipleResultMaps()) { 
ResultMap[] resultMaps = statement.getAdditionalResultMaps(); 
int i = 0; 
while (moveToNextResultsSafely(statementScope, ps)) { 
if (i >= resultMaps.length) break; 
ResultMap rm = resultMaps[i]; 
statementScope.setResultMap(rm); 
rs = ps.getResultSet(); 
RowHandler rh = multipleRowHandler.getNextRowHandler(); 
RowHandlerCallback hdc = new RowHandlerCallback(rm, null, rh); 
handleResults(statementScope, rs, skipResults, maxResults,hdc ); 
multipleRowHandler = (MultiRowHandler)hdc.getRowHandler(); 
i++; 
} 
statementScope.setResultMap(statement.getResultMap()); 
} else { 

while (moveToNextResultsSafely(statementScope, ps)) ; 
} 
} 



-- 
View this message in context: http://www.nabble.com/RowHandler-for-multiple-resultsets-tp19060584p19608235.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Mime
View raw message