public int findNodeN(Node node, int n, int callNumber) //Call initially with findNodeN(tree.getRoot(), n, 0) { if (node.hasLeft()) findNodeN(node.getLeftChild(), n, callNumber); if (callNumber == n) return node.getElement(); else callNumber++; if (node.hasRight()) printTreeInOrder(node.getRightChild(), n, callNumber); }
public Expression generateExpression(GenerationContext context) { Expression whereClause = left.generateExpression(context); return whereClause; } }
/** * INTERNAL * Validate the current node. */ public void validate(ParseTreeContext context, GroupByNode groupbyNode) { if (having != null) { having.validate(context); if ((groupbyNode != null) && !groupbyNode.isValidHavingExpr(having)) { throw JPQLException.invalidHavingExpression( context.getQueryInfo(), having.getLine(), having.getColumn(), having.getAsString(), groupbyNode.getAsString()); } } }
public String toString(int indent) { StringBuilder buffer = new StringBuilder(); buffer.append(toStringDisplayName()); buffer.append("\r\n"); toStringIndent(indent, buffer); if (hasLeft()) { buffer.append("Left: " + getLeft().toString(indent + 1)); } else { buffer.append("Left: null"); } buffer.append("\r\n"); toStringIndent(indent, buffer); if (hasRight()) { buffer.append("Right: " + getRight().toString(indent + 1)); } else { buffer.append("Right: null"); } return buffer.toString(); }
/** * INTERNAL * Checks whether the left hand side of this dot node is navigable. */ private void checkNavigation(Node node, ParseTreeContext context) { TypeHelper typeHelper = context.getTypeHelper(); // Checks whether the type of the dot node allows a navigation. Object type = node.getType(); if (!typeHelper.isEntityClass(type) && !typeHelper.isEmbeddable(type) && !typeHelper.isEnumType(type)) { throw JPQLException.invalidNavigation( context.getQueryInfo(), node.getLine(), node.getColumn(), this.getAsString(), node.getAsString(), typeHelper.getTypeName(type)); } // Special check to disallow collection valued relationships if (node.isDotNode()) { Node left = node.getLeft(); AttributeNode right = (AttributeNode)node.getRight(); if (typeHelper.isCollectionValuedRelationship( left.getType(), right.getAttributeName())) { throw JPQLException.invalidCollectionNavigation( context.getQueryInfo(), right.getLine(), right.getColumn(), this.getAsString(), right.getAttributeName()); } } }
left.validate(context); checkNavigation(left, context); Object type = null; if (left.isVariableNode()){ Node path = context.pathForVariable(((VariableNode)left).getVariableName()); if (path != null){ type = path.getType(); type = typeHelper.resolveAttribute(type, name); type = typeHelper.resolveAttribute(left.getType(), name); context.getQueryInfo(), right.getLine(), right.getColumn(), name, typeHelper.getTypeName(left.getType())); if (right.isAttributeNode()){ type = ((AttributeNode)right).computeActualType(type, typeHelper); ((AttributeNode)right).checkForQueryKey(left.getType(), typeHelper); right.setType(type); } else { String typeName = left.getAsString(); Object type = resolveEnumTypeName(typeName, typeHelper); if ((type != null) && typeHelper.isEnumType(type)) { if (enumConstant == null) { throw JPQLException.invalidEnumLiteral(context.getQueryInfo(), right.getLine(), right.getColumn(), typeName, name);
private boolean selectingRelationshipField(Node node, GenerationContext context) { if ((node == null) || !node.isDotNode()) { return false; } TypeHelper typeHelper = context.getParseTreeContext().getTypeHelper(); Node path = node.getLeft(); AttributeNode attribute = (AttributeNode)node.getRight(); return typeHelper.isRelationship(path.getType(), attribute.getAttributeName()); }
/** * Create an expression to represent one of the nodes on a SetToNode. * We will assume that set_to nodes change elements that are direct mappings on the reference * class of the query. */ protected Expression getExpressionForNode(Node node, Class referenceClass, GenerationContext context) { Expression expression = null; if (node.isAttributeNode()) { // look up a preexisting expression based on the reference class of the query. String classVariable = context.getParseTreeContext().getVariableNameForClass(referenceClass, context); expression = context.expressionFor(classVariable); if (expression == null) { expression = new ExpressionBuilder(); context.addExpression(expression, classVariable); } expression = node.addToExpression(expression, context); } else { expression = node.generateExpression(context); } return expression; }
public void validate(ParseTreeContext context) { TypeHelper typeHelper = context.getTypeHelper(); left.validate(context); if (!left.isVariableNode()){ throw JPQLException.indexOnlyAllowedOnVariable(context.getQueryInfo(), getLine(), getColumn(), left.getAsString()); } setType(typeHelper.getIntType()); } }
if (!(isSingleSelectExpression() && getFirstSelectExpressionNode().isCountNode())) { selectContext.useOuterJoins(); if (node.isAliasableNode() && identifiers != null){ String alias = (String)identifiers.get(i); if (alias != null){ node.applyToQuery(readQuery, context); selectContext.dontUseOuterJoins();
/** * INTERNAL makeNodeOneToMany: * Traverse to the leaf on theNode and mark as one to many */ public void makeNodeOneToMany(Node theNode) { Node currentNode = theNode; do { if (!currentNode.hasRight()) { ((AttributeNode)currentNode).setRequiresCollectionAttribute(true); return; } currentNode = currentNode.getRight(); } while (true); }
public static void preorder(Node root) { if(root == null) return; root.printValue(); preorder(root.getLeft()); preorder(root.getRight()); return; }
/** * INTERNAL * Apply this node to the passed query */ public void applyToQuery(ObjectLevelReadQuery theQuery, GenerationContext context) { if (theQuery.isReportQuery()) { ReportQuery reportQuery = (ReportQuery)theQuery; reportQuery.addAttribute("size", getLeft().generateExpression(context).count(), (Class)getType()); reportQuery.addGrouping(getLeft().getLeft().generateExpression(context)); } }
/** * INTERNAL * Get the string representation of this node. */ public String getAsString() { return left.getAsString() + " <> " + right.getAsString(); } }
/** * INTERNAL * Does this node have a left */ public boolean hasLeft() { return getLeft() != null; }
/** * INTERNAL * Apply this node to the passed query */ public void applyToQuery(ObjectLevelReadQuery theQuery, GenerationContext context) { if (theQuery instanceof ReportQuery) { SelectGenerationContext selectContext = (SelectGenerationContext)context; ReportQuery reportQuery = (ReportQuery)theQuery; reportQuery.beginAddingConstructorArguments( getConstructorClass(context.getParseTreeContext())); for (Iterator i = constructorItems.iterator(); i.hasNext();) { Node node = (Node)i.next(); if (selectingRelationshipField(node, context)) { selectContext.useOuterJoins(); } node.applyToQuery(reportQuery, context); selectContext.dontUseOuterJoins(); } reportQuery.endAddingToConstructorItem(); } }