2015-04-03 75 views
0

在我們的應用程序中,存儲過程中返回1個參考遊標和1個標量參數(即狀態代碼)的要求。返回參考遊標和標量值的存儲過程

現在我正在使用Spring API,即StoredProcedure和RowMapper類。

我能夠執行存儲過程,但執行方法調用後,Spring不調用我的RowMapper方法MapRow。

下面是我的代碼

DriverManagerDataSource ds = getDataSource(); 

     Map<String, Integer> inputValues = new HashMap<String, Integer>(); 
     inputValues.put("P_CLIENT_ID", java.sql.Types.VARCHAR); 
     inputValues.put("P_REQ_TYP", java.sql.Types.VARCHAR); 

     Map<String, RowMapper> outputMappers = new HashMap<String, RowMapper>(); 
     outputMappers.put("p_recordset", new SessionMgmtMapper()); 

     Map<String, Integer> outputValues = new HashMap<String, Integer>(); 
     outputValues.put("P_STATUS_CD", java.sql.Types.VARCHAR); 

     Map<String, Object> valueMap = new HashMap<String, Object>(); 
     valueMap.put("P_CLIENT_ID", "0c1cab610a4445929932c09efe10225a"); 
     valueMap.put("P_REQ_TYP", "Authorization"); 

MultiMapperIOStoredProc multiMapperIOStoredProc = new MultiMapperIOStoredProc(ds, "GET_CLIENT_RS1", inputValues, outputValues, outputMappers); 

multiMapperIOStoredProc.executeStoredProc(valueMap); 

和我MultiMapperIOStoredProc構造。

public MultiMapperIOStoredProc(final DataSource dataSource, final String storedProc, 
      final Map<String, Integer> inputValues, final Map<String, Integer> outputValues, 
      final Map<String, RowMapper> outputMappers) { 
     super(dataSource, storedProc); 

     if (null != inputValues && inputValues.size() > 0) { 
      for (final String key : inputValues.keySet()) { 
       this.declareParameter(new SqlParameter(key, inputValues.get(key))); 
      } 
     } 
    // Pass multiple Mappers 
     if (null != outputMappers && outputMappers.size() > 0) { 
      for (final String key : outputMappers.keySet()) { 
       this.declareParameter(new SqlOutParameter(key, OracleTypes.CURSOR, outputMappers.get(key))); 
      } 
     } 

     if (null != outputValues && outputValues.size() > 0) { 
      for (final String key : outputValues.keySet()) { 
       this.declareParameter(new SqlOutParameter(key, outputValues.get(key))); 
      } 
     } 

     this.compile(); 
    } 

我executeStoredProc方法

public <T> List<T> executeStoredProc(final Map<String, Object> valueMap) { 

     LOG.debug("executing stored procedure " + this.getSql() + " with values: " + valueMap); 

     // execute stored procedure 
     final Map<String, Object> resultMap = this.execute(valueMap); 
     return null; 
    } 

任何想法如何使這項工作。

+0

任何幫助表示讚賞。 – 2015-04-03 18:46:30

回答

0

所以這個工作稍作改動。根據Spring文檔,我們必須按照它們在Oracle DB中底層存儲過程中定義的順序傳遞IN和OUT參數。但是,如果您查看上面的代碼,我使用Map的HashMap實現來設置我的IN和OUT根據Java Doc不提供任何訂貨保證的參數。

我將所有的Map實現從HashMap改爲LinkedHashMap,如下所示。

// For IN params. 
LinkedHashMap<String, Integer> inputValues = new LinkedHashMap<String, Integer>(); 

// for output values 
Map<String, RowMapper> outputMappers = new LinkedHashMap<String, RowMapper>(); 

// For OUT params. 
LinkedHashMap<String, Integer> outputValues = new LinkedHashMap<String, Integer>(); 

Spring文檔也顯示了使用地圖的這是不正確的,需要更改爲任意有序的數據結構。

這解決了我的問題。快樂的編碼。