JavaTypeMapping m = tables[0].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);
statementExpressionIndex[prefetchFieldNumbers[i]].setExpressionIndex(stmt.selectField(fieldName, "APP_ID", true));
}
}
}
}
// TODO Select fetch plan fields also ? This should be done for all fields that are in *all* subclass tables
}
else
{
// TODO When we have all possible candidates in single table and using discriminator
// we should really select all fields here to save doing the retrieve of the other fields later.
// Currently we only retrieve the fetch-plan/DFG fields for the base candidate class
if (useFetchPlan)
{
// Select all fields in the FetchPlan
// TODO This only utilises the first table. What if we have multiple ?
AbstractClassMetaData cmd = storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(getCandidateClass(), stmt.getClassLoaderResolver());
getFetchPlan().manageFetchPlanForClass(cmd);
FetchPlanForClass fpc = getFetchPlan().getFetchPlanForClass(cmd);
int fieldNumbers[] = fpc.getFieldsInActualFetchPlan();
int prefetchFieldCount = 0;
int fieldCount = cmd.getNoOfInheritedManagedMembers() + cmd.getNoOfManagedMembers();
int fn[] = new int[fieldNumbers.length];
statementExpressionIndex = new StatementExpressionIndex[fieldCount];
for (int i = 0; i < fieldNumbers.length; ++i)
{
JavaTypeMapping m = tables[0].getFieldMapping(cmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumbers[i]));
if (m != null)
{
// omit fields not stored in the table, e.g. List, Set, etc or transactional
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);
// select the fetch-plan fields to be fetched from the database
if (stmt.getTableExpression(elmIdentifier) != null)
{
Mappings.selectMapping(stmt, elmIdentifier, statementExpressionIndex);
}
else
{
Mappings.selectMapping(stmt, statementExpressionIndex);
}
}
else
{
// if no fetchplan is used and is application identity, select only PK fields
AbstractClassMetaData cmd = storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(getCandidateClass(),stmt.getClassLoaderResolver());
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 = tables[0].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);
}
}
}
// following the actual fetch plan, we select the fields to be fetched from the database