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

GroupByNode

public class GroupByNode extends MajorNode
INTERNAL

Purpose: Represent an GROUP BY

Responsibilities:

  • Generate the correct expression for an GROUP BY

Fields Summary
List
groupByItems
Constructors Summary
public GroupByNode()
Return a new GroupByNode.


             
      
        super();
    
Methods Summary
private voidaddGroupByItem(java.lang.Object theNode)
INTERNAL Add an Group By Item to this node

        getGroupByItems().add(theNode);
    
public voidaddGroupingToQuery(oracle.toplink.essentials.queryframework.ObjectLevelReadQuery theQuery, oracle.toplink.essentials.internal.parsing.GenerationContext context)
INTERNAL Add the grouping expressions to the passed query

        if (theQuery.isReportQuery()) {
            Iterator iter = getGroupByItems().iterator();
            while (iter.hasNext()) {
                Node nextNode = (Node)iter.next();
                ((ReportQuery)theQuery).addGrouping(nextNode.generateExpression(context));
            }
        }
    
public java.lang.StringgetAsString()
INTERNAL Get the string representation of this node.

        StringBuffer repr = new StringBuffer();
        for (Iterator i = groupByItems.iterator(); i.hasNext(); ) {
            Node expr = (Node)i.next();
            if (repr.length() > 0) {
                repr.append(", ");
            }
            repr.append(expr.getAsString());
        }
        return "GROUP BY " + repr.toString();
    
public java.util.ListgetGroupByItems()
INTERNAL Return the GROUP BY statements

        if (groupByItems == null) {
            setGroupByItems(new Vector());
        }
        return groupByItems;
    
private booleanisGroupbyItem(oracle.toplink.essentials.internal.parsing.Node expr)
INTERNAL Return true if the specified expr is a groupby item.

        if (expr.isDotNode() || expr.isVariableNode()) {
            String exprRepr = expr.getAsString();
            for (Iterator i = groupByItems.iterator(); i.hasNext();) {
                Node item = (Node)i.next();
                String itemRepr = item.getAsString();
                if (exprRepr.equals(itemRepr)) {
                    return true;
                }
            }
        }
        return false;
    
public booleanisValidHavingExpr(oracle.toplink.essentials.internal.parsing.Node expr)
INTERNAL Returns true if the sp

        if (expr.isDotNode() || expr.isVariableNode()) {
            return isGroupbyItem(expr);
        } else {
            // delegate to child node if any
            Node left = expr.getLeft();
            Node right = expr.getRight();
            return ((left == null) || isValidHavingExpr(left)) &&
                ((right == null) || isValidHavingExpr(right));
        }
    
private booleanisValidSelectExpr(oracle.toplink.essentials.internal.parsing.Node expr)
INTERNAL Returns true if the specified expr is a valid SELECT clause expression.

        if (expr.isAggregateNode()) {
            return true;
        } else if (expr.isConstructorNode()) {
            List args = ((ConstructorNode)expr).getConstructorItems();
            for (Iterator i = args.iterator(); i.hasNext(); ) {
                Node arg = (Node)i.next();
                if (!isValidSelectExpr(arg)) {
                    return false;
                }
            }
            return true;
        }
        return isGroupbyItem(expr);
    
public voidsetGroupByItems(java.util.List newItems)
INTERNAL Set the GROUP BY statements

        groupByItems = newItems;
    
public voidvalidate(oracle.toplink.essentials.internal.parsing.ParseTreeContext context, oracle.toplink.essentials.internal.parsing.SelectNode selectNode)
INTERNAL Validate the current node.

        for (Iterator i = groupByItems.iterator(); i.hasNext(); ) {
            Node item = (Node)i.next();
            item.validate(context);
        }

        List selectExprs = selectNode.getSelectExpressions();
        // check select expressions
        for (Iterator i = selectExprs.iterator(); i.hasNext(); ) {
            Node selectExpr = (Node)i.next();
            if (!isValidSelectExpr(selectExpr)) {
                throw EJBQLException.invalidSelectForGroupByQuery(
                    context.getQueryInfo(), 
                    selectExpr.getLine(), selectExpr.getColumn(), 
                    selectExpr.getAsString(), getAsString());
            }
        }