compileQueryFull(parameterValues, acmd);
if (result != null)
{
// Check existence of invalid selections in the result
StatementResultMapping resultMapping = datastoreCompilation.getResultDefinition();
for (int i=0;i<resultMapping.getNumberOfResultExpressions();i++)
{
Object stmtMap = resultMapping.getMappingForResultExpression(i);
if (stmtMap instanceof StatementMappingIndex)
{
StatementMappingIndex idx = (StatementMappingIndex)stmtMap;
AbstractMemberMetaData mmd = idx.getMapping().getMemberMetaData();
if (mmd != null)
{
if ((mmd.hasCollection() || mmd.hasMap() || mmd.hasArray()) &&
idx.getMapping() instanceof AbstractContainerMapping)
{
throw new NucleusUserException(LOCALISER.msg("021213"));
}
}
}
}
if (resultClass != null)
{
// Check validity of resultClass for the result (PrivilegedAction since uses reflection)
AccessController.doPrivileged(new PrivilegedAction()
{
public Object run()
{
// Check that this class has the necessary constructor/setters/fields to be used
StatementResultMapping resultMapping = datastoreCompilation.getResultDefinition();
if (QueryUtils.resultClassIsSimple(resultClass.getName()))
{
if (resultMapping.getNumberOfResultExpressions() > 1)
{
// Invalid number of result expressions
throw new NucleusUserException(LOCALISER.msg("021201", resultClass.getName()));
}
Object stmtMap = resultMapping.getMappingForResultExpression(0);
if (stmtMap instanceof StatementMappingIndex)
{
StatementMappingIndex idx = (StatementMappingIndex)stmtMap;
Class exprType = idx.getMapping().getJavaType();
boolean typeConsistent = false;
if (exprType == resultClass)
{
typeConsistent = true;
}
else if (exprType.isPrimitive())
{
Class resultClassPrimitive = ClassUtils.getPrimitiveTypeForType(resultClass);
if (resultClassPrimitive == exprType)
{
typeConsistent = true;
}
}
if (!typeConsistent)
{
// Inconsistent expression type not matching the result class type
throw new NucleusUserException(LOCALISER.msg("021202", resultClass.getName(), exprType));
}
}
else
{
// TODO Handle StatementClassMapping
// TODO Handle StatementNewObjectMapping
throw new NucleusUserException("Don't support result clause of " +
result + " with resultClass of " + resultClass.getName());
}
}
else if (QueryUtils.resultClassIsUserType(resultClass.getName()))
{
// Check for valid constructor (either using param types, or using default ctr)
Class[] ctrTypes = new Class[resultMapping.getNumberOfResultExpressions()];
for (int i=0;i<ctrTypes.length;i++)
{
Object stmtMap = resultMapping.getMappingForResultExpression(i);
if (stmtMap instanceof StatementMappingIndex)
{
ctrTypes[i] = ((StatementMappingIndex)stmtMap).getMapping().getJavaType();
}
else if (stmtMap instanceof StatementNewObjectMapping)
{
// TODO Handle this
}
}
Constructor ctr = ClassUtils.getConstructorWithArguments(resultClass, ctrTypes);
if (ctr == null && !ClassUtils.hasDefaultConstructor(resultClass))
{
// No valid constructor found!
throw new NucleusUserException(LOCALISER.msg("021205", resultClass.getName()));
}
else if (ctr == null)
{
// We are using default constructor, so check the types of the result expressions for means of input
for (int i=0;i<resultMapping.getNumberOfResultExpressions();i++)
{
Object stmtMap = resultMapping.getMappingForResultExpression(i);
if (stmtMap instanceof StatementMappingIndex)
{
StatementMappingIndex mapIdx = (StatementMappingIndex)stmtMap;
AbstractMemberMetaData mmd = mapIdx.getMapping().getMemberMetaData();
String fieldName = mapIdx.getColumnAlias();