0

私たちのアプリケーションには、ストアド プロシージャで 1 つの Ref Cursor と 1 つのスカラー パラメータ、つまりステータス コードを返すという要件があります。

現在、Spring API、つまり StoredProcedure および RowMapper クラスを使用しています。

ストアド プロシージャを実行できますが、execute メソッド呼び出しの後、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;
    }

これを機能させる方法についてのアイデア。

4

1 に答える 1

0

したがって、これは少し変更するだけで機能します。Spring doc に従って、IN および OUT パラメータを Oracle DB の基になるストアド プロシージャで定義されている順序で渡す必要があります。しかし、上記のコードを見ると、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 のドキュメントには、 Map の使用法も示されていますが、これは正しくなく、順序付けられたデータ構造に変更する必要があります。

これで私の問題は解決しました。ハッピーコーディング。

于 2015-04-05T16:02:25.333 に答える