/* Generated By:JJTree: Do not edit this line. SubqueryCompareCriteria.java Version 4.3 */ /* JavaCCOptions:MULTI=true,NODE_USES_PARSER=true,VISITOR=true,TRACK_TOKENS=false,NODE_PREFIX=,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ package org.teiid.query.sql.lang; import org.teiid.core.util.EquivalenceUtil; import org.teiid.designer.query.sql.lang.ISubqueryCompareCriteria; import org.teiid.designer.runtime.version.spi.TeiidServerVersion.Version; import org.teiid.language.SQLConstants; import org.teiid.query.parser.LanguageVisitor; import org.teiid.query.parser.TeiidNodeFactory.ASTNodes; import org.teiid.designer.runtime.version.spi.ITeiidServerVersion; import org.teiid.query.sql.symbol.Expression; import org.teiid.query.sql.symbol.ScalarSubquery; /** * <p>This class implements a quantified comparison predicate. This is * a criteria which represents a simple operator relationship between an expression and * either a scalar subquery or a table subquery preceded by one of the possible quantifiers. * </p> * * <p>The quantifiers are: * <ul><li>{@link #NO_QUANTIFIER}, meaning the subquery has no quantifier and therefore must be * a scalar subquery</li> * <li>{@link #SOME} and {@link #ANY}, which are synonymous - the criteria is true if there is at * least one comparison between the left expression and the values of the subquery. The criteria * is false if the subquery returns no rows.</li> * <li>{@link #ALL}</li> - the criteria is true only if all of the comparisons between the left * expression and each value of the subquery is true. The criteria is also true if the subquery * returns no rows.</li></ul> * * <p>Some examples are:</p> * <UL> * <LI>ticker = ANY (Select ... FROM ... WHERE ... )</LI> * <li>price >= ALL (Select ... FROM ... WHERE ... )</LI> * <LI>revenue < (Select ... FROM ... WHERE ... )</LI> * </UL> * * This can also represent a quantified comparison against array. In which case the * arrayExpression member will be set and command will not. * */ public class SubqueryCompareCriteria extends AbstractCompareCriteria implements SubqueryContainer<QueryCommand>, ISubqueryCompareCriteria< LanguageVisitor, QueryCommand> { /** * Predicate quantifiers */ public enum PredicateQuantifier { /** "Some" predicate quantifier (equivalent to "Any") */ SOME, /** "Any" predicate quantifier (equivalent to "Some") */ ANY, /** "All" predicate quantifier */ ALL; /** * @return index of predicate */ public int getQuantifier() { return ordinal() + 2; } /** * @param quantifier * @return {@link PredicateQuantifier} with the given quantifier index */ public static PredicateQuantifier findQuantifier(int quantifier) { for (PredicateQuantifier pq : values()) { if (pq.getQuantifier() == quantifier) return pq; } throw new IllegalStateException(); } } private PredicateQuantifier predicateQuantifier = PredicateQuantifier.ALL; private Expression arrayExpression; private QueryCommand command; private SubqueryHint subqueryHint = new SubqueryHint(); /** * @param p * @param id */ public SubqueryCompareCriteria(ITeiidServerVersion p, int id) { super(p, id); } /** * Get the predicate quantifier - returns one of the following: * <ul> * <li>{@link #ANY}</li> * <li>{@link #SOME}</li> * <li>{@link #ALL}</li></ul> * @return the predicate quantifier */ public PredicateQuantifier getPredicateQuantifier() { return this.predicateQuantifier; } /** * Returns the predicate quantifier as a string. * @return String version of predicate quantifier */ public String getPredicateQuantifierAsString() { String name = this.predicateQuantifier.name(); return name; } /** * Set the predicate quantifier - use one of the following: * <li>{@link PredicateQuantifier#ANY}</li> * <li>{@link PredicateQuantifier#SOME}</li> * <li>{@link PredicateQuantifier#ALL}</li></ul> * * @param predicateQuantifier the predicate quantifier */ public void setPredicateQuantifier(PredicateQuantifier predicateQuantifier) { this.predicateQuantifier = predicateQuantifier; } @Override public QueryCommand getCommand() { return this.command; } /** * Set the subquery command (either a SELECT or a procedure execution). * @param command Command to execute to get the values for the criteria */ @Override public void setCommand(QueryCommand command) { this.command = command; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((this.command == null) ? 0 : this.command.hashCode()); result = prime * result + ((this.predicateQuantifier == null) ? 0 : this.predicateQuantifier.hashCode()); return result; } @Override public boolean equals(Object obj) { // Use super.equals() to check obvious stuff and variable if(obj == this) { return true; } if(! (obj instanceof SubqueryCompareCriteria)) { return false; } SubqueryCompareCriteria scc = (SubqueryCompareCriteria)obj; return getOperator() == scc.getOperator() && getPredicateQuantifier() == scc.getPredicateQuantifier() && EquivalenceUtil.areEqual(getLeftExpression(), scc.getLeftExpression()) && EquivalenceUtil.areEqual(getCommand(), scc.getCommand()) && EquivalenceUtil.areEqual(subqueryHint, scc.subqueryHint) && EquivalenceUtil.areEqual(arrayExpression, scc.arrayExpression); } /** Accept the visitor. **/ @Override public void acceptVisitor(LanguageVisitor visitor) { visitor.visit(this); } @Override public SubqueryCompareCriteria clone() { SubqueryCompareCriteria clone = new SubqueryCompareCriteria(getTeiidVersion(), this.id); if(getCommand() != null) clone.setCommand(getCommand().clone()); if(getPredicateQuantifier() != null) clone.setPredicateQuantifier(getPredicateQuantifier()); if(operator != null) clone.setOperator(operator); if(getLeftExpression() != null) clone.setLeftExpression(getLeftExpression().clone()); if (this.subqueryHint != null) { clone.subqueryHint = this.subqueryHint.clone(); } if (this.arrayExpression != null) { clone.arrayExpression = (Expression) this.arrayExpression.clone(); } return clone; } public SubqueryHint getSubqueryHint() { return subqueryHint; } public void setSubqueryHint(SubqueryHint subqueryHint) { this.subqueryHint = subqueryHint; } public Expression getArrayExpression() { return arrayExpression; } public void setArrayExpression(Expression expression) { this.arrayExpression = expression; } } /* JavaCC - OriginalChecksum=e9b141cd60d09da32342d127668258f8 (do not edit this line) */