FileDocCategorySizeDatePackage
InNode.javaAPI DocGlassfish v2 API5959Tue May 22 16:54:38 BST 2007oracle.toplink.essentials.internal.parsing

InNode

public class InNode extends SimpleConditionalExpressionNode
INTERNAL

Purpose: Represent an IN in EJBQL

Responsibilities:

  • Generate the correct expression for an IN
author
Jon Driscoll and Joel Lucuik
since
TopLink 4.0

Fields Summary
private List
theObjects
private boolean
notIndicated
Constructors Summary
public InNode()
InNode constructor comment.


            
      
        super();
    
Methods Summary
public voidaddNodeToTheObjects(oracle.toplink.essentials.internal.parsing.Node theNode)
INTERNAL Add the passed node value to the collection of object for this node

        getTheObjects().add(theNode);
    
public oracle.toplink.essentials.expressions.ExpressiongenerateExpression(oracle.toplink.essentials.internal.parsing.GenerationContext context)
INTERNAL Return the TopLink expression for this node

        Expression whereClause = getLeft().generateExpression(context);
        List arguments = getTheObjects();
        Node firstArg = (Node)arguments.get(0);
        if (firstArg.isSubqueryNode()) {
            SubqueryNode subqueryNode = (SubqueryNode)firstArg;
            ReportQuery reportQuery = subqueryNode.getReportQuery(context);
            if (notIndicated()) {
                whereClause = whereClause.notIn(reportQuery);
            }
            else {
                whereClause = whereClause.in(reportQuery);
            }
        }
        else {
            Vector inArguments = new Vector(arguments.size());
            for (Iterator iter = arguments.iterator(); iter.hasNext();) {
                Node nextNode = (Node)iter.next();
                inArguments.add(nextNode.generateExpression(context));
            }
            if (inArguments.size() > 0) {
                if (notIndicated()) {
                    whereClause = whereClause.notIn(inArguments);
                } else {
                    whereClause = whereClause.in(inArguments);
                }
            }
        }
        return whereClause;
    
public java.util.ListgetTheObjects()
INTERNAL Return the collection of the objects used as parameters for this node

        if (theObjects == null) {
            setTheObjects(new Vector());
        }
        return theObjects;
    
public voidindicateNot()
INTERNAL Indicate if a NOT was found in the WHERE clause. Examples: ...WHERE ... NOT IN(...)

        notIndicated = true;
    
public booleannotIndicated()

        return notIndicated;
    
public voidsetTheObjects(java.util.List newTheObjects)
INTERNAL Set this node's object collection to the passed value

        theObjects = newTheObjects;
    
public voidvalidate(oracle.toplink.essentials.internal.parsing.ParseTreeContext context)
INTERNAL Validate the current node and calculates its type.

        Object leftType = null;
        TypeHelper typeHelper = context.getTypeHelper();

        if (left != null) {
            left.validate(context);
            leftType = left.getType();
        }
        for (Iterator i = getTheObjects().iterator(); i.hasNext();) {
            Node node = (Node)i.next();
            node.validate(context);
            node.validateParameter(context, leftType);
            Object nodeType = node.getType();
            if ((leftType != null) && !typeHelper.isAssignableFrom(leftType, nodeType))
                throw EJBQLException.invalidExpressionArgument(
                    context.getQueryInfo(), node.getLine(), node.getColumn(),
                    "IN", node.getAsString(), typeHelper.getTypeName(leftType));
        }

        setType(typeHelper.getBooleanType());