简体   繁体   中英

Call stored procedure using Spring SimpleJdbcCall with callback

I have an Oracle Stored procedure that takes CLOB input and REFCURSOR output. I invoke the SP via Spring SimpleJdbcCall passing in a RowMapper to map the results.

However, since the result set is large, I need to provide callback feature to the client. I can't quite figure out how to add callback for an SP call using Spring - both with and without SimpleJdbcCall.

One thought I have is to pass-in a RowCallbackHandler. Will this work or is there a better way to solve this problem? Any help here is appreciated.

    private Map<String, Object> arguments = ...;
    SimpleJdbcCall jdbcCall = new SimpleJdbcCall(this.jdbcTemplate)
            .withCatalogName(this.packageName)
            .withProcedureName(this.storedProcName)
            .withoutProcedureColumnMetaDataAccess()
            .declareParameters(this.outputParameters.toArray(new SqlOutParameter[]{}));

    if(!isEmpty(inputParameters)) {
        jdbcCall.declareParameters(inputParameters.toArray(new SqlParameter[]{}));
    }

    this.outputParameters.add(new SqlOutParameter(outputParamName, VARCHAR, rowMapper));

    jdbcCall.execute(arguments);

Actually the RowCallbackHandler is a good solution for your case:

 this.outputParameters.add(new SqlOutParameter(outputParamName, VARCHAR, new RowCallbackHandler() {
  public void processRow(ResultSet rs) throws SQLException { 
      // Build model object from ROW and invoke client service from here
  }
}));

 jdbcCall.execute(arguments);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM