}
continue;
}
if (namedParameters && param.getParameterType() != SPParameter.RETURN_VALUE) {
if (inputExpressions.put(param.getName().toUpperCase(), param.getExpression()) != null) {
throw new QueryResolverException(QueryPlugin.Util.getString("ExecResolver.duplicate_named_params", param.getName().toUpperCase())); //$NON-NLS-1$
}
} else {
inputExpressions.put(param.getIndex() + adjustIndex, param.getExpression());
}
}
storedProcedureCommand.clearParameters();
int origInputs = inputExpressions.size();
/*
* Take the values set from the stored procedure implementation, and match up with the
* types of parameter it is from the metadata and then reset the newly joined parameters
* into the stored procedure command. If it is a result set get those columns and place
* them into the stored procedure command as well.
*/
List<SPParameter> metadataParams = storedProcedureInfo.getParameters();
List<SPParameter> clonedMetadataParams = new ArrayList<SPParameter>(metadataParams.size());
int inputParams = 0;
int outParams = 0;
boolean hasReturnValue = false;
for (SPParameter metadataParameter : metadataParams) {
if( (metadataParameter.getParameterType()==ParameterInfo.IN) ||
(metadataParameter.getParameterType()==ParameterInfo.INOUT)){
inputParams++;
} else if (metadataParameter.getParameterType() == ParameterInfo.OUT) {
outParams++;
} else if (metadataParameter.getParameterType() == ParameterInfo.RETURN_VALUE) {
hasReturnValue = true;
}
SPParameter clonedParam = (SPParameter)metadataParameter.clone();
clonedMetadataParams.add(clonedParam);
storedProcedureCommand.setParameter(clonedParam);
}
if (storedProcedureCommand.isCalledWithReturn() && !hasReturnValue) {
throw new QueryResolverException(QueryPlugin.Util.getString("ExecResolver.return_expected", storedProcedureCommand.getGroup())); //$NON-NLS-1$
}
if(!namedParameters && (inputParams > inputExpressions.size())) {
throw new QueryResolverException("ERR.015.008.0007", QueryPlugin.Util.getString("ERR.015.008.0007", inputParams, origInputs, storedProcedureCommand.getGroup())); //$NON-NLS-1$ //$NON-NLS-2$
}
// Walk through the resolved parameters and set the expressions from the
// input parameters
int exprIndex = 1;
HashSet<String> expected = new HashSet<String>();
if (storedProcedureCommand.isCalledWithReturn() && hasReturnValue) {
for (SPParameter param : clonedMetadataParams) {
if (param.getParameterType() == SPParameter.RETURN_VALUE) {
Expression expr = inputExpressions.remove(exprIndex++);
param.setExpression(expr);
}
}
}
for (SPParameter param : clonedMetadataParams) {
if(param.getParameterType() == SPParameter.RESULT_SET || param.getParameterType() == SPParameter.RETURN_VALUE) {
continue;
}
if (namedParameters) {
String nameKey = param.getParameterSymbol().getShortCanonicalName();
Expression expr = inputExpressions.remove(nameKey);
// With named parameters, have to check on optional params and default values
if (expr == null && param.getParameterType() != ParameterInfo.OUT) {
expr = ResolverUtil.getDefault(param.getParameterSymbol(), metadata);
param.setUsingDefault(true);
expected.add(nameKey);
}
param.setExpression(expr);
} else {
if(param.getParameterType() == SPParameter.OUT) {
continue;
}
Expression expr = inputExpressions.remove(exprIndex++);
param.setExpression(expr);
}
}
// Check for leftovers, i.e. params entered by user w/ wrong/unknown names
if (!inputExpressions.isEmpty()) {
if (namedParameters) {
throw new QueryResolverException(QueryPlugin.Util.getString("ExecResolver.invalid_named_params", inputExpressions.keySet(), expected)); //$NON-NLS-1$
}
throw new QueryResolverException("ERR.015.008.0007", QueryPlugin.Util.getString("ERR.015.008.0007", inputParams, origInputs, storedProcedureCommand.getGroup().toString())); //$NON-NLS-1$ //$NON-NLS-2$
}
// Create temporary metadata that defines a group based on either the stored proc
// name or the stored query name - this will be used later during planning
String procName = storedProcedureCommand.getProcedureName();