QueryExpression st = storeMgr.getDatastoreAdapter().newQueryStatement(subclassTable, subclassTableIdentifier, om.getClassLoaderResolver());
LogicSetExpression table_expr_sub = st.newTableExpression(subclassTable, subclassTableIdentifier);
JavaTypeMapping subMapping = subclassTable.getIDMapping();
st.select(subclassTableIdentifier, subMapping);
ScalarExpression subExpr = subMapping.newScalarExpression(qs, table_expr_sub);
ScalarExpression schExpr =
(((DatastoreClass)schemaDataOption.getDatastoreContainerObject()).getIDMapping()).newScalarExpression(
qs,qs.getMainTableExpression());
qs.leftOuterJoin(subExpr, schExpr, table_expr_sub, true);
qs.andCondition(new NullLiteral(qs).eq(subExpr));
}
}
// WHERE (object id) = ?
JavaTypeMapping idMapping = ((DatastoreClass)schemaDataOption.getDatastoreContainerObject()).getIDMapping();
// 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
Class pc_class = om.getClassLoaderResolver().classForName(schemaDataOption.getName());
StateManager sm = StateManagerFactory.newStateManagerForHollow(om,pc_class,id);
ScalarExpression fieldExpr = idMapping.newScalarExpression(qs, qs.getMainTableExpression());
ScalarExpression fieldValue = idMapping.newLiteral(qs, sm.getObject());
qs.andCondition(fieldExpr.eq(fieldValue), true);
// Discriminator for this class
JavaTypeMapping discrimMapping = schemaDataOption.getDatastoreContainerObject().getDiscriminatorMapping(false);
DiscriminatorMetaData discrimMetaData = cmd.getInheritanceMetaData().getDiscriminatorMetaData();
if (discrimMapping != null)
{
ScalarExpression discrimExpr = discrimMapping.newScalarExpression(qs, qs.getMainTableExpression());
Object value = null;
if (cmd.getDiscriminatorStrategy() == DiscriminatorStrategy.CLASS_NAME)
{
value = schemaDataOption.getName();
}
else if (cmd.getDiscriminatorStrategy() == DiscriminatorStrategy.VALUE_MAP)
{
value = discrimMetaData.getValue();
}
ScalarExpression discrimValue = discrimMapping.newLiteral(qs, value);
qs.andCondition(discrimExpr.eq(discrimValue), true);
}
if (qs_base==null)
{