* @return The Result Object factory
*/
public ResultObjectFactory newResultObjectFactory(StateManager sm, QueryExpression stmt, boolean ignoreCache, boolean useFetchPlan)
{
MappedStoreManager storeMgr = (MappedStoreManager)sm.getObjectManager().getStoreManager();
ClassLoaderResolver clr = sm.getObjectManager().getClassLoaderResolver();
if (valuesAreEmbedded || valuesAreSerialised)
{
// Value = Embedded, Serialised
// valueTable is null here so why return this ?
return new PersistentIDROF(this.valueTable, null, vmd, null, null, null, ignoreCache, false,
stmt.hasMetaDataExpression(), null, clr.classForName(valueType));
}
else
{
// Value = PC
// Select any datastore/version columns
int[] datastoreIndex = null;
int[] versionIndex = null;
if (stmt.getTableExpression(elmIdentifier) != null)
{
if (valueTable.getIdentityType() == IdentityType.DATASTORE)
{
datastoreIndex = stmt.select(elmIdentifier, valueTable.getDataStoreObjectIdMapping(),true);
}
if (valueTable.getVersionMapping(true) != null)
{
versionIndex = stmt.select(elmIdentifier, valueTable.getVersionMapping(true), true);
}
}
else
{
if (valueTable.getIdentityType() == IdentityType.DATASTORE)
{
datastoreIndex = stmt.select(stmt.getMainTableAlias(),
valueTable.getDataStoreObjectIdMapping(),true);
}
if (valueTable.getVersionMapping(true) != null)
{
versionIndex = stmt.select(stmt.getMainTableAlias(),
valueTable.getVersionMapping(true), true);
}
}
StatementExpressionIndex[] statementExpressionIndex = null;
int[] prefetchFieldNumbers = null;
if (useFetchPlan)
{
// Select the FetchPlan fields
FetchPlan fp = sm.getObjectManager().getFetchPlan();
fp.manageFetchPlanForClass(vmd);
FetchPlanForClass fpc = fp.getFetchPlanForClass(vmd);
int fieldNumbers[] = fpc.getFieldsInActualFetchPlan();
int fn[] = new int[fieldNumbers.length];
int prefetchFieldCount = 0;
int fieldCount = vmd.getNoOfInheritedManagedMembers() + vmd.getNoOfManagedMembers();
statementExpressionIndex = new StatementExpressionIndex[fieldCount];
for (int i=0; i<fieldNumbers.length; ++i)
{
JavaTypeMapping m = valueTable.getFieldMapping(vmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumbers[i]));
if (m != null)
{
if (m.includeInFetchStatement() && !(m instanceof AbstractContainerMapping))
{
statementExpressionIndex[fieldNumbers[i]] = new StatementExpressionIndex();
statementExpressionIndex[fieldNumbers[i]].setMapping(m);
fn[prefetchFieldCount++] = fieldNumbers[i];
}
}
}
prefetchFieldNumbers = new int[prefetchFieldCount];
System.arraycopy(fn, 0, prefetchFieldNumbers, 0, prefetchFieldCount);
}
else
{
AbstractClassMetaData cmd = vmd;
if (cmd.getIdentityType() == IdentityType.APPLICATION)
{
prefetchFieldNumbers = new int[cmd.getPKMemberPositions().length];
int fieldCount = cmd.getNoOfInheritedManagedMembers() + cmd.getNoOfManagedMembers();
statementExpressionIndex = new StatementExpressionIndex[fieldCount];
for (int i = 0; i < prefetchFieldNumbers.length; ++i)
{
prefetchFieldNumbers[i] = cmd.getPKMemberPositions()[i];
JavaTypeMapping m = valueTable.getFieldMapping(cmd.getMetaDataForManagedMemberAtAbsolutePosition(prefetchFieldNumbers[i]));
if (m != null) // field is not stored in the table, e.g List, Set, etc or is transactional
{
if (m.includeInFetchStatement() && !(m instanceof AbstractContainerMapping))
{
statementExpressionIndex[prefetchFieldNumbers[i]] = new StatementExpressionIndex();
statementExpressionIndex[prefetchFieldNumbers[i]].setMapping(m);
}
}
}
}
}
if (stmt.getTableExpression(elmIdentifier) != null)
{
Mappings.selectMapping(stmt, elmIdentifier, statementExpressionIndex);
}
else
{
Mappings.selectMapping(stmt, statementExpressionIndex);
}
return new PersistentIDROF(storeMgr.getDatastoreClass(getValueType(), clr),
prefetchFieldNumbers, vmd, statementExpressionIndex, datastoreIndex, versionIndex,
ignoreCache, iterateUsingDiscriminator, stmt.hasMetaDataExpression(), null, clr.classForName(valueType));
}
}