{
throw new JPOXException("Class "+objectClass.getName()+" is abstract, and a non abstract was expected.").setFatal();
}
// Form the query to find which one of these classes has the instance with this id
DiscriminatorIteratorStatement discrimStmt = new DiscriminatorIteratorStatement(clr, new Class[] {primaryClass}, true, storeMgr, true);
// Check all instances of this table to see if we have all possible candidates in our "options" list
DatastoreClass primaryTable = storeMgr.getDatastoreClass(primaryClass.getName(), clr);
StoreData[] storeData = storeMgr.getStoreDataForDatastoreContainerObject(primaryTable.getIdentifier());
boolean haveAllCandidates = true;
for (int i=0;i<storeData.length;i++)
{
if (storeData[i] instanceof MappedStoreData)
{
ClassTable tbl = (ClassTable)((MappedStoreData)storeData[i]).getDatastoreContainerObject();
String[] managedClasses = tbl.getManagedClasses();
for (int j=0;j<managedClasses.length;j++)
{
boolean managedClassFound = false;
Iterator optionsIter = schemaDataOptions.iterator();
while (optionsIter.hasNext())
{
StoreData optionData = (StoreData)optionsIter.next();
if (optionData.getName().equals(managedClasses[j]))
{
managedClassFound = true;
break;
}
}
if (!managedClassFound)
{
haveAllCandidates = false;
break;
}
}
if (!haveAllCandidates)
{
break;
}
}
}
if (haveAllCandidates)
{
// We have all possible candidates that are stored in this table so we can omit the restriction on the discriminator
discrimStmt.setRestrictDiscriminator(false); // Just retrieve the discriminator for this id (accept any possible disc values)
}
// Create the statement
QueryExpression stmt = discrimStmt.getQueryStatement(null);
// WHERE (object id) = ?
// We have to create a StateManager here just to map fields from the AppId key object to the table fields.
// Really the table should have some way of doing this. TODO : Refactor this
StateManager sm = StateManagerFactory.newStateManagerForHollow(om, objectClass, id);