1 21 package oracle.toplink.essentials.internal.parsing; 23 24 37 import oracle.toplink.essentials.expressions.*; 38 import oracle.toplink.essentials.exceptions.EJBQLException; 39 40 public class ModNode extends ArithmeticFunctionNode { 41 42 private Node denominator = null; 43 44 48 public void validate(ParseTreeContext context) { 49 TypeHelper typeHelper = context.getTypeHelper(); 50 if (left != null) { 51 left.validate(context); 52 left.validateParameter(context, typeHelper.getIntType()); 53 54 Object type = left.getType(); 55 if (!typeHelper.isIntegralType(type)) 56 throw EJBQLException.invalidFunctionArgument("MOD", left.getAsString(), "integral type"); 57 } 58 59 if (denominator != null) { 60 denominator.validate(context); 61 denominator.validateParameter(context, typeHelper.getIntType()); 62 63 Object denominatorType = denominator.getType(); 64 if (!typeHelper.isIntegralType(denominatorType)) 65 throw EJBQLException.invalidFunctionArgument("MOD", denominator.getAsString(), "integral type"); 66 } 67 68 setType(typeHelper.getIntType()); 69 } 70 71 72 public Expression generateExpression(GenerationContext context) { 73 Expression whereClause; 74 Integer i = new Integer (((LiteralNode)getDenominator()).getLiteral().toString()); 75 76 if (getLeft().isLiteralNode()) { 78 ExpressionBuilder builder = new ExpressionBuilder(); 79 Integer leftInt = new Integer (((IntegerLiteralNode)getLeft()).getLiteral().toString()); 80 whereClause = ExpressionMath.mod(builder.value(leftInt.intValue()), builder.value(i.intValue())); 81 } else { 82 whereClause = ExpressionMath.mod(getLeft().generateExpression(context), i.intValue()); 83 } 84 return whereClause; 85 } 86 87 public Node getDenominator() { 89 return denominator; 90 } 91 92 public void setDenominator(Node denominator) { 93 this.denominator = denominator; 94 } 95 } 96 | Popular Tags |