Hello All,
I'm extending the Spring StoredProcedure class to invoke an oracle sproc which returns a REF cursor. I'm currently using a SqlOutParamer with a ParameterizedRowMapper to map the REF cursor row to my java objects. In addition to the row by row mapping, I need to include a "header" row in the results and I'd like to generate that row dynamically using the resultSet metadata. It seems that the RowMapper and ResultSetExtractor are stateless and wouldn't allow me break out of the row by row processing and the RowCallbackHandler is not threadsafe/reusable and so shouldn't be used when declaring Out params with the StoredProcedure class. I'm hoping to stay with the StoredProcedure approach but it seems like the RowCallBackHandler might be my only option which means I'd have to dump the StoredProcedure approach and use something like SimpleJDBCTemplate directly. Does anyone know of a way to include this header row in the results while still staying within the confines of using the StoredProcedure class?
Here's an example code snippet:
Any help would be greatly appreciated.
Thanks!
I'm extending the Spring StoredProcedure class to invoke an oracle sproc which returns a REF cursor. I'm currently using a SqlOutParamer with a ParameterizedRowMapper to map the REF cursor row to my java objects. In addition to the row by row mapping, I need to include a "header" row in the results and I'd like to generate that row dynamically using the resultSet metadata. It seems that the RowMapper and ResultSetExtractor are stateless and wouldn't allow me break out of the row by row processing and the RowCallbackHandler is not threadsafe/reusable and so shouldn't be used when declaring Out params with the StoredProcedure class. I'm hoping to stay with the StoredProcedure approach but it seems like the RowCallBackHandler might be my only option which means I'd have to dump the StoredProcedure approach and use something like SimpleJDBCTemplate directly. Does anyone know of a way to include this header row in the results while still staying within the confines of using the StoredProcedure class?
Here's an example code snippet:
Code:
public class MyProcedure extends StoredProcedure {
private static final String RESULT_CURSOR = "O_REF_CURSOR";
public MyProcedure(DataSource dataSource) {
super(dataSource, "SOME_PKG.SOME_SPROC");
// Input Param
declareParameter(new SqlParameter("p_param_1", Types.CHAR));
// Output Param (REF cursor)
// Currently using PRM, can't use RowCallBackHandler here due to thread safety.
declareParameter(new SqlOutParameter(RESULT_CURSOR, OracleTypes.CURSOR, new ParameterizedRowMapper<Row>() {
@Override
public Row mapRow(ResultSet rs, int rowNum) throws SQLException {
int columnCount = rs.getMetaData().getColumnCount();
List<String> values = new ArrayList<String>();
for (int i = 1; i <= columnCount; i++) {
values.add(rs.getString(i));
}
return new Row(values);
}
}));
compile();
}
public SomeResponseType execute(String param1 {
results = super.execute(param1);
List<Row> rows = (List<Row>) results.get(RESULT_CURSOR);
// Somehow I'd like the first row of the "rows" list to contain a header row built from the resultset column metadata
return new SomeResponseType(rows);
}
}
Thanks!