org.eclipse.persistence.jpa.jpql.parser.ExistsExpression Maven / Gradle / Ivy
Show all versions of eclipselink Show documentation
/*******************************************************************************
* Copyright (c) 2006, 2013 Oracle and/or its affiliates. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Oracle - initial API and implementation
*
******************************************************************************/
package org.eclipse.persistence.jpa.jpql.parser;
import org.eclipse.persistence.jpa.jpql.ExpressionTools;
import org.eclipse.persistence.jpa.jpql.WordParser;
/**
* An EXISTS expression is a predicate that is true
only if the result of the
* subquery consists of one or more values and that is false
otherwise.
*
*
BNF: exists_expression ::= [NOT] EXISTS(subquery)
*
* @version 2.5
* @since 2.3
* @author Pascal Filion
*/
public final class ExistsExpression extends AbstractSingleEncapsulatedExpression {
/**
* The actual NOT identifier found in the string representation of the JPQL query.
*/
private String notIdentifier;
/**
* Creates a new ExistsExpression
.
*
* @param parent The parent of this expression
*/
public ExistsExpression(AbstractExpression parent) {
super(parent, EXISTS);
}
/**
* {@inheritDoc}
*/
public void accept(ExpressionVisitor visitor) {
visitor.visit(this);
}
/**
* {@inheritDoc}
*/
@Override
public String getEncapsulatedExpressionQueryBNFId() {
return SubqueryBNF.ID;
}
/**
* Returns the actual NOT identifier found in the string representation of the JPQL query,
* which has the actual case that was used.
*
* @return The NOT identifier that was actually parsed, or an empty string if it was not
* parsed
*/
public String getActualNotIdentifier() {
return (notIdentifier != null) ? notIdentifier : ExpressionTools.EMPTY_STRING;
}
/**
* {@inheritDoc}
*/
public JPQLQueryBNF getQueryBNF() {
return getQueryBNF(ExistsExpressionBNF.ID);
}
/**
* Determines whether the identifier NOT was parsed.
*
* @return true
if the identifier NOT was parsed; false
otherwise
*/
public boolean hasNot() {
return (notIdentifier != null);
}
/**
* {@inheritDoc}
*/
@Override
protected void parse(WordParser wordParser, boolean tolerant) {
// Parse 'NOT'
if (wordParser.startsWithIgnoreCase('N')) {
int position = wordParser.position();
notIdentifier = wordParser.substring(position, position + 3);
setText(NOT_EXISTS);
}
super.parse(wordParser, tolerant);
}
/**
* {@inheritDoc}
*/
@Override
protected AbstractExpression parse(WordParser wordParser, String queryBNFId, boolean tolerant) {
if (tolerant) {
return super.parse(wordParser, queryBNFId, tolerant);
}
SimpleSelectStatement expression = new SimpleSelectStatement(this);
expression.parse(wordParser, tolerant);
return expression;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy