Example #1
0
 private void retrieveOutputParameters(
     StatementScope statementScope,
     CallableStatement cs,
     ParameterMapping[] mappings,
     Object[] parameters,
     RowHandlerCallback callback)
     throws SQLException {
   for (int i = 0; i < mappings.length; i++) {
     ParameterMapping mapping = ((ParameterMapping) mappings[i]);
     if (mapping.isOutputAllowed()) {
       if ("java.sql.ResultSet".equalsIgnoreCase(mapping.getJavaTypeName())) {
         ResultSet rs = (ResultSet) cs.getObject(i + 1);
         ResultMap resultMap;
         if (mapping.getResultMapName() == null) {
           resultMap = statementScope.getResultMap();
           handleOutputParameterResults(statementScope, resultMap, rs, callback);
         } else {
           SqlMapClientImpl client =
               (SqlMapClientImpl) statementScope.getSession().getSqlMapClient();
           resultMap = client.getDelegate().getResultMap(mapping.getResultMapName());
           DefaultRowHandler rowHandler = new DefaultRowHandler();
           RowHandlerCallback handlerCallback =
               new RowHandlerCallback(resultMap, null, rowHandler);
           handleOutputParameterResults(statementScope, resultMap, rs, handlerCallback);
           parameters[i] = rowHandler.getList();
         }
         rs.close();
       } else {
         parameters[i] = mapping.getTypeHandler().getResult(cs, i + 1);
       }
     }
   }
 }
Example #2
0
  private ResultSet handleMultipleResults(
      PreparedStatement ps,
      StatementScope statementScope,
      int skipResults,
      int maxResults,
      RowHandlerCallback callback)
      throws SQLException {
    ResultSet rs;
    rs = getFirstResultSet(statementScope, ps);
    if (rs != null) {
      handleResults(statementScope, rs, skipResults, maxResults, callback);
    }

    // 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
    return rs;
  }