}
callStringBuffer.append(")}");
String callString = callStringBuffer.toString();
OracleCallableStatement cstmt =
(OracleCallableStatement) con.prepareCall(callString.toString());
DOMPrinter domPrinter = new DOMPrinter();
// Iterate through list of Param nodes.
for (int paramIndex = 0; paramIndex < paramCount; paramIndex++) {
// Get the node from the node list
Node paramNode = paramNodeList.item(paramIndex);
// The index position of the "?" parameter in the callable statement
// is 2 more than the index position of the Param element in the
// Java list we are traversing. The callable statement parameters
// use 1-based indexing, unlike the 0-based indexing used in the
// Java list, and the first callable statement parameter is
// an output parameter reserved for a return value.
int callableStatementParamIndex = paramIndex + 2;
setCallableStatementParameterValue(cstmt,
callableStatementParamIndex,
procedureNameValue,
paramNode,
xmlParseUtils,
domPrinter,
id,
strDescriptor);
} // End of loop through Param elements
// Register the output parameter as cursor.
cstmt.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
// Call the stored procedure to insert the data.
try {
cstmt.executeUpdate();
// If the Procedure node had the IdColumnName attribute set,
// retrieve the ID value using the column name.
Console.displayDev("ID column name: ", idColumnName, true, "scb");
if (idColumnName != null || writeData) {
ResultSet rs = null;
try {
// Get the return value
rs = cstmt.getCursor(1);
/*
ResultSetMetaData md = rs.getMetaData();
for (int k = 1; k < md.getColumnCount() + 1; k++) {
Console.displayDev("Column names", md.getColumnName(k) +
" of type " + md.getColumnType(k), false, "scb");
} */
// Get id value as integer.
while (rs.next()) {
if (writeData) {
this.dataWriter.append(rs);
}
if (idColumnName != null) {
id = rs.getInt(idColumnName);
SQLWarning stmtWarning = cstmt.getWarnings();
SQLWarning rsWarning = rs.getWarnings();
if (stmtWarning != null || rsWarning != null) {
StringBuffer warningBuffer = new StringBuffer(100);
warningBuffer.append("WARNING:");
while (stmtWarning != null) {
warningBuffer.append(" Stmt Message: " + stmtWarning.getMessage() );
warningBuffer.append(" Stmt SQLState: " + stmtWarning.getSQLState() );
warningBuffer.append(" Stmt ErrorCode: " + stmtWarning.getErrorCode() );
stmtWarning = stmtWarning.getNextWarning();
}
while (rsWarning != null) {
warningBuffer.append(" Rs Message: " + rsWarning.getMessage() );
warningBuffer.append(" Rs SQLState: " + rsWarning.getSQLState() );
warningBuffer.append(" Rs ErrorCode: " + rsWarning.getErrorCode() );
rsWarning = rsWarning.getNextWarning();
}
super.msgEntry.setAppContext("callStoredProcedure()");
super.msgEntry.setDocInfo(currentFilename);
super.msgEntry.setMessageText("Warning calling stored procedure " +
procedureNameValue +
" from OracleDbUtils.callStoredProcedure().");
super.msgEntry.setError( new String(warningBuffer) );
logger.logWarning(super.msgEntry);
}
} // end if idColumnName != null
} // end while next record is available
} // end try to get cursor
finally {
try {
if (writeData) {
this.dataWriter.write(this.currentFilename, procedureNameValue);
}
if (rs != null) {
rs.close();
}
}
catch (SQLException sqle) {
super.msgEntry.setAppContext("callStoredProcedure()");
super.msgEntry.setDocInfo(currentFilename);
super.msgEntry.setMessageText("Unable to close result set.");
StringBuffer buffer = new StringBuffer(100);
// Multiple exceptions may be chained together. Get all information.
while (sqle != null) {
buffer.append( "Message: " + sqle.getMessage() );
buffer.append( " SQLState: " + sqle.getSQLState() );
buffer.append( " ErrorCode: " + sqle.getErrorCode() );
sqle = sqle.getNextException();
}
super.msgEntry.setError( new String(buffer) );
logger.logWarning(super.msgEntry);
}
}
} // end if idColumnName != null || writeData
else {
SQLWarning stmtWarning = cstmt.getWarnings();
if (stmtWarning != null) {
StringBuffer warningBuffer = new StringBuffer(100);
warningBuffer.append("WARNING:");
while (stmtWarning != null) {
warningBuffer.append(" Stmt Message: " + stmtWarning.getMessage() );
warningBuffer.append(" Stmt SQLState: " + stmtWarning.getSQLState() );
warningBuffer.append(" Stmt ErrorCode: " + stmtWarning.getErrorCode() );
stmtWarning = stmtWarning.getNextWarning();
}
super.msgEntry.setAppContext("callStoredProcedure()");
super.msgEntry.setDocInfo(currentFilename);
super.msgEntry.setMessageText("Warning calling stored procedure " +
procedureNameValue +
" from OracleDbUtils.callStoredProcedure().");
super.msgEntry.setError( new String(warningBuffer) );
logger.logWarning(super.msgEntry);
}
} // end if idColumnName == null && !writeData
}
catch (SQLException sqle) {
boolean moveToBad;
StringBuffer buffer = new StringBuffer(100);
// Decide whether file should be moved to bad location.
// If so, throw exception up to DBStoreProcessor for execution.
if (moveToBadLocUponFailure != null &&
moveToBadLocUponFailure.equals(DBXmlConfig.YES)) {
moveToBad = true;
}
else {
moveToBad = false;
}
if (moveToBad) {
buffer.append("Error calling stored procedure ");
buffer.append(procedureNameValue);
buffer.append(" in OracleDbUtils.callStoredProcedure processing file ");
buffer.append(currentFilename);
buffer.append(":");
// Multiple exceptions may be chained together. Get all information.
while (sqle != null) {
buffer.append( " Message: " + sqle.getMessage() );
buffer.append( " SQLState: " + sqle.getSQLState() );
buffer.append( " ErrorCode: " + sqle.getErrorCode() );
sqle = sqle.getNextException();
}
throw new DbStoredProcedureException( new String(buffer) );
}
super.msgEntry.setAppContext("callStoredProcedure()");
super.msgEntry.setDocInfo(currentFilename);
super.msgEntry.setMessageText("Error calling stored procedure " +
procedureNameValue +
" from OracleDbUtils.callStoredProcedure().");
// Multiple exceptions may be chained together. Get all information.
while (sqle != null) {
buffer.append( "Message: " + sqle.getMessage() );
buffer.append( " SQLState: " + sqle.getSQLState() );
buffer.append( " ErrorCode: " + sqle.getErrorCode() );
sqle = sqle.getNextException();
}
super.msgEntry.setError( new String(buffer) );
logger.logWarning(super.msgEntry);
continue;
}
finally {
try {
if (cstmt != null) {
cstmt.close();
}
}
catch (SQLException sqle) {
super.msgEntry.setAppContext("callStoredProcedure()");
super.msgEntry.setDocInfo(currentFilename);