Skip to content

Commit

Permalink
Support for compile of TypeExpression(PrimaryExpression) where the
Browse files Browse the repository at this point in the history
priamry has a discriminator. Fixes #187
  • Loading branch information
andyjefferson committed Apr 7, 2017
1 parent da36344 commit c4b71da
Showing 1 changed file with 25 additions and 0 deletions.
Expand Up @@ -58,6 +58,7 @@
import org.datanucleus.query.expression.ParameterExpression;
import org.datanucleus.query.expression.PrimaryExpression;
import org.datanucleus.query.expression.SubqueryExpression;
import org.datanucleus.query.expression.TypeExpression;
import org.datanucleus.query.expression.VariableExpression;
import org.datanucleus.state.ObjectProvider;
import org.datanucleus.store.query.QueryCompilerSyntaxException;
Expand Down Expand Up @@ -796,6 +797,30 @@ else if (resultExprs[i] instanceof Literal)
}
resultDefinition.addMappingForResultExpression(i, idx);
}
else if (resultExprs[i] instanceof TypeExpression)
{
// TYPE(identification_variable | single_valued_path_expr | input_parameter)
TypeExpression typeExpr = (TypeExpression)resultExprs[i];
Expression containedExpr = typeExpr.getContainedExpression();
if (containedExpr instanceof PrimaryExpression)
{
processPrimaryExpression((PrimaryExpression)containedExpr);
SQLExpression sqlExpr = stack.pop();
JavaTypeMapping discrimMapping = sqlExpr.getSQLTable().getTable().getSurrogateMapping(SurrogateColumnType.DISCRIMINATOR, true);
if (discrimMapping == null)
{
throw new NucleusException("Result has call to " + typeExpr + " but contained expression has no discriminator. Not supported");
}

StatementMappingIndex idx = new StatementMappingIndex(discrimMapping);
idx.setColumnPositions(stmt.select(sqlExpr.getSQLTable(), discrimMapping, null, true));
resultDefinition.addMappingForResultExpression(i, idx);
}
else
{
throw new NucleusException("Result has call to " + typeExpr + " but contained expression not supported");
}
}
else if (resultExprs[i] instanceof CreatorExpression)
{
processCreatorExpression((CreatorExpression)resultExprs[i]);
Expand Down

0 comments on commit c4b71da

Please sign in to comment.