4 Replies Latest reply: May 10, 2013 8:14 AM by Jonathan Hult RSS

    Result set in service handlers

    Chely
      I am having a query, which is being executed in the loop, All i need is all the loop query results in a single resut set.
      my code is as below. but it is not working somehow.

      plz let me know where m missing...
       result = new DataResultSet();
                     
                     for (String key : keys) {
                          String library = (String) libMap.get(key);
                           queryString = "select count(distinct(ddocname)) as docCount from revisions where dsecuritygroup = '"
                                    + library
                                    + "' and dindate between '"
                                    + fromDate
                                    + "' AND " + "'" + toDate + "'";
                          
                 
                                ResultSet temp=  ws.createResultSetSQL(queryString);
                                 
      
                                                                                    result.merge(null, temp, false);
                                                                                   SystemUtils.info("result.toString()"+result.toString());
                              
                    
                            
                      }
                     
                     
           
                                                m_binder.addResultSet(resultSetName, result);
      Thanks
        • 1. Re: Result set in service handlers
          Jiri.Machotka-Oracle
          See the answer in this thread: http://tech.groups.yahoo.com/group/intradoc_users/message/23256
          • 2. Re: Result set in service handlers
            Jonathan Hult
            More information about why you need to create a copy of the ResultSet (into a DataResultSet), can be found here: http://jonathanhult.com/blog/2012/11/resultset-versus-dataresultset/

            Jonathan
            http://jonathanhult.com
            • 3. Re: Result set in service handlers
              Chely
              Modified the code and now m copying the result..but when i go outside the loop, the result will contain only the latest result and not holding all the values...


              result = new DataResultSet();
                             
                             for (String key : keys) {
                                  String library = (String) libMap.get(key);
                                   queryString = "select count(distinct(ddocname)) as docCount from revisions where dsecuritygroup = '"
                                            + library
                                            + "' and dindate between '"
                                            + fromDate
                                            + "' AND " + "'" + toDate + "'";
                                  
                         
                                        ResultSet temp=  ws.createResultSetSQL(queryString);
                                         
               
                                                                                            result.copy(temp);
                                                                                                              
                            
                                    
                              }
                             
                             
                   
                                                        m_binder.addResultSet(resultSetName, result);
              Edited by: Chely on May 10, 2013 12:41 AM
              • 4. Re: Result set in service handlers
                Jonathan Hult
                result.copy(temp) is replacing all the current values in the DataResultSet.

                Instead, try the following:
                result = new DataResultSet();
                
                for (String key : keys) {
                     String library = (String) libMap.get(key);
                     queryString = "select count(distinct(ddocname)) as docCount from revisions where dsecuritygroup = '"
                               + library
                               + "' and dindate between '"
                               + fromDate
                               + "' AND " + "'" + toDate + "'";
                     
                
                     ResultSet temp = ws.createResultSetSQL(queryString);
                      
                     DataResultSet tempDRS = new DataResultSet();
                     
                     tempDRS.copy(temp);
                     
                     for (tempDRS.first(); tempDRS.isRowPresent(); tempDRS.next()) {
                          result.addRowWithList(tempDRS.getCurrentRowAsList());
                     } 
                }
                
                m_binder.addResultSet(resultSetName, result);
                Jonathan
                http://jonathanhult.com