2016-08-25 34 views
1

我想从我的存储过程调用返回的blob流。我正在尝试使用弹簧AbstractLobStreamingResultSetExtractor来完成此操作。从存储过程调用流blob数据

public OutputStream getDocument(final Document doc, final OutputStream outStream) { 

    SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(rdcJdbcTemplate) 
    .withProcedureName(PROC_NAME) 
    .withCatalogName(CATALOG_NAME) 
    .withSchemaName(SCHEMA_NAME).declareParameters(new SqlParameter(DOC_ID_PARAM, OracleTypes.VARCHAR), 
      new SqlOutParameter(OUT_PARAM, OracleTypes.BLOB , new AbstractLobStreamingResultSetExtractor<Object>(){ 

       @Override 
       protected void streamData(ResultSet rs) throws SQLException, 
         IOException, DataAccessException { 

        InputStream blobStream = lobHandler.getBlobAsBinaryStream(rs, 1);    
        if (blobStream != null){      
         FileCopyUtils.copy(blobStream, outStream); 
        }  
       } 
      })); 

    SqlParameterSource in = new MapSqlParameterSource().addValue(DOC_ID_PARAM, doc.getId()); 

    Map<String,Object> out = simpleJdbcCall.execute(in); 
    return outStream; 
} 

当我调试这个streamdata代码永远不会被调用。

任何想法,我可能会实现这个?

回答

0

只是为了未来的读者我已经找到了解决这一

public OutputStream getGlasDocument(final Document doc, final OutputStream outStream) {    

    SimpleJdbcCall simpleJdbcCall = new SimpleJdbcCall(rdcJdbcTemplate) 
    .withProcedureName(PROC_NAME) 
    .withCatalogName(CATALOG_NAME) 
    .withSchemaName(SCHEMA_NAME).declareParameters(new SqlParameter(DOC_ID_PARAM, OracleTypes.VARCHAR), 
      new SqlOutParameter(OUT_PARAM, OracleTypes.BLOB, null, new SqlReturnType() { 

       @Override 
       public Object getTypeValue(CallableStatement cs, int paramIndex, 
         int sqlType, String typeName) throws SQLException { 
        try { 
         Blob blob = cs.getBlob(1); 
         if (blob != null){ 
          FileCopyUtils.copy(cs.getBlob(1).getBinaryStream(), outStream); 
         }       
        } catch (IOException e) {       
         logger.debug(e.getMessage()); 
        } 
        return null; 
       } 
      })); 

    SqlParameterSource in = new MapSqlParameterSource().addValue(DOC_ID_PARAM, doc.getId());   
    simpleJdbcCall.execute(in); 
    return outStream; 
}