1 21 package oracle.toplink.essentials.internal.parsing; 23 24 25 import java.util.*; 27 28 import oracle.toplink.essentials.expressions.*; 30 import oracle.toplink.essentials.queryframework.ReportQuery; 31 import oracle.toplink.essentials.exceptions.EJBQLException; 32 33 42 public class InNode extends SimpleConditionalExpressionNode { 43 44 private List theObjects = null; 45 46 private boolean notIndicated = false; 48 49 52 public InNode() { 53 super(); 54 } 55 56 60 public void addNodeToTheObjects(Node theNode) { 61 getTheObjects().add(theNode); 62 } 63 64 68 public void validate(ParseTreeContext context) { 69 Object leftType = null; 70 TypeHelper typeHelper = context.getTypeHelper(); 71 72 if (left != null) { 73 left.validate(context); 74 leftType = left.getType(); 75 } 76 for (Iterator i = getTheObjects().iterator(); i.hasNext();) { 77 Node node = (Node)i.next(); 78 node.validate(context); 79 node.validateParameter(context, leftType); 80 Object nodeType = node.getType(); 81 if ((leftType != null) && !typeHelper.isAssignableFrom(leftType, nodeType)) 82 throw EJBQLException.invalidExpressionArgument("IN", node.getAsString(), typeHelper.getTypeName(leftType)); 83 } 84 85 setType(typeHelper.getBooleanType()); 86 } 87 88 92 public Expression generateExpression(GenerationContext context) { 93 Expression whereClause = getLeft().generateExpression(context); 94 List arguments = getTheObjects(); 95 Node firstArg = (Node)arguments.get(0); 96 if (firstArg.isSubqueryNode()) { 97 SubqueryNode subqueryNode = (SubqueryNode)firstArg; 98 ReportQuery reportQuery = subqueryNode.getReportQuery(context); 99 if (notIndicated()) { 100 whereClause = whereClause.notIn(reportQuery); 101 } 102 else { 103 whereClause = whereClause.in(reportQuery); 104 } 105 } 106 else { 107 Vector inArguments = new Vector(arguments.size()); 108 for (Iterator iter = arguments.iterator(); iter.hasNext();) { 109 Node nextNode = (Node)iter.next(); 110 inArguments.add(nextNode.generateExpression(context)); 111 } 112 if (inArguments.size() > 0) { 113 if (notIndicated()) { 114 whereClause = whereClause.notIn(inArguments); 115 } else { 116 whereClause = whereClause.in(inArguments); 117 } 118 } 119 } 120 return whereClause; 121 } 122 123 127 public List getTheObjects() { 128 if (theObjects == null) { 129 setTheObjects(new Vector()); 130 } 131 return theObjects; 132 } 133 134 138 public void setTheObjects(List newTheObjects) { 139 theObjects = newTheObjects; 140 } 141 142 148 public void indicateNot() { 149 notIndicated = true; 150 } 151 152 public boolean notIndicated() { 153 return notIndicated; 154 } 155 } 156 | Popular Tags |