/** * Answer true if the SELECT ends in a direct-to-field. * true: SELECT phone.areaCode * false: SELECT employee.address */ private boolean selectingDirectToField(Node node, GenerationContext context) { if ((node == null) || !node.isDotNode()) { return false; } return ((DotNode)node).endsWithDirectToField(context); }
/** * INTERNAL * Apply this node to the passed query */ public void applyToQuery(ObjectLevelReadQuery theQuery, GenerationContext context) { if (theQuery.isReportQuery()){ ReportQuery reportQuery = (ReportQuery)theQuery; reportQuery.addAttribute(resolveAttribute(), generateExpression(context)); reportQuery.dontRetrievePrimaryKeys(); } }
/** * INTERNAL * Check the left child node for an unqualified field access. The method * delegates to the left most expression of multi-navigation path * expression. */ public Node qualifyAttributeAccess(ParseTreeContext context) { if (getLeft() != null) { setLeft(getLeft().qualifyAttributeAccess(context)); } return this; }
String name = ((AttributeNode)right).getAttributeName(); Node leftMost = getLeftMostNode(); if (isDeclaredVariable(leftMost, context)) { left.validate(context); checkNavigation(left, context); Object type = typeHelper.resolveAttribute(left.getType(), name); if (type == null) { name, typeHelper.getTypeName(left.getType())); setType(type); right.setType(type); } else { Object type = resolveEnumTypeName(typeName, typeHelper); if ((type != null) && typeHelper.isEnumType(type)) { enumConstant = typeHelper.resolveEnumConstant(type, name); leftMost.getColumn(), leftMost.getAsString()); setType(type); right.setType(type);
/** * INTERNAL * Generate the EclipseLink expression for this node */ public Expression generateExpression(GenerationContext context) { DotNode dotNode = (DotNode)getLeft(); Node prefix = dotNode.getLeft(); String variableName = ((AttributeNode)dotNode.getRight()).getAttributeName(); // check whether variable denotes a collection valued field if (!dotNode.endsWithCollectionField(context)) { throw JPQLException.invalidSizeArgument( context.getParseTreeContext().getQueryInfo(), getLine(), getColumn(), variableName); } Expression whereClause = prefix.generateExpression(context); whereClause = whereClause.size(variableName); return whereClause; }
Node left = getLeft(); Node right = getRight(); } else { Expression whereClause = getLeft().generateExpression(context); ((AttributeNode)right).setMapping(resolveMapping(context));
public Object getTypeForMapKey(ParseTreeContext context){ Object type = null; String name = ((AttributeNode)right).getAttributeName(); Node leftMost = getLeftMostNode(); if (isDeclaredVariable(leftMost, context)) { type = context.getTypeHelper().resolveMapKey(left.getType(), name); } return type; } /**
/** * INTERNAL * Answer the name of the attribute which is represented by the receiver's * right node. */ public String resolveAttribute() { return ((AttributeNode)getRight()).getAttributeName(); }
/** * INTERNAL * Return the left most node of a dot expr, so return 'a' for 'a.b.c'. */ public Node getLeftMostNode() { if (left.isDotNode()){ return ((DotNode)left).getLeftMostNode(); } return left; }
public void validate(ParseTreeContext context) { left.validate(context); if (left.isVariableNode()){ setType(((VariableNode)left).getTypeForMapKey(context)); } else if (left.isDotNode()){ setType(((DotNode)left).getTypeForMapKey(context)); } }
/** */ public Object newJoinVariableDecl(int line, int column, boolean outerJoin, Object path, String variable, Object downcast) { DotNode dotNode = (DotNode)path; AttributeNode rightNode = (AttributeNode)dotNode.getRight(); rightNode.setOuterJoin(outerJoin); if (downcast != null){ AttributeNode rightMostNode = (AttributeNode)dotNode.getRightMostNode(); rightMostNode.setCastClassName((String)downcast); } JoinDeclNode node = new JoinDeclNode(); node.setPath(dotNode); node.setVariableName(variable); node.setOuterJoin(outerJoin); setPosition(node, line, column); context.registerJoinVariable(node.getCanonicalVariableName(), dotNode, line, column); currentIdentificationVariable = variable; return node; }
/** * 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()); } } }
String name = ((AttributeNode)right).getAttributeName(); Node leftMost = getLeftMostNode(); if (isDeclaredVariable(leftMost, context)) { left.validate(context); checkNavigation(left, context); Object type = null; if (left.isVariableNode()){ ((AttributeNode)right).checkForQueryKey(left.getType(), typeHelper); setType(type); right.setType(type); } else { Object type = resolveEnumTypeName(typeName, typeHelper); if ((type != null) && typeHelper.isEnumType(type)) { enumConstant = typeHelper.resolveEnumConstant(type, name); leftMost.getColumn(), leftMost.getAsString()); setType(type); right.setType(type);
/** * INTERNAL * Generate the EclipseLink expression for this node */ public Expression generateExpression(GenerationContext context) { DotNode dotNode = (DotNode)getLeft(); Node prefix = dotNode.getLeft(); String variableName = ((AttributeNode)dotNode.getRight()).getAttributeName(); // check whether variable denotes a collection valued field if (!dotNode.endsWithCollectionField(context)) { throw JPQLException.invalidSizeArgument( context.getParseTreeContext().getQueryInfo(), getLine(), getColumn(), variableName); } Expression whereClause = prefix.generateExpression(context); whereClause = whereClause.size(variableName); return whereClause; }
/** * INTERNAL * Return a TopLink expression by getting the required variables using the * left and right nodes * "emp.address.city" = builder.get("address").get("city") */ public Expression generateExpression(GenerationContext context) { Node right = getRight(); if (enumConstant != null) { // enum literal access return new ConstantExpression(enumConstant, new ExpressionBuilder()); } else { // Get the left expression Expression whereClause = getLeft().generateExpression(context); // Calculate the mapping and pass it to the right expression if (right.isAttributeNode()) { ((AttributeNode)right).setMapping(resolveMapping(context)); } // Or it with whatever the right expression is whereClause = right.addToExpression(whereClause, context); if (alias != null){ context.addExpression(whereClause, alias); } // and return the expression... return whereClause; } }
/** * INTERNAL * Check the left child node for an unqualified field access. The method * delegates to the left most expression of multi-navigation path * expression. */ public Node qualifyAttributeAccess(ParseTreeContext context) { if (getLeft() != null) { setLeft(getLeft().qualifyAttributeAccess(context)); } return this; }
public Object getTypeForMapKey(ParseTreeContext context){ Object type = null; String name = ((AttributeNode)right).getAttributeName(); Node leftMost = getLeftMostNode(); if (isDeclaredVariable(leftMost, context)) { type = context.getTypeHelper().resolveMapKey(left.getType(), name); } return type; } /**