Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 79957 invoked from network); 22 Sep 2008 13:44:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Sep 2008 13:44:36 -0000 Received: (qmail 5428 invoked by uid 500); 22 Sep 2008 13:44:30 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 5411 invoked by uid 500); 22 Sep 2008 13:44:30 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 5400 invoked by uid 99); 22 Sep 2008 13:44:30 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Sep 2008 06:44:30 -0700 X-ASF-Spam-Status: No, hits=4.0 required=10.0 tests=DNS_FROM_OPENWHOIS,FORGED_YAHOO_RCVD,SPF_HELO_PASS,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Sep 2008 13:43:29 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1Khlhq-0000kV-Ab for user-java@ibatis.apache.org; Mon, 22 Sep 2008 06:44:02 -0700 Message-ID: <19608235.post@talk.nabble.com> Date: Mon, 22 Sep 2008 06:44:02 -0700 (PDT) From: Bangarum To: user-java@ibatis.apache.org Subject: Re: RowHandler for multiple resultsets In-Reply-To: <19060584.post@talk.nabble.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: bangaru_99@yahoo.com References: <19060584.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org 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.