}
catch (SQLException sqe)
{
String msg = LOCALISER.msg("021043", sqe.getMessage());
NucleusLogger.QUERY.error(msg);
throw new NucleusUserException(msg);
}
}
// If the user requires Object[] then just give them what we have
if (resultClass == Object[].class)
{
return fieldValues;
}
if (QueryUtils.resultClassIsSimple(resultClass.getName()))
{
// User wants a single field
if (fieldValues.length == 1 && (fieldValues[0] == null || resultClass.isAssignableFrom(fieldValues[0].getClass())))
{
// Simple object is the correct type so just give them the field
return fieldValues[0];
}
else if (fieldValues.length == 1 && !resultClass.isAssignableFrom(fieldValues[0].getClass()))
{
// Simple object is not assignable to the ResultClass so throw an error
String msg = LOCALISER.msg("021202",
resultClass.getName(), fieldValues[0].getClass().getName());
NucleusLogger.QUERY.error(msg);
throw new NucleusUserException(msg);
}
}
else
{
// User requires creation of one of his own type of objects, or a Map
// A. Find a constructor with the correct constructor arguments
Object obj = QueryUtils.createResultObjectUsingArgumentedConstructor(resultClass, fieldValues,
resultFieldTypes);
if (obj != null)
{
return obj;
}
else if (NucleusLogger.QUERY.isDebugEnabled())
{
// Give debug message that no constructor was found with the right args
Class[] ctr_arg_types = new Class[resultFieldNames.length];
for (int i=0;i<resultFieldNames.length;i++)
{
if (fieldValues[i] != null)
{
ctr_arg_types[i] = fieldValues[i].getClass();
}
else
{
ctr_arg_types[i] = null;
}
}
NucleusLogger.QUERY.debug(LOCALISER.msg("021206",
resultClass.getName(), StringUtils.objectArrayToString(ctr_arg_types)));
}
// B. No argumented constructor exists so create an object and update fields using fields/put method/set method
obj = QueryUtils.createResultObjectUsingDefaultConstructorAndSetters(resultClass, resultFieldNames,
resultClassFieldsByName, fieldValues);
return obj;
}
// Impossible to satisfy the resultClass requirements so throw exception
String msg = LOCALISER.msg("021203",resultClass.getName());
NucleusLogger.QUERY.error(msg);
throw new NucleusUserException(msg);
}