I am successfully using BatchSqlUpdate implementation for doing batch stored procedure (Oracle Function) calls. The call is successful and I get the results updated on the back-end.
The only problem is how to successfully parse the return and OUT argument values. The following way is how I have implemented this,
public class MyClass extends BatchSqlUpdate {
private final Map<String, Object> inParameters;
List<Map<String, Object>> batchedOutArguments;
....
public EntityWriterStoredProcedureBatchUpdate(StoredProcedureAttributes spAttributes, int batchSizeRequired)
throws SQLException {
super (spAttributes.getDataSource(), spAttributes.getCallStatement());
declareParameters();
setBatchSize(batchSizeRequired);
compile();
.....
private void declareParameters() {
for (StoredProcedureParameter spParameter : this.spAttributes.getStoredProcedureParameters()) {
switch (spParameter.getArgumentType()) {
case IN:
declareParameter(new SqlParameter(spParameter.getParameterName(), spParameter.getSqlType()));
break;
case OUT:
declareParameter(new SqlOutParameter(spParameter.getParameterName(), spParameter.getSqlType()));
break;
case IN_OUT:
declareParameter(new SqlInOutParameter(spParameter.getParameterName(), spParameter.getSqlType()));
break;
}
}
LOGGER.debug("Declared parameters for [{}]", STORED_PROC_NAME);
}
.....
public int execute(EntityWriterState writerState) throws StoredProcedureException {
int rtnVal = 0;
for (StoredProcedureParameter spParameter : this.spAttributes.getStoredProcedureParameters()) {
switch (spParameter.getArgumentType()) {
case IN:
case IN_OUT: break;
case OUT:
Object outParam = null;
inParameters.put(spParameter.getParameterName(), outParam);
break;
}
}
try {
super.updateByNamedParam(inParameters);
batchedOutArguments.add(inParameters);
} catch (Exception ex) {
throw new StoredProcedureException(ex);
}
Each set of parameters (for making one procedure call) including the OUT parameter references is kept in batchedOutArguments.
But no luck in getting any thing for the OUT type variables, On Oracle side my procedure looks like,
create or replace FUNCTION "MY_FUNC" (
p_error_message OUT NOCOPY VARCHAR2,
p_module_context_name OUT NOCOPY VARCHAR2,
p_sql_error OUT NOCOPY VARCHAR2,
p_host_id IN VARCHAR2,
p_code IN VARCHAR2,
p_value_type IN VARCHAR2,
p_value IN NUMBER)
RETURN NUMBER
AS
....
Any ways to get the OUT variables extracted?
Aucun commentaire:
Enregistrer un commentaire