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

org.eclipse.persistence.jpa.jpql.tools.model.query.SimpleSelectStatementStateObject Maven / Gradle / Ivy

There is a newer version: 4.0.2
Show newest version
/*
 * Copyright (c) 2011, 2018 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.tools.model.query;

import org.eclipse.persistence.jpa.jpql.parser.SimpleSelectStatement;
import org.eclipse.persistence.jpa.jpql.tools.model.ISimpleSelectExpressionStateObjectBuilder;

/**
 * This state object represents a subquery, which has at least a SELECT clause
 * and a FROM clause. The other clauses are optional.
 * 

* BNF: subquery ::= simple_select_clause subquery_from_clause [where_clause] [groupby_clause] [having_clause]

* * @see SimpleSelectStatement * * @version 2.4 * @since 2.4 * @author Pascal Filion */ public class SimpleSelectStatementStateObject extends AbstractSelectStatementStateObject { /** * Creates a new SimpleSelectStatementStateObject. * * @param parent The parent of this state object, which cannot be null * @exception NullPointerException The given parent cannot be null */ public SimpleSelectStatementStateObject(StateObject parent) { super(parent); } /** * {@inheritDoc} */ public void accept(StateObjectVisitor visitor) { visitor.visit(this); } /** * Adds a new derived collection declaration to the FROM clause. * * @return The {@link CollectionMemberDeclarationStateObject} representing the collection * declaration */ public CollectionMemberDeclarationStateObject addDerivedCollectionDeclaration() { return getFromClause().addDerivedCollectionDeclaration(); } /** * Adds a new derived collection declaration to the FROM clause. * * @param collectionValuedPath The collection-valued path expression * @return The {@link CollectionMemberDeclarationStateObject} representing the collection * declaration */ public CollectionMemberDeclarationStateObject addDerivedCollectionDeclaration(String collectionValuedPath) { return getFromClause().addDerivedCollectionDeclaration(collectionValuedPath); } /** * Adds a new derived identification variable declaration to the FROM clause. * * @return The {@link DerivedPathIdentificationVariableDeclarationStateObject} representing the collection * declaration */ public DerivedPathIdentificationVariableDeclarationStateObject addDerivedPathDeclaration() { return getFromClause().addDerivedPathDeclaration(); } /** * Adds a new derived identification variable declaration to the FROM clause. * * @param path Either the derived singled-valued object field or the collection-valued path expression * @param identificationVariable The identification variable defining the given path * @return The {@link DerivedPathIdentificationVariableDeclarationStateObject} representing the * path declaration */ public DerivedPathIdentificationVariableDeclarationStateObject addDerivedPathDeclaration(String path, String identificationVariable) { return getFromClause().addDerivedPathDeclaration(path, identificationVariable); } /** * {@inheritDoc} */ @Override protected AbstractFromClauseStateObject buildFromClause() { return new SimpleFromClauseStateObject(this); } /** * {@inheritDoc} */ @Override protected AbstractSelectClauseStateObject buildSelectClause() { return new SimpleSelectClauseStateObject(this); } /** * {@inheritDoc} */ @Override public SimpleSelectStatement getExpression() { return (SimpleSelectStatement) super.getExpression(); } /** * {@inheritDoc} */ @Override public SimpleFromClauseStateObject getFromClause() { return (SimpleFromClauseStateObject) super.getFromClause(); } /** * Creates and returns a new {@link ISimpleSelectExpressionStateObjectBuilder} that can be used * to programmatically create a single select expression and once the expression is complete, * {@link ISimpleSelectExpressionStateObjectBuilder#commit()} will push the {@link StateObject} * representation of that expression as this clause's select expression. * * @return A new builder that can be used to quickly create a select expression */ public ISimpleSelectExpressionStateObjectBuilder getSelectBuilder() { return getSelectClause().getBuilder(); } /** * {@inheritDoc} */ @Override public SimpleSelectClauseStateObject getSelectClause() { return (SimpleSelectClauseStateObject) super.getSelectClause(); } /** * Keeps a reference of the {@link SimpleSelectStatement parsed object} object, which should only * be done when this object is instantiated during the conversion of a parsed JPQL query into * {@link StateObject StateObjects}. * * @param expression The {@link SimpleSelectStatement parsed object} representing a subquery * SELECT statement */ public void setExpression(SimpleSelectStatement expression) { super.setExpression(expression); } /** * Sets the given {@link StateObject} as the SELECT clause's select item. * * @param stateObject The {@link StateObject} representing the single select item */ public void setSelectItem(StateObject stateObject) { getSelectClause().setSelectItem(stateObject); } /** * Parses the given JPQL fragment and create the select item. For the top-level query, the * fragment can contain several select items but for a subquery, it can represent only one. * * @param jpqlFragment The portion of the query representing one or several select items */ public void setSelectItem(String jpqlFragment) { getSelectClause().parse(jpqlFragment); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy