@Override
public void initializeCall(XRServiceAdapter xrService, QueryOperation queryOperation,
DatabaseQuery databaseQuery) {
StoredProcedureCall spCall = createCall();
if (getName() != null) {
spCall.setProcedureName(getName());
} else {
spCall.setProcedureName(queryOperation.getName());
}
QName resultType = queryOperation.getResultType();
if ((getInOutArguments().size() + getOutArguments().size()) > 1 &&
!queryOperation.isSimpleXMLFormat()) {
throw DBWSException.multipleOutputArgumentsOnlySupportedForSimpleXML();
}
// find IN and INOUT parameters
for (Parameter p : queryOperation.getParameters()) {
ProcedureArgument arg = findInOutArgument(p.getName());
// default argument name to parameter name
String argName = p.getName();
// override with explicit argument name
if (arg != null) {
argName = arg.getName();
}
if (arg != null && arg instanceof ProcedureOutputArgument) {
if (isCursorType(xrService, p.getType())) {
throw DBWSException.inoutCursorArgumentsNotSupported();
}
spCall.addNamedInOutputArgument(argName, p.getName());
} else {
spCall.addNamedArgument(argName, p.getName());
}
}
// find OUT parameters
if (queryOperation.hasResponse()) {
if (!queryOperation.isSimpleXMLFormat() ||
(spCall.isStoredFunctionCall() && !isCursorType(xrService, resultType))) {
setSingleResult(xrService, spCall, resultType);
}
else {
if (spCall.isStoredFunctionCall() && isCursorType(xrService, resultType)) {
spCall.useUnnamedCursorOutputAsResultSet();
}
else if (getOutArguments().isEmpty()) {
spCall.useUnnamedCursorOutputAsResultSet();
}
else {
for (ProcedureOutputArgument arg : getOutArguments()) {
// use argument type
if (arg.getResultType() != null && isCursorType(xrService, arg.getResultType())) {
spCall.useNamedCursorOutputAsResultSet(arg.getName());
} else {
spCall.addNamedOutputArgument(arg.getName());
}
}
}
}
}