All Downloads are FREE. Search and download functionalities are using the official Maven repository.

oracle.toplink.essentials.internal.parsing.MemberOfNode Maven / Gradle / Ivy

The newest version!
/*
 * The contents of this file are subject to the terms 
 * of the Common Development and Distribution License 
 * (the "License").  You may not use this file except 
 * in compliance with the License.
 * 
 * You can obtain a copy of the license at 
 * glassfish/bootstrap/legal/CDDLv1.0.txt or 
 * https://glassfish.dev.java.net/public/CDDLv1.0.html. 
 * See the License for the specific language governing 
 * permissions and limitations under the License.
 * 
 * When distributing Covered Code, include this CDDL 
 * HEADER in each file and include the License file at 
 * glassfish/bootstrap/legal/CDDLv1.0.txt.  If applicable, 
 * add the following below this CDDL HEADER, with the 
 * fields enclosed by brackets "[]" replaced with your 
 * own identifying information: Portions Copyright [yyyy] 
 * [name of copyright owner]
 */
// Copyright (c) 1998, 2006, Oracle. All rights reserved.  
package oracle.toplink.essentials.internal.parsing;

/**
 * INTERNAL
 * 

Purpose: Represent the MEMBER-OF operator *

Responsibilities:

    *
  • MEMBER OF is not supported. *
* @author Jon Driscoll and Joel Lucuik * @since since July 2003 */ import oracle.toplink.essentials.expressions.*; public class MemberOfNode extends BinaryOperatorNode { private boolean notIndicated = false; //If we're dealing with a NOT, we store the expression for the left. //When we get to the one-to-many on the right, it will handle the noneOf using //the receiver stored in the context. //(i.e. secondLastRightExpression.noneOf(lastRightVariable, leftExpression) private Expression leftExpression = null; /** * Return a new MemberOfNode */ public MemberOfNode() { super(); } /** * 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); } /** * INTERNAL * Validate node and calculates its type. */ public void validate(ParseTreeContext context) { super.validate(context); Node left = getLeft(); if (left.isVariableNode() && ((VariableNode)left).isAlias(context)) { context.usedVariable(((VariableNode)left).getCanonicalVariableName()); } TypeHelper typeHelper = context.getTypeHelper(); setType(typeHelper.getBooleanType()); } public Expression generateExpression(GenerationContext context) { //BUG 3107061 - Handle if left node is declared in FROM //i.e. "SELECT OBJECT(emp) FROM Employee emp, SmallProject s", and the left //node is the "s" if (getLeft().isVariableNode() && ((VariableNode)getLeft()).isAlias(context)) { VariableNode leftVariableNode = (VariableNode)getLeft(); makeNodeOneToMany(getRight()); return getRight().generateExpression(context).equal(new ExpressionBuilder(leftVariableNode.resolveClass(context))); } // Need to make sure one of the node is marked as a one to many if (getRight().isParameterNode()) { makeNodeOneToMany(getLeft()); } else { makeNodeOneToMany(getRight()); } //Handle NOT. Store the expression for the left, let VariableNode handle it. if (notIndicated()) { Expression resultFromRight = null; context.setMemberOfNode(this); this.setLeftExpression(getLeft().generateExpression(context)); resultFromRight = getRight().generateExpression(context); //clean up context.setMemberOfNode(null); this.setLeftExpression(null); return resultFromRight; } else { //otherwise, handle like normal anyOf() return getRight().generateExpression(context).equal(getLeft().generateExpression(context)); } } /** * INTERNAL * Indicate if a NOT was found in the WHERE clause. * Examples: * ...WHERE ... NOT MEMBER OF */ public void indicateNot() { notIndicated = true; } public boolean notIndicated() { return notIndicated; } //set and get the leftExpression. This is for NOT MEMBER OF. public void setLeftExpression(Expression newLeftExpression) { leftExpression = newLeftExpression; } public Expression getLeftExpression() { return leftExpression; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy