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

org.eclipse.persistence.internal.jpa.parsing.NodeFactoryImpl Maven / Gradle / Ivy

There is a newer version: 4.0.2
Show newest version
/*
 * Copyright (c) 1998, 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 from Oracle TopLink
//     tware - updates for JPA 2.0 specification
package org.eclipse.persistence.internal.jpa.parsing;

import java.util.List;

import org.eclipse.persistence.internal.jpa.parsing.TemporalLiteralNode.TemporalType;

/**
 * INTERNAL
 * 

Purpose: Implements a node factory used by the EJBQLParser * class. *

Responsibilities:

    *
  • Create EJBQLParseTree instances for EJBQL SELECT-, UPDATE- and DELETE * statements (see methods newSelectStatement, newUpdateStatement and * newDeleteStatement). *
  • Any new method returns an instance of the appropriate Node * subclass. *
  • The relationship to the child nodes passed as arguments are * automatically initialized. *
  • Note, this implementation has a state managing the parse tree context * and a list of parameter names for the current parse tree. This state needs * to be initialized before the same node factory implementation instance may * be used to create a second parse tree (see methods initContext and * initParameters). *
  • The implementation automatically adds the list of parameters to the * created parse tree. *
  • The implementation automatically sets the parse tree context for any * created major node. *
*/ public class NodeFactoryImpl implements NodeFactory { /** The parse tree context. */ private ParseTreeContext context; /** */ private String currentIdentificationVariable; /** No-arg Constructor */ public NodeFactoryImpl(String queryInfo) { this.context = new ParseTreeContext(this, queryInfo); } // ------------------------------------------ // Trees // ------------------------------------------ /** */ public Object newSelectStatement(int line, int column, Object select, Object from, Object where, Object groupBy, Object having, Object orderBy) { QueryNode queryNode = (QueryNode)select; JPQLParseTree tree = new JPQLParseTree(); queryNode.setParseTree(tree); tree.setContext(context); tree.setQueryNode(queryNode); tree.setFromNode((FromNode)from); tree.setWhereNode((WhereNode)where); tree.setGroupByNode((GroupByNode)groupBy); tree.setHavingNode((HavingNode)having); tree.setOrderByNode((OrderByNode)orderBy); return tree; } /** */ public Object newUpdateStatement(int line, int column, Object update, Object set, Object where) { QueryNode queryNode = (QueryNode)update; JPQLParseTree tree = new JPQLParseTree(); queryNode.setParseTree(tree); tree.setContext(context); tree.setQueryNode(queryNode); tree.setSetNode((SetNode)set); tree.setWhereNode((WhereNode)where); return tree; } /** */ public Object newDeleteStatement(int line, int column, Object delete, Object where) { QueryNode queryNode = (QueryNode)delete; JPQLParseTree tree = new JPQLParseTree(); queryNode.setParseTree(tree); tree.setContext(context); tree.setQueryNode(queryNode); tree.setWhereNode((WhereNode)where); return tree; } // ------------------------------------------ // Major nodes // ------------------------------------------ public Object newSelectClause(int line, int column, boolean distinct, List selectExprs) { return newSelectClause(line, column, distinct, selectExprs, null); } public Object newSelectClause(int line, int column, boolean distinct, List selectExprs, List identifiers) { SelectNode node = new SelectNode(); node.setContext(context); node.setSelectExpressions(selectExprs); node.setIdentifiers(identifiers); if (identifiers != null){ for (int i=0;i // use schema name as variable context.registerSchema(calculateCanonicalName(schema), schema, line, column); } } /** */ private String calculateCanonicalName(String name) { return (name == null) ? null : IdentificationVariableDeclNode.calculateCanonicalName(name); } public Object newKey(int line, int column, Object left){ MapKeyNode node = new MapKeyNode(); node.setLeft((Node)left); setPosition(node, line, column); return node; } public Object newMapEntry(int line, int column, Object arg){ MapEntryNode node = new MapEntryNode(); node.setLeft((Node)arg); setPosition(node, line, column); return node; } public Object newType(int line, int column, Object left){ ClassForInheritanceNode node = new ClassForInheritanceNode(); node.setLeft((Node)left); setPosition(node, line, column); return node; } public Object newCaseClause(int line, int column, Object base, List whenClauses, Object elseClause){ CaseNode node = new CaseNode(); node.setWhenClauses(whenClauses); if (base != null){ node.setLeft((Node)base); } node.setRight((Node)elseClause); setPosition(node, line, column); return node; } public Object newCoalesceClause(int line, int column, List clauses){ CoalesceNode node = new CoalesceNode(); node.setClauses(clauses); setPosition(node, line, column); return node; } public Object newNullIfClause(int line, int column, Object left, Object right){ NullIfNode node = new NullIfNode(); node.setLeft((Node)left); node.setRight((Node)right); setPosition(node, line, column); return node; } public Object newWhenClause(int line, int column, Object conditionClause, Object thenClause){ WhenThenNode node = new WhenThenNode(); node.setLeft((Node)conditionClause); node.setRight((Node)thenClause); setPosition(node, line, column); return node; } public Object newIndex(int line, int column, Object object){ IndexNode node = new IndexNode(); node.setLeft((Node)object); setPosition(node, line, column); return node; } public Object newDateLiteral(int line, int column, Object value){ TemporalLiteralNode node = new TemporalLiteralNode(TemporalType.DATE); node.setLiteral(value); setPosition(node, line, column); return node; } public Object newTimeLiteral(int line, int column, Object value){ TemporalLiteralNode node = new TemporalLiteralNode(TemporalType.TIME); node.setLiteral(value); setPosition(node, line, column); return node; } public Object newTimeStampLiteral(int line, int column, Object value){ TemporalLiteralNode node = new TemporalLiteralNode(TemporalType.TIMESTAMP); node.setLiteral(value); setPosition(node, line, column); return node; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy