org.eclipse.persistence.jpa.jpql.parser.ExistsExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eclipselink Show documentation
Show all versions of eclipselink Show documentation
EclipseLink build based upon Git transaction f2b9fc5
/*
* Copyright (c) 2006, 2020 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 v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// 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);
}
@Override
public void accept(ExpressionVisitor visitor) {
visitor.visit(this);
}
@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;
}
@Override
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);
}
@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);
}
@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;
}
}