}
final MDXCompiler compiler = new MDXCompiler(parameters, locale);
final String mdxQuery = compiler.translateAndLookup(rawMdxQuery, parameters);
// Alternatively, JNDI is possible. Maybe even more ..
final Query query = connection.parseQuery(mdxQuery);
if (queryTimeoutValue > 0)
{
query.setQueryTimeoutMillis(queryTimeoutValue * 1000);
}
final Parameter[] parameterDefs = query.getParameters();
for (int i = 0; i < parameterDefs.length; i++)
{
final Parameter def = parameterDefs[i];
Object parameterValue = parameters.get(def.getName());
final Object processedParamValue;
final Type parameterType = def.getType();
// Mondrian doesn't handle null MemberType/SetType parameters well (http://jira.pentaho.com/browse/MONDRIAN-745)
// If parameterValue is null, give it the default value
try
{
if (parameterValue == null && (parameterType instanceof MemberType || parameterType instanceof SetType))
{
parameterValue = def.getDefaultExp().toString();
}
}
catch (Exception e)
{
// Ignore - this is a safety procedure anyway
}
if (parameterValue != null)
{
if (parameterType instanceof StringType)
{
if (!(parameterValue instanceof String))
{
throw new ReportDataFactoryException(parameterValue + " is incorrect for type " + parameterType);
}
processedParamValue = parameterValue;
}
else if (parameterType instanceof NumericType)
{
if (!(parameterValue instanceof Number))
{
throw new ReportDataFactoryException(parameterValue + " is incorrect for type " + parameterType);
}
processedParamValue = parameterValue;
}
else if (parameterType instanceof MemberType)
{
final MemberType memberType = (MemberType) parameterType;
final Hierarchy hierarchy = memberType.getHierarchy();
if (parameterValue instanceof String)
{
final Member member = findMember(query, hierarchy, query.getCube(), String.valueOf(parameterValue));
if (member != null)
{
processedParamValue = new MemberExpr(member);
}
else
{
processedParamValue = null;
}
}
else
{
if (!(parameterValue instanceof OlapElement))
{
throw new ReportDataFactoryException(parameterValue + " is incorrect for type " + parameterType);
}
else
{
processedParamValue = parameterValue;
}
}
}
else if (parameterType instanceof SetType)
{
final SetType setType = (SetType) parameterType;
final Hierarchy hierarchy = setType.getHierarchy();
if (parameterValue instanceof String)
{
final String rawString = (String) parameterValue;
final String[] memberStr = rawString.replaceFirst("^ *\\{", "").replaceFirst("} *$", "").split(",");
final List<Member> list = new ArrayList<Member>(memberStr.length);
for (int j = 0; j < memberStr.length; j++)
{
final String str = memberStr[j];
final Member member = findMember(query, hierarchy, query.getCube(), String.valueOf(str));
if (member != null)
{
list.add(member);
}
}