// TODO Improve this and check PK cols
return null;
}
int[] fieldNumbers = stmtMapping.getMemberNumbers();
StatementClassMapping mappingDefinition;
int[] mappedFieldNumbers;
if (acmd instanceof InterfaceMetaData)
{
// Persistent-interface : create new mapping definition for a result type of the implementation
mappingDefinition = new StatementClassMapping();
mappingDefinition.setNucleusTypeColumnName(stmtMapping.getNucleusTypeColumnName());
mappedFieldNumbers = new int[fieldNumbers.length];
for (int i = 0; i < fieldNumbers.length; i++)
{
AbstractMemberMetaData mmd = acmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumbers[i]);
mappedFieldNumbers[i] = cmd.getAbsolutePositionOfMember(mmd.getName());
mappingDefinition.addMappingForMember(mappedFieldNumbers[i],
stmtMapping.getMappingForMemberPosition(fieldNumbers[i]));
}
}
else
{
// Persistent class
mappingDefinition = stmtMapping;
mappedFieldNumbers = fieldNumbers;
}
// Extract any surrogate version
VersionMetaData vermd = cmd.getVersionMetaDataForClass();
Object surrogateVersion = null;
StatementMappingIndex versionMapping = null;
if (vermd != null)
{
if (vermd.getFieldName() == null)
{
versionMapping = stmtMapping.getMappingForMemberPosition(StatementClassMapping.MEMBER_VERSION);
}
else
{
AbstractMemberMetaData vermmd = cmd.getMetaDataForMember(vermd.getFieldName());
versionMapping = stmtMapping.getMappingForMemberPosition(vermmd.getAbsoluteFieldNumber());
}
}
if (versionMapping != null)
{
// Surrogate version column returned by query
JavaTypeMapping mapping = versionMapping.getMapping();
surrogateVersion = mapping.getObject(ec, rs, versionMapping.getColumnPositions());
}
// Extract the object from the ResultSet
Object obj = null;
boolean needToSetVersion = false;
if (persistentClass.isInterface() && !cmd.isImplementationOfPersistentDefinition())
{
// Querying by interface, and not a generated implementation so use the metadata for the interface
cmd = ec.getMetaDataManager().getMetaDataForInterface(persistentClass, clr);
}
if (cmd.getIdentityType() == IdentityType.APPLICATION)
{
// Check if the PK field(s) are all null (implies null object, when using OUTER JOIN)
int[] pkNumbers = cmd.getPKMemberPositions();
ResultSet resultSet = (ResultSet)rs;
boolean nullObject = true;
for (int i=0;i<pkNumbers.length;i++)
{
StatementMappingIndex pkIdx = mappingDefinition.getMappingForMemberPosition(pkNumbers[i]);
if (pkIdx == null)
{
throw new NucleusException("You have just executed an SQL statement yet the information " +
"for the primary key column(s) is not available! " +
"Please generate a testcase and report this issue");