[jboss-cvs] JBossAS SVN: r94178 - in trunk/server: src/main and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Sep 30 15:05:48 EDT 2009
Author: pgier
Date: 2009-09-30 15:05:48 -0400 (Wed, 30 Sep 2009)
New Revision: 94178
Added:
trunk/server/src/main/jjtree/
trunk/server/src/main/jjtree/org/
trunk/server/src/main/jjtree/org/jboss/
trunk/server/src/main/jjtree/org/jboss/ejb/
trunk/server/src/main/jjtree/org/jboss/ejb/plugins/
trunk/server/src/main/jjtree/org/jboss/ejb/plugins/cmp/
trunk/server/src/main/jjtree/org/jboss/ejb/plugins/cmp/ejbql/
trunk/server/src/main/jjtree/org/jboss/ejb/plugins/cmp/ejbql/EJBQLParser.jjt
trunk/server/src/main/jjtree/org/jboss/ejb/plugins/cmp/ejbql/JBossQLParser.jjt
Removed:
trunk/server/src/main/java/org/jboss/ejb/plugins/cmp/ejbql/EJBQLParser.jjt
trunk/server/src/main/java/org/jboss/ejb/plugins/cmp/ejbql/JBossQLParser.jjt
Modified:
trunk/server/pom.xml
Log:
[JBBUILD-541] Move jjtree sources into a separate directory.
Modified: trunk/server/pom.xml
===================================================================
--- trunk/server/pom.xml 2009-09-30 19:02:30 UTC (rev 94177)
+++ trunk/server/pom.xml 2009-09-30 19:05:48 UTC (rev 94178)
@@ -26,7 +26,6 @@
<goal>jjtree</goal>
</goals>
<configuration>
- <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
<includes>
<include>org/jboss/ejb/plugins/cmp/ejbql/JBossQLParser.jjt</include>
</includes>
@@ -38,7 +37,6 @@
<goal>jjtree</goal>
</goals>
<configuration>
- <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
<includes>
<include>org/jboss/ejb/plugins/cmp/ejbql/EJBQLParser.jjt</include>
</includes>
Deleted: trunk/server/src/main/java/org/jboss/ejb/plugins/cmp/ejbql/EJBQLParser.jjt
===================================================================
--- trunk/server/src/main/java/org/jboss/ejb/plugins/cmp/ejbql/EJBQLParser.jjt 2009-09-30 19:02:30 UTC (rev 94177)
+++ trunk/server/src/main/java/org/jboss/ejb/plugins/cmp/ejbql/EJBQLParser.jjt 2009-09-30 19:05:48 UTC (rev 94178)
@@ -1,1235 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-options {
- BUILD_NODE_FILES=false;
- MULTI=true;
-
- JAVA_UNICODE_ESCAPE = true;
- STATIC = false;
-
- CHOICE_AMBIGUITY_CHECK = 5;
- OTHER_AMBIGUITY_CHECK = 5;
-
- LOOKAHEAD = 1;
- DEBUG_PARSER = false;
- DEBUG_LOOKAHEAD = false;
- DEBUG_TOKEN_MANAGER = false;
- ERROR_REPORTING = true;
- UNICODE_INPUT = false;
- IGNORE_CASE = false;
- USER_TOKEN_MANAGER = false;
- USER_CHAR_STREAM = false;
- BUILD_PARSER = true;
- BUILD_TOKEN_MANAGER = true;
- SANITY_CHECK = true;
- FORCE_LA_CHECK = false;
-}
-
-PARSER_BEGIN(EJBQLParser)
-package org.jboss.ejb.plugins.cmp.ejbql;
-
-import java.io.CharArrayReader;
-import java.util.ArrayList;
-import java.util.List;
-import org.jboss.ejb.plugins.cmp.bridge.EntityBridge;
-import org.jboss.ejb.plugins.cmp.bridge.CMPFieldBridge;
-import org.jboss.ejb.plugins.cmp.bridge.CMRFieldBridge;
-import org.jboss.ejb.plugins.cmp.bridge.FieldBridge;
-
-/**
- * This class parses EJB-QL into an abstract syntax tree.
- *
- * @author <a href="mailto:dain at daingroup.com">Dain Sundstrom</a>
- * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
- * @version $Revision$
- */
-public class EJBQLParser {
- private Catalog catalog;
- private Class[] argumentTypes;
- private IdentifierManager idManager;
- private boolean selectDistinct;
- private String selectPath;
-
- public ASTEJBQL parse(Catalog catalog, Class[] argumentTypes, String ejbql)
- throws ParseException {
-
- this.catalog = catalog;
- token_source.catalog = catalog;
- this.argumentTypes = argumentTypes;
- token_source.argumentTypes = argumentTypes;
- idManager = new IdentifierManager(catalog);
- token_source.idManager = idManager;
-
- String lowerCase = ejbql.toLowerCase();
- int fromBeginIndex = indexOf(lowerCase, "from");
- if(fromBeginIndex < 0) {
- throw new ParseException("FROM not found");
- }
-
- int fromEndIndex = indexOf(lowerCase, "where");
- if(fromEndIndex < 0) {
- fromEndIndex = indexOfOrderBy(lowerCase);
- }
- if(fromEndIndex < 0) {
- fromEndIndex = ejbql.length();
- }
-
- // just the from clause
- char[] from = ejbql.toCharArray();
- clear(from, 0, fromBeginIndex);
- clear(from, fromEndIndex, from.length);
-
- // everything except for the from clause
- char[] sansFrom = ejbql.toCharArray();
- clear(sansFrom, fromBeginIndex + 4, fromEndIndex);
-
- // From clause
- ReInit(new CharArrayReader(from));
- ASTFrom fromNode = ParseFromClause();
-
- // Everything else
- ReInit(new CharArrayReader(sansFrom));
- ASTEJBQL ejbqlNode = EJBQL();
-
- // replace the dummy from clause in the EJBQL
- // node with the real from node
- ejbqlNode.jjtAddChild(fromNode, 1);
-
- return ejbqlNode;
- }
-
- /**
- * Returns the first index of the word (surrounded with whitespaces) in the string
- * or -1 if the word was not found.
- */
- private static final int indexOf(String ql, String word)
- {
- return indexOf(ql, word, 0);
- }
-
- /**
- * Returns the first index of the word (surrounded with whitespaces) in the string
- * starting with startInd position or -1 if the word was not found.
- */
- private static final int indexOf(String ql, String word, int startInd)
- {
- int i = ql.indexOf(word, startInd);
- if(i < 0)
- {
- return -1;
- }
-
- int qlLength = ql.length();
- int wordLength = word.length();
- while(i >= 0)
- {
- int endInd = i + wordLength;
- if((i == 0 || Character.isWhitespace(ql.charAt(i - 1))) &&
- (endInd == qlLength || endInd < qlLength && Character.isWhitespace(ql.charAt(endInd))))
- {
- break;
- }
-
- i = ql.indexOf(word, i + 1);
- }
- return i;
- }
-
- private static final int indexOfOrderBy(String ql)
- {
- int orderInd = indexOf(ql, "order", 0);
- int byInd = -1;
- while(orderInd > 0)
- {
- if(byInd < orderInd)
- {
- byInd = indexOf(ql, "by", orderInd + 5);
- }
-
- if(byInd > 0)
- {
- int i = byInd - 1;
- while(i >= orderInd + 5 && Character.isWhitespace(ql.charAt(i--)));
- if(i == orderInd + 4)
- {
- break;
- }
- else
- {
- orderInd = indexOf(ql, "order", orderInd + 5);
- }
- }
- else
- {
- orderInd = -1;
- }
- }
- return orderInd;
- }
-
- private final void clear(char[] c, int beginIndex, int endIndex) {
- for(int i=beginIndex; i < endIndex; i++) {
- if(c[i]!='\r' && c[i]!='\n' && c[i]!='\t') {
- c[i] = ' ';
- }
- }
- }
-
- private final void initPathNode(ASTPath pathNode, String path, int type) {
- pathNode.pathList = idManager.getPathList(path);
- pathNode.fieldList = idManager.getFieldList(path);
- pathNode.type = type;
- }
-
- private final void initParameterNode(
- ASTParameter parameterNode,
- String number,
- int type) {
-
- parameterNode.number = Integer.parseInt(number);
- parameterNode.type = type;
- }
-}
-
-PARSER_END(EJBQLParser)
-
-ASTEJBQL EJBQL() #EJBQL :
-{}
-{
- SelectClause() FromKeyword() [WhereClause()] [OrderByClause()] <EOF>
- { return jjtThis; }
-}
-
-ASTOrderBy OrderByClause() #OrderBy :
-{}
-{
- <ORDER> <BY> OrderByPathExpression() ( <COMMA> OrderByPathExpression() ) *
- { return jjtThis; }
-}
-
-void OrderByPathExpression() #OrderByPath :
-{}
-{
- ( NumericValuedPath() | StringValuedPath() | DatetimeValuedPath() )
- [<ASC> | <DESC> { jjtThis.ascending=false; } ]
-}
-
-void FromKeyword() #From :
-{}
-{
- <FROM>
-}
-
-ASTFrom ParseFromClause() #void :
-{ ASTFrom node; }
-{
- node = FromClause() <EOF>
- { return node; }
-}
-
-ASTFrom FromClause() #From :
-{}
-{
- (
- <FROM> IdentificationVariableDeclaration()
- ( <COMMA> IdentificationVariableDeclaration() )*
- ) { return jjtThis; }
-}
-
-void IdentificationVariableDeclaration() #void :
-{}
-{
- (CollectionMemberDeclaration() | RangeVariableDeclaration())
-}
-
-void CollectionMemberDeclaration() :
-{
- Token path;
- Token id;
-}
-{
- ( <IN> <LPAREN> path=CollectionValuedPath() <RPAREN>
- [<AS>] id=Identifier() )
- { idManager.declareCollectionMember(id.image, path.image); }
-}
-
-void RangeVariableDeclaration() :
-{
- Token schema;
- Token id;
-}
-{
- ( schema=AbstractSchema() [<AS>] id=Identifier() )
- { idManager.declareRangeVariable(id.image, schema.image); }
-}
-
-ASTSelect SelectClause() #Select :
-{}
-{
- (
- <SELECT> [<DISTINCT> { jjtThis.distinct=true; }]
- (
- <OBJECT> <LPAREN> IdentificationVariable() <RPAREN> |
- SelectExpression()
- )
- ) { return jjtThis; }
-}
-
-void SelectExpression() #void :
-{}
-{
- SingleValuedPath() | AggregateSelectExpression()
-}
-
-ASTWhere WhereClause() #Where :
-{}
-{
- <WHERE> WhereExpression()
- { return jjtThis; }
-}
-
-//
-// ASTWhereExpression and ASTWhereConditionalTerm mimic
-// ConditionalExpression and ConditionalTerm.
-// They are added to support joins per WhereConditionalTerm.
-//
-void WhereExpression() #void :
-{}
-{
- (
- WhereConditionalTerm() ( <OR> WhereConditionalTerm() )*
- ) #Or(>1)
-}
-
-ASTWhereConditionalTerm WhereConditionalTerm() #WhereConditionalTerm :
-{}
-{
- (
- ConditionalFactor() ( <AND> ConditionalFactor() )*
- ) #And(>1)
- {return jjtThis;}
-}
-
-void ConditionalExpression() #void :
-{}
-{
- (
- ConditionalTerm() ( <OR> ConditionalTerm() )*
- ) #Or(>1)
-}
-
-void ConditionalTerm() #void :
-{}
-{
- (
- ConditionalFactor() ( <AND> ConditionalFactor() )*
- ) #And(>1)
-}
-
-void ConditionalFactor() #void :
-{ boolean not = false; }
-{
- (
- [<NOT>{ not=true; }] ConditionalTest()
- ) #Not(not)
-}
-
-void ConditionalTest() #void :
-{}
-{
- ConditionalPrimary()
-}
-
-void ConditionalPrimary() #void :
-{}
-{
- LOOKAHEAD(<LPAREN> ConditionalExpression() <RPAREN>)
- (<LPAREN> ConditionalExpression() <RPAREN>) #ConditionalParenthetical
-|
- SimpleCondExpression()
-}
-
-void SimpleCondExpression() #void :
-{}
-{
- EmptyCollectionComparisonExpression()
-|
- LOOKAHEAD({ getToken(2).kind==IS })
- NullComparisonExpression()
-|
- LOOKAHEAD({ getToken(2).kind==MEMBER || getToken(3).kind==MEMBER })
- CollectionMemberExpression()
-|
- LOOKAHEAD({ getToken(2).kind==LIKE || getToken(3).kind==LIKE })
- LikeExpression()
-|
- LOOKAHEAD({ getToken(2).kind==IN || getToken(3).kind==IN })
- InExpression()
-|
- ComparisonExpression()
-}
-
-void BetweenExpression() #Between :
-{}
-{
- ArithmeticExpression() [<NOT> { jjtThis.not=true; } ] <BETWEEN>
- ArithmeticExpression() <AND> ArithmeticExpression()
-}
-
-void InExpression() #In :
-{}
-{
- (StringExpression() [<NOT> { jjtThis.not=true; } ] <IN>
- <LPAREN> StringExpression() ( <COMMA> StringExpression() )* <RPAREN>)
-|
- (ArithmeticPrimary() [<NOT> { jjtThis.not=true; } ] <IN>
- <LPAREN> ArithmeticPrimary() ( <COMMA> ArithmeticPrimary() )* <RPAREN>)
-}
-
-void LikeExpression() #Like :
-{}
-{
- StringValuedPath() [<NOT> { jjtThis.not=true; } ] <LIKE>
- StringExpression() [<ESCAPE> (StringLiteral() | NumericValuedParameter())]
-}
-
-void NullComparisonExpression() #NullComparison :
-{}
-{
- (
- SingleValuedPath() |
- NumericValuedParameter() |
- EntityValuedParameter() |
- StringValuedParameter() |
- DatetimeValuedParameter() |
- BooleanValuedParameter()
- )
- <IS> [<NOT> { jjtThis.not=true; } ] <NULL>
-}
-
-void EmptyCollectionComparisonExpression() #IsEmpty :
-{}
-{
- CollectionValuedPath() <IS> [<NOT> { jjtThis.not=true; } ] <EMPTY>
-}
-
-void CollectionMemberExpression() #MemberOf :
-{}
-{
- (EntityValuedPath() |
- IdentificationVariable() |
- EntityValuedParameter())
- [<NOT> { jjtThis.not=true; } ] <MEMBER> [<OF>] CollectionValuedPath()
-}
-
-
-void ComparisonExpression() #void :
-{}
-{
- (
- StringValue()
- (
- <EQ> { jjtThis.opp="="; } |
- <GT> { jjtThis.opp=">"; } |
- <GE> { jjtThis.opp=">="; } |
- <LT> { jjtThis.opp="<"; } |
- <LE> { jjtThis.opp="<="; } |
- <NE> { jjtThis.opp="<>"; }
- )
- StringExpression()
- ) #StringComparison
-|
- (
- BooleanValue()
- [
- (
- <EQ> { jjtThis.opp="="; } |
- <NE> { jjtThis.opp="<>"; }
- ) BooleanExpression()
- ]
- ) #BooleanComparison
-|
- (
- DatetimeValue()
- (
- <EQ> { jjtThis.opp="="; } |
- <GT> { jjtThis.opp=">"; } |
- <LT> { jjtThis.opp="<"; } |
- <NE> { jjtThis.opp="<>"; } |
- <GE> { jjtThis.opp=">="; } |
- <LE> { jjtThis.opp="<="; }
- )
- DatetimeExpression()
- ) #DatetimeComparison
-|
- (
- EntityBeanValue()
- (
- <EQ> { jjtThis.opp="="; } |
- <NE> { jjtThis.opp="<>"; }
- )
- EntityBeanExpression()
- ) #EntityComparison
-|
- LOOKAHEAD(ArithmeticValue() ( <EQ> | <GT> | <GE> | <LT> | <LE> | <NE> ) )
- (
- ArithmeticValue()
- (
- <EQ> { jjtThis.opp="="; } |
- <GT> { jjtThis.opp=">"; } |
- <GE> { jjtThis.opp=">="; } |
- <LT> { jjtThis.opp="<"; } |
- <LE> { jjtThis.opp="<="; } |
- <NE> { jjtThis.opp="<>"; }
- )
- SingleValueDesignator()
- ) #ArithmeticComparison
-|
- BetweenExpression()
-}
-
-void ArithmeticValue() #void :
-{}
-{
- NumericValuedPath() | FunctionsReturningNumerics()
-}
-
-void SingleValueDesignator() #void :
-{}
-{
- ScalarExpression()
-}
-
-void ScalarExpression() #void :
-{}
-{
- ArithmeticExpression()
-}
-
-void ArithmeticExpression() #void :
-{}
-{
- (
- ArithmeticTerm()
- (
- (
- <PLUS> { jjtThis.addOpp("+"); } |
- <MINUS> { jjtThis.addOpp("-"); }
- ) ArithmeticTerm()
- )*
- ) #PlusMinus(>1)
-}
-
-void ArithmeticTerm() #void :
-{}
-{
- (
- ArithmeticFactor()
- (
- (
- <MULT> { jjtThis.addOpp("*"); } |
- <DIV> { jjtThis.addOpp("/"); }
- ) ArithmeticFactor()
- )*
- ) #MultDiv(>1)
-}
-
-void ArithmeticFactor() #void :
-{ boolean negation = false; }
-{
- (
- [<PLUS>|<MINUS>{negation=true;}] ArithmeticPrimary()
- ) #Negation(negation)
-}
-
-void ArithmeticPrimary() #void :
-{}
-{
- NumericValuedPath() |
- NumericLiteral() |
- (<LPAREN> ArithmeticExpression() <RPAREN>) #ArithmeticParenthetical |
- NumericValuedParameter() |
- FunctionsReturningNumerics()
-}
-
-void StringValue() #void :
-{}
-{
- StringValuedPath() | FunctionsReturningStrings()
-}
-
-void StringExpression() #void :
-{}
-{
- StringPrimary() | StringValuedParameter()
-}
-
-void StringPrimary() #void :
-{}
-{
- StringValuedPath() |
- StringLiteral() |
- (<LPAREN> StringExpression() <RPAREN>) #StringParenthetical |
- FunctionsReturningStrings()
-}
-
-void DatetimeValue() #void :
-{}
-{
- DatetimeValuedPath()
-}
-
-void DatetimeExpression() #void :
-{}
-{
- DatetimeValue() | DatetimeValuedParameter()
-}
-
-void BooleanValue() #void :
-{}
-{
- BooleanValuedPath()
-}
-
-void BooleanExpression() #void :
-{}
-{
- BooleanValue() | BooleanValuedParameter() | BooleanLiteral()
-}
-
-void EntityBeanValue() #void :
-{}
-{
- EntityValuedPath() | IdentificationVariable()
-}
-
-void EntityBeanExpression() #void :
-{}
-{
- EntityBeanValue() | EntityValuedParameter()
-}
-
-void FunctionsReturningStrings() #void :
-{}
-{
- (
- <CONCAT> <LPAREN> StringExpression() <COMMA> StringExpression() <RPAREN>
- ) #Concat
-|
- (
- <SUBSTRING> <LPAREN>
- StringExpression() <COMMA>
- ArithmeticExpression() <COMMA>
- ArithmeticExpression() <RPAREN>
- ) #Substring
-}
-
-void FunctionsReturningNumerics() #void :
-{}
-{
- (
- <LENGTH> <LPAREN> StringExpression() <RPAREN>
- ) #Length
-|
- (
- <LOCATE> <LPAREN>
- StringExpression() <COMMA> StringExpression()
- [ <COMMA> ArithmeticExpression()] <RPAREN>
- ) #Locate
-|
- (
- <ABS> <LPAREN> ArithmeticExpression() <RPAREN>
- ) #Abs
-|
- (
- <SQRT> <LPAREN> ArithmeticExpression() <RPAREN>
- ) #Sqrt
-|
- (
- <MOD> <LPAREN> ArithmeticExpression() <COMMA> ArithmeticExpression() <RPAREN>
- ) #Mod
-}
-
-Token CollectionValuedPath() #Path :
-{ Token t; }
-{
- t=<COLLECTION_VALUED_PATH>
- {
- initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE);
- return t;
- }
-}
-
-Token IdentificationVariable() #Path :
-{ Token t; }
-{
- t=<IDENTIFICATION_VARIABLE>
- {
- t.image = t.image.toLowerCase();
- initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE);
- return t;
- }
-}
-
-Token AbstractSchema() #AbstractSchema :
-{ Token t; }
-{
- t=<ABSTRACT_SCHEMA>
- {
- jjtThis.abstractSchemaName = t.image;
- jjtThis.entity = catalog.getEntityByAbstractSchemaName(t.image);
- return t;
- }
- |
- t=<ORDER>
- {
- jjtThis.abstractSchemaName = t.image;
- jjtThis.entity = catalog.getEntityByAbstractSchemaName(t.image);
- return t;
- }
-}
-
-Token Identifier() #Identifier :
-{ Token t; }
-{
- t=<IDENTIFIER>
- {
- t.image = t.image.toLowerCase();
- jjtThis.identifier = t.image;
- return t;
- }
-}
-
-void SingleValuedPath() #void :
-{}
-{
- NumericValuedPath()
-| StringValuedPath()
-| DatetimeValuedPath()
-| BooleanValuedPath()
-| EntityValuedPath()
-| ValueClassValuedPath()
-}
-
-void NumericValuedPath() #Path :
-{ Token t; }
-{
- t=<NUMERIC_VALUED_PATH>
- { initPathNode(jjtThis, t.image, EJBQLTypes.NUMERIC_TYPE); }
-}
-
-void StringValuedPath() #Path :
-{ Token t; }
-{
- t=<STRING_VALUED_PATH>
- { initPathNode(jjtThis, t.image, EJBQLTypes.STRING_TYPE); }
-}
-
-void DatetimeValuedPath() #Path :
-{ Token t; }
-{
- t=<DATETIME_VALUED_PATH>
- { initPathNode(jjtThis, t.image, EJBQLTypes.DATETIME_TYPE); }
-}
-
-void BooleanValuedPath() #Path :
-{ Token t; }
-{
- t=<BOOLEAN_VALUED_PATH>
- { initPathNode(jjtThis, t.image, EJBQLTypes.BOOLEAN_TYPE); }
-}
-
-void EntityValuedPath() #Path :
-{ Token t; }
-{
- t=<ENTITY_VALUED_PATH>
- { initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE); }
-}
-
-void ValueClassValuedPath() #Path :
-{ Token t; }
-{
- t=<VALUE_CLASS_VALUED_PATH>
- { initPathNode(jjtThis, t.image, EJBQLTypes.VALUE_CLASS_TYPE); }
-}
-
-void NumericValuedParameter() #Parameter :
-{ Token t; }
-{
- t=<NUMERIC_VALUED_PARAMETER>
- { initParameterNode(jjtThis, t.image, EJBQLTypes.NUMERIC_TYPE); }
-}
-
-void StringValuedParameter() #Parameter :
-{ Token t; }
-{
- t=<STRING_VALUED_PARAMETER>
- { initParameterNode(jjtThis, t.image, EJBQLTypes.STRING_TYPE); }
-}
-
-void DatetimeValuedParameter() #Parameter :
-{ Token t; }
-{
- t=<DATETIME_VALUED_PARAMETER>
- { initParameterNode(jjtThis, t.image, EJBQLTypes.DATETIME_TYPE); }
-}
-
-void BooleanValuedParameter() #Parameter :
-{ Token t; }
-{
- t=<BOOLEAN_VALUED_PARAMETER>
- { initParameterNode(jjtThis, t.image, EJBQLTypes.BOOLEAN_TYPE); }
-}
-
-void EntityValuedParameter() #Parameter :
-{ Token t; }
-{
- t=<ENTITY_VALUED_PARAMETER>
- { initParameterNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE); }
-}
-
-void ValueClassValuedParameter() #Parameter :
-{ Token t; }
-{
- t=<VALUE_CLASS_VALUED_PARAMETER>
- { initParameterNode(jjtThis, t.image, EJBQLTypes.VALUE_CLASS_TYPE); }
-}
-
-void NumericLiteral() #void :
-{ Token t; }
-{
- (
- t=<INTEGER_LITERAL> { jjtThis.setValue(t.image); }
- ) #ExactNumericLiteral
-|
- (
- t=<FLOATING_POINT_LITERAL> { jjtThis.setValue(t.image); }
- ) #ApproximateNumericLiteral
-}
-
-void StringLiteral() #StringLiteral :
-{ Token t; }
-{
- t=<STRING_LITERAL>
- { jjtThis.value=t.image; }
-}
-
-void BooleanLiteral() #BooleanLiteral :
-{ Token t; }
-{
- <TRUE> { jjtThis.value=true; } | <FALSE> { jjtThis.value=false; }
-}
-
-void AggregateSelectExpression() #void:
-{}
-{
- (
- <AVG> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
- ) #Avg
-|
- (
- <MAX> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
- ) #Max
-|
- (
- <MIN> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
- ) #Min
-|
- (
- <SUM> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
- ) #Sum
-|
- (
- <COUNT> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}]
- (
- SingleValuedPath() | EntityBeanValue()
- )
- <RPAREN>
- ) #Count
-}
-
-/////////////////////////
-// Tokens
-/////////////////////////
-
-TOKEN_MGR_DECLS :
-{
- public Catalog catalog;
- public Class[] argumentTypes;
- public IdentifierManager idManager;
-
- // used for navigation building
- private List pathList;
- private List fieldList;
- private String path;
-
- private void resetPath() {
- path = "";
- pathList = new ArrayList();
- fieldList = new ArrayList();
- }
-
- private void throwUnknownPath(
- String reason,
- String fieldName) {
-
- throw new UnknownPathException(
- reason,
- path,
- fieldName,
- input_stream.getEndLine(),
- input_stream.getEndColumn());
- }
-
- private void addPath(String nav) {
- String fieldName = nav.substring(0, nav.length()-1);
- if(fieldList.size() > 0) {
- FieldBridge field = getCurrentSchema().getFieldByName(fieldName);
- if(field == null) {
- throwUnknownPath("Unknown cmr field in path", fieldName);
- }
- if(!(field instanceof CMRFieldBridge)) {
- throwUnknownPath("In path field is not a cmr field", fieldName);
- }
-
- CMRFieldBridge cmrField = (CMRFieldBridge)field;
- if(!cmrField.isSingleValued()) {
- throwUnknownPath("In path cmr field is collection valued",
- fieldName);
- }
- fieldList.add(cmrField);
- } else {
- EntityBridge entityBridge = idManager.getEntity(fieldName);
- if(entityBridge == null) {
- throwUnknownPath("Unknown initial identifier", fieldName);
- }
- fieldList.add(entityBridge);
- }
- pathList.add(path + fieldName);
- path += nav;
- }
-
- private EntityBridge getCurrentSchema() {
- Object lastElement = fieldList.get(fieldList.size()-1);
- if(lastElement instanceof EntityBridge) {
- return (EntityBridge)lastElement;
- } else if(lastElement instanceof CMRFieldBridge) {
- return ((CMRFieldBridge)lastElement).getRelatedEntity();
- }
- // should never happen
- throw new IllegalStateException("Unknown path element type: " +
- lastElement);
- }
-}
-
-<DEFAULT> SKIP :
-{
- " "
-| "\t"
-| "\n"
-| "\r"
-}
-
-<DEFAULT> TOKEN [IGNORE_CASE] : /* RESERVED WORDS */
-{
- < ABS: "ABS" >
-| < AND: "AND" >
-| < AS: "AS" >
-| < BETWEEN: "BETWEEN" >
-| < CONCAT: "CONCAT" >
-| < DISTINCT: "DISTINCT" >
-| < EMPTY: "EMPTY" >
-| < ESCAPE: "ESCAPE" >
-| < FROM: "FROM" >
-| < IN: "IN" >
-| < IS: "IS" >
-| < LENGTH: "LENGTH" >
-| < LIKE: "LIKE" >
-| < LOCATE: "LOCATE" >
-| < NOT: "NOT" >
-| < NULL: "NULL" >
-| < OBJECT: "OBJECT" >
-| < OF: "OF " >
-| < OR: "OR" >
-| < SELECT: "SELECT" >
-| < SUBSTRING: "SUBSTRING" >
-| < SQRT: "SQRT" >
-| < UNKNOWN: "UNKNOWN" >
-| < WHERE: "WHERE" >
-| < MEMBER: "MEMBER" >
-
-// EJB QL 2.1 tokens
-
-| < ORDER: "ORDER" >
-| < BY: "BY" >
-| < ASC: "ASC" >
-| < DESC: "DESC" >
-| < COUNT: "COUNT" >
-| < MAX: "MAX" >
-| < MIN: "MIN" >
-| < AVG: "AVG" >
-| < SUM: "SUM" >
-| < MOD: "MOD" >
-}
-
-<DEFAULT> TOKEN : /* SEPARATORS */
-{
- < LPAREN: "(" >
-| < RPAREN: ")" >
-| < COMMA: "," >
-| < DOT: "." >
-}
-
-<DEFAULT> TOKEN : /* OPERATORS */
-{
- < GT: ">" >
-| < LT: "<" >
-| < EQ: "=" >
-| < LE: "<=" >
-| < GE: ">=" >
-| < NE: "<>" >
-| < PLUS: "+" >
-| < MINUS: "-" >
-| < MULT: "*" >
-| < DIV: "/" >
-}
-
-<DEFAULT> TOKEN : /* String Literal */
-{
- < STRING_LITERAL: "'" (~["'"])* ( "''" (~["'"])* )* "'" >
-}
-
-<DEFAULT> TOKEN : /* Numeric Literal */
-{
- < INTEGER_LITERAL:
- <DECIMAL_LITERAL> (["l","L"])?
- | <HEX_LITERAL> (["l","L"])?
- | <OCTAL_LITERAL> (["l","L"])?
- >
-|
- < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
-|
- < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
-|
- < #OCTAL_LITERAL: "0" (["0"-"7"])* >
-|
- < FLOATING_POINT_LITERAL:
- (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
- | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
- | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
- | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
- >
-|
- < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
-}
-
-<DEFAULT> TOKEN [IGNORE_CASE] : /* Boolean Literal */
-{
- < FALSE: "FALSE" >
-| < TRUE: "TRUE" >
-}
-
-<DEFAULT> TOKEN : /* IDENTIFIERS */
-{
- < IDENTIFIER: <NAME> >
- {
- if(catalog.getEntityByAbstractSchemaName(matchedToken.image) != null) {
- matchedToken.kind = ABSTRACT_SCHEMA;
- } else if(idManager.getEntity(matchedToken.image.toLowerCase()) != null) {
- matchedToken.kind = IDENTIFICATION_VARIABLE;
- matchedToken.image = matchedToken.image.toLowerCase();
-
- List pathList = new ArrayList();
- pathList.add(matchedToken.image);
- List fieldList = new ArrayList();
- fieldList.add(idManager.getEntity(matchedToken.image));
- idManager.registerPath(matchedToken.image, pathList, fieldList);
- }
- }
-|
- < ABSTRACT_SCHEMA: [] >
-|
- < IDENTIFICATION_VARIABLE: [] >
-|
- < #NAME: <LETTER> (<LETTER>|<DIGIT>)* >
-|
- < #LETTER:
- [
- "\u0024",
- "\u0041"-"\u005a",
- "\u005f",
- "\u0061"-"\u007a",
- "\u00c0"-"\u00d6",
- "\u00d8"-"\u00f6",
- "\u00f8"-"\u00ff",
- "\u0100"-"\u1fff",
- "\u3040"-"\u318f",
- "\u3300"-"\u337f",
- "\u3400"-"\u3d2d",
- "\u4e00"-"\u9fff",
- "\uf900"-"\ufaff"
- ]
- >
-|
- < #DIGIT:
- [
- "\u0030"-"\u0039",
- "\u0660"-"\u0669",
- "\u06f0"-"\u06f9",
- "\u0966"-"\u096f",
- "\u09e6"-"\u09ef",
- "\u0a66"-"\u0a6f",
- "\u0ae6"-"\u0aef",
- "\u0b66"-"\u0b6f",
- "\u0be7"-"\u0bef",
- "\u0c66"-"\u0c6f",
- "\u0ce6"-"\u0cef",
- "\u0d66"-"\u0d6f",
- "\u0e50"-"\u0e59",
- "\u0ed0"-"\u0ed9",
- "\u1040"-"\u1049"
- ]
- >
-}
-
-<DEFAULT> TOKEN : /* PARAMETERS */
-{
- < UNKNOWN_PARAMETER: "?" <INTEGER_LITERAL> >
- {
- int n = EJBQLTypes.UNKNOWN_TYPE;
- try {
- n = Integer.parseInt(matchedToken.image.substring(1, lengthOfMatch));
- } catch(Exception e) { /* Should never come here. */ }
-
- matchedToken.image = "" + n;
-
- // zero base the index
- n--;
-
- if(n < argumentTypes.length) {
- switch(EJBQLTypes.getEJBQLType(argumentTypes[n])) {
- case EJBQLTypes.NUMERIC_TYPE:
- matchedToken.kind = NUMERIC_VALUED_PARAMETER;
- break;
- case EJBQLTypes.STRING_TYPE:
- matchedToken.kind = STRING_VALUED_PARAMETER;
- break;
- case EJBQLTypes.DATETIME_TYPE:
- matchedToken.kind = DATETIME_VALUED_PARAMETER;
- break;
- case EJBQLTypes.BOOLEAN_TYPE:
- matchedToken.kind = BOOLEAN_VALUED_PARAMETER;
- break;
- case EJBQLTypes.ENTITY_TYPE:
- matchedToken.kind = ENTITY_VALUED_PARAMETER;
- break;
- case EJBQLTypes.VALUE_CLASS_TYPE:
- matchedToken.kind = VALUE_CLASS_VALUED_PARAMETER;
- break;
- }
- }
- }
-| < NUMERIC_VALUED_PARAMETER: [] >
-| < STRING_VALUED_PARAMETER: [] >
-| < DATETIME_VALUED_PARAMETER: [] >
-| < BOOLEAN_VALUED_PARAMETER: [] >
-| < ENTITY_VALUED_PARAMETER: [] >
-| < VALUE_CLASS_VALUED_PARAMETER: [] >
-}
-
-/**
- * WARNING: Be careful here. If look ahead is to high in the from clause, it
- * is possible that the identification varible is not registered before it
- * is used here.
- */
-<DEFAULT> SPECIAL_TOKEN : /* Navigation */
-{
- < <NAME> <DOT> > {
- resetPath();
- addPath(matchedToken.image.toLowerCase());
- } : IN_NAVIGATION
-}
-
-<IN_NAVIGATION> SPECIAL_TOKEN :
-{
- < <NAME> <DOT> > { addPath(matchedToken.image); } : IN_NAVIGATION
-}
-
-<IN_NAVIGATION> TOKEN :
-{
- < PART: <NAME> > {
- String fieldName = matchedToken.image;
- matchedToken.image = path + fieldName;
-
- FieldBridge field = getCurrentSchema().getFieldByName(fieldName);
- if(field == null) {
- throwUnknownPath("Unknown terminal field", fieldName);
- }
- if(field instanceof CMPFieldBridge) {
- CMPFieldBridge cmpField = (CMPFieldBridge)field;
- switch(EJBQLTypes.getEJBQLType(cmpField.getFieldType())) {
- case EJBQLTypes.NUMERIC_TYPE:
- matchedToken.kind = NUMERIC_VALUED_PATH;
- break;
- case EJBQLTypes.STRING_TYPE:
- matchedToken.kind = STRING_VALUED_PATH;
- break;
- case EJBQLTypes.DATETIME_TYPE:
- matchedToken.kind = DATETIME_VALUED_PATH;
- break;
- case EJBQLTypes.BOOLEAN_TYPE:
- matchedToken.kind = BOOLEAN_VALUED_PATH;
- break;
- case EJBQLTypes.ENTITY_TYPE:
- matchedToken.kind = ENTITY_VALUED_PATH;
- break;
- case EJBQLTypes.VALUE_CLASS_TYPE:
- matchedToken.kind = VALUE_CLASS_VALUED_PATH;
- break;
- default:
- throwUnknownPath("Unknown cmp field type", fieldName);
- }
- } else {
- CMRFieldBridge cmrField = (CMRFieldBridge)field;
- if(cmrField.isSingleValued()) {
- matchedToken.kind = ENTITY_VALUED_PATH;
- } else {
- matchedToken.kind = COLLECTION_VALUED_PATH;
- }
- }
- pathList.add(matchedToken.image);
- fieldList.add(field);
- idManager.registerPath(matchedToken.image, pathList, fieldList);
- resetPath();
- } : DEFAULT
-| < NUMERIC_VALUED_PATH: [] >
-| < STRING_VALUED_PATH: [] >
-| < DATETIME_VALUED_PATH: [] >
-| < BOOLEAN_VALUED_PATH: [] >
-| < ENTITY_VALUED_PATH: [] >
-| < VALUE_CLASS_VALUED_PATH: [] >
-| < UNKNOWN_PATH: [] >
-| < COLLECTION_VALUED_PATH: [] >
-}
-
-
Deleted: trunk/server/src/main/java/org/jboss/ejb/plugins/cmp/ejbql/JBossQLParser.jjt
===================================================================
--- trunk/server/src/main/java/org/jboss/ejb/plugins/cmp/ejbql/JBossQLParser.jjt 2009-09-30 19:02:30 UTC (rev 94177)
+++ trunk/server/src/main/java/org/jboss/ejb/plugins/cmp/ejbql/JBossQLParser.jjt 2009-09-30 19:05:48 UTC (rev 94178)
@@ -1,1331 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-options {
- BUILD_NODE_FILES=false;
- MULTI=true;
- VISITOR=true;
-
- JAVA_UNICODE_ESCAPE = true;
- STATIC = false;
-
- CHOICE_AMBIGUITY_CHECK = 5;
- OTHER_AMBIGUITY_CHECK = 5;
-
- LOOKAHEAD = 1;
- DEBUG_PARSER = false;
- DEBUG_LOOKAHEAD = false;
- DEBUG_TOKEN_MANAGER = false;
- ERROR_REPORTING = true;
- UNICODE_INPUT = false;
- IGNORE_CASE = false;
- USER_TOKEN_MANAGER = false;
- USER_CHAR_STREAM = false;
- BUILD_PARSER = true;
- BUILD_TOKEN_MANAGER = true;
- SANITY_CHECK = true;
- FORCE_LA_CHECK = false;
-}
-
-PARSER_BEGIN(JBossQLParser)
-package org.jboss.ejb.plugins.cmp.ejbql;
-
-import java.io.CharArrayReader;
-import java.util.ArrayList;
-import java.util.List;
-import org.jboss.ejb.plugins.cmp.bridge.EntityBridge;
-import org.jboss.ejb.plugins.cmp.bridge.CMPFieldBridge;
-import org.jboss.ejb.plugins.cmp.bridge.CMRFieldBridge;
-import org.jboss.ejb.plugins.cmp.bridge.FieldBridge;
-
-/**
- * This class parses JBossQL into an abstract syntax tree.
- *
- * @author <a href="mailto:dain at daingroup.com">Dain Sundstrom</a>
- * @author <a href="mailto:alex at jboss.org">Alex Loubyansky</a>
- * @version $Revision$
- */
-public class JBossQLParser {
- private Catalog catalog;
- private Class[] argumentTypes;
- private IdentifierManager idManager;
- private boolean selectDistinct;
- private String selectPath;
-
- public ASTEJBQL parse(Catalog catalog, Class[] argumentTypes, String ejbql)
- throws ParseException {
-
- this.catalog = catalog;
- token_source.catalog = catalog;
- this.argumentTypes = argumentTypes;
- token_source.argumentTypes = argumentTypes;
- idManager = new IdentifierManager(catalog);
- token_source.idManager = idManager;
-
- String lowerCase = ejbql.toLowerCase();
- int fromBeginIndex = indexOf(lowerCase, "from");
- if(fromBeginIndex < 0) {
- throw new ParseException("FROM not found");
- }
-
- int fromEndIndex = indexOf(lowerCase, "where");
- ///////////////////// CHANGED //////////////////////////////
- if(fromEndIndex < 0) {
- fromEndIndex = indexOfOrderBy(lowerCase);
- }
- if(fromEndIndex < 0) {
- fromEndIndex = indexOf(lowerCase, "offset");
- }
- if(fromEndIndex < 0) {
- fromEndIndex = indexOf(lowerCase, "limit");
- }
- if(fromEndIndex < 0) {
- fromEndIndex = ejbql.length();
- }
- ////////////////////////////////////////////////////////////
-
- // just the from clause
- char[] from = ejbql.toCharArray();
- clear(from, 0, fromBeginIndex);
- clear(from, fromEndIndex, from.length);
-
- // everything except for the from clause
- char[] sansFrom = ejbql.toCharArray();
- clear(sansFrom, fromBeginIndex + 4, fromEndIndex);
-
- // From clause
- ReInit(new CharArrayReader(from));
- ASTFrom fromNode = ParseFromClause();
-
- // Everything else
- ReInit(new CharArrayReader(sansFrom));
- ASTEJBQL ejbqlNode = EJBQL();
-
- // replace the dummy from clause in the EJBQL
- // node with the real from node
- ejbqlNode.jjtAddChild(fromNode, 1);
-
- return ejbqlNode;
- }
-
- /**
- * Returns the first index of the word (surrounded with whitespaces) in the string
- * or -1 if the word was not found.
- */
- private static final int indexOf(String ql, String word)
- {
- return indexOf(ql, word, 0);
- }
-
- /**
- * Returns the first index of the word (surrounded with whitespaces) in the string
- * starting with startInd position or -1 if the word was not found.
- */
- private static final int indexOf(String ql, String word, int startInd)
- {
- int i = ql.indexOf(word, startInd);
- if(i < 0)
- {
- return -1;
- }
-
- int qlLength = ql.length();
- int wordLength = word.length();
- while(i >= 0)
- {
- int endInd = i + wordLength;
- if((i == 0 || Character.isWhitespace(ql.charAt(i - 1))) &&
- (endInd == qlLength || endInd < qlLength && Character.isWhitespace(ql.charAt(endInd))))
- {
- break;
- }
-
- i = ql.indexOf(word, i + 1);
- }
- return i;
- }
-
- private static final int indexOfOrderBy(String ql)
- {
- int orderInd = indexOf(ql, "order", 0);
- int byInd = -1;
- while(orderInd > 0)
- {
- if(byInd < orderInd)
- {
- byInd = indexOf(ql, "by", orderInd + 5);
- }
-
- if(byInd > 0)
- {
- int i = byInd - 1;
- while(i >= orderInd + 5 && Character.isWhitespace(ql.charAt(i--)));
- if(i == orderInd + 4)
- {
- break;
- }
- else
- {
- orderInd = indexOf(ql, "order", orderInd + 5);
- }
- }
- else
- {
- orderInd = -1;
- }
- }
- return orderInd;
- }
-
- private final void clear(char[] c, int beginIndex, int endIndex) {
- for(int i=beginIndex; i < endIndex; i++) {
- if(c[i]!='\r' && c[i]!='\n' && c[i]!='\t') {
- c[i] = ' ';
- }
- }
- }
-
- private final void initPathNode(ASTPath pathNode, String path, int type) {
- pathNode.pathList = idManager.getPathList(path);
- pathNode.fieldList = idManager.getFieldList(path);
- pathNode.type = type;
- }
-
- private final void initParameterNode(
- ASTParameter parameterNode,
- String number,
- int type) {
-
- parameterNode.number = Integer.parseInt(number);
- parameterNode.type = type;
- }
-}
-
-PARSER_END(JBossQLParser)
-
-////////////////////// New or changed elements /////////////////////////////
-
-ASTEJBQL EJBQL() #EJBQL :
-{}
-{
- SelectClause() FromKeyword() [WhereClause()] [OrderByClause()] [LimitClause()] <EOF>
- { return jjtThis; }
-}
-
-ASTOrderBy OrderByClause() #OrderBy :
-{}
-{
- <ORDER> <BY> OrderByPathExpression() ( <COMMA> OrderByPathExpression() ) *
- { return jjtThis; }
-}
-
-void OrderByPathExpression() #OrderByPath :
-{}
-{
- ( NumericValuedPath() | StringValuedPath() | DatetimeValuedPath() | ValueClassExpression())
- [<ASC> | <DESC> { jjtThis.ascending=false; } ]
-}
-
-void LimitClause() #LimitOffset :
-{}
-{
- <OFFSET> ArithmeticValue() { jjtThis.hasOffset = true; } [<LIMIT> ArithmeticValue() { jjtThis.hasLimit = true; }]
- | <LIMIT> ArithmeticValue() { jjtThis.hasLimit = true; }
-}
-
-////////////////////////////////////////////////////////////////////////////
-
-void FromKeyword() #From :
-{}
-{
- <FROM>
-}
-
-ASTFrom ParseFromClause() #void :
-{ ASTFrom node; }
-{
- node = FromClause() <EOF>
- { return node; }
-}
-
-ASTFrom FromClause() #From :
-{}
-{
- (
- <FROM> IdentificationVariableDeclaration()
- ( <COMMA> IdentificationVariableDeclaration() )*
- ) { return jjtThis; }
-}
-
-void IdentificationVariableDeclaration() #void :
-{}
-{
- (CollectionMemberDeclaration() | RangeVariableDeclaration())
-}
-
-void CollectionMemberDeclaration() :
-{
- Token path;
- Token id;
-}
-{
- ( <IN> <LPAREN> path=CollectionValuedPath() <RPAREN>
- [<AS>] id=Identifier() )
- { idManager.declareCollectionMember(id.image, path.image); }
-}
-
-void RangeVariableDeclaration() :
-{
- Token schema;
- Token id;
-}
-{
- ( schema=AbstractSchema() [<AS>] id=Identifier() )
- { idManager.declareRangeVariable(id.image, schema.image); }
-}
-
-ASTSelect SelectClause() #Select :
-{}
-{
- (
- <SELECT> [<DISTINCT> { jjtThis.distinct=true; }]
- (
- <OBJECT> <LPAREN> IdentificationVariable() <RPAREN> |
- SingleValuedPath() |
- FunctionsAllowedInSelect()
- )
- ) { return jjtThis; }
-}
-
-ASTWhere WhereClause() #Where :
-{}
-{
- <WHERE> WhereExpression()
- { return jjtThis; }
-}
-
-//
-// ASTWhereExpression and ASTWhereConditionalTerm mimic
-// ConditionalExpression and ConditionalTerm.
-// They are added to support joins per WhereConditionalTerm.
-//
-void WhereExpression() #void :
-{}
-{
- (
- WhereConditionalTerm() ( <OR> WhereConditionalTerm() )*
- ) #Or(>1)
-}
-
-ASTWhereConditionalTerm WhereConditionalTerm() #WhereConditionalTerm :
-{}
-{
- (
- ConditionalFactor() ( <AND> ConditionalFactor() )*
- ) #And(>1)
- {return jjtThis;}
-}
-
-void ConditionalExpression() #void :
-{}
-{
- (
- ConditionalTerm() ( <OR> ConditionalTerm() )*
- ) #Or(>1)
-}
-
-void ConditionalTerm() #void :
-{}
-{
- (
- ConditionalFactor() ( <AND> ConditionalFactor() )*
- ) #And(>1)
-}
-
-void ConditionalFactor() #void :
-{ boolean not = false; }
-{
- (
- [<NOT>{ not=true; }] ConditionalTest()
- ) #Not(not)
-}
-
-void ConditionalTest() #void :
-{}
-{
- ConditionalPrimary()
-}
-
-void ConditionalPrimary() #void :
-{}
-{
- LOOKAHEAD(<LPAREN> ConditionalExpression() <RPAREN>)
- (<LPAREN> ConditionalExpression() <RPAREN>) #ConditionalParenthetical
-|
- SimpleCondExpression()
-}
-
-////////////////////// New or changed elements /////////////////////////////
-
-void FunctionsAllowedInSelect() #void :
-{}
-{
- FunctionsReturningNumerics() |
- FunctionsReturningStrings()
-}
-
-void SimpleCondExpression() #void :
-{}
-{
- EmptyCollectionComparisonExpression()
-|
- LOOKAHEAD({ getToken(2).kind==IS })
- NullComparisonExpression()
-|
- LOOKAHEAD({ getToken(2).kind==MEMBER || getToken(3).kind==MEMBER })
- CollectionMemberExpression()
-|
- LOOKAHEAD(StringValue() [<NOT>] <LIKE>)
- LikeExpression()
-|
- LOOKAHEAD((StringValue() | ArithmeticValue() | DatetimeValue()) [<NOT>] <IN>)
- InExpression()
-|
- ComparisonExpression()
-}
-
-void BetweenExpression() #Between :
-{}
-{
- (ArithmeticExpression() [<NOT> { jjtThis.not=true; } ] <BETWEEN>
- ArithmeticExpression() <AND> ArithmeticExpression())
-|
- (DatetimeValue() [<NOT> { jjtThis.not=true; } ] <BETWEEN>
- DatetimeValue() <AND> DatetimeValue())
-|
- (StringValue() [<NOT> { jjtThis.not=true; } ] <BETWEEN>
- StringValue() <AND> StringValue())
-}
-
-void InExpression() #In :
-{}
-{
- (StringExpression() [<NOT> { jjtThis.not=true; } ] <IN>
- <LPAREN> StringExpression() ( <COMMA> StringExpression() )* <RPAREN>)
-|
- (ArithmeticPrimary() [<NOT> { jjtThis.not=true; } ] <IN>
- <LPAREN> ArithmeticPrimary() ( <COMMA> ArithmeticPrimary() )* <RPAREN>)
-|
- (DatetimeValue() [<NOT> { jjtThis.not=true; } ] <IN>
- <LPAREN> DatetimeValue() ( <COMMA> DatetimeValue() )* <RPAREN>)
-}
-
-void LikeExpression() #Like :
-{}
-{
- StringValue() [<NOT> { jjtThis.not=true; } ] <LIKE>
- StringExpression() [<ESCAPE> (StringLiteral() | NumericValuedParameter())]
-}
-
-////////////////////////////////////////////////////////////////////////////
-
-void NullComparisonExpression() #NullComparison :
-{}
-{
- (
- SingleValuedPath() |
- NumericValuedParameter() |
- EntityValuedParameter() |
- StringValuedParameter() |
- DatetimeValuedParameter() |
- BooleanValuedParameter()
- )
- <IS> [<NOT> { jjtThis.not=true; } ] <NULL>
-}
-
-void EmptyCollectionComparisonExpression() #IsEmpty :
-{}
-{
- CollectionValuedPath() <IS> [<NOT> { jjtThis.not=true; } ] <EMPTY>
-}
-
-void CollectionMemberExpression() #MemberOf :
-{}
-{
- (EntityValuedPath() |
- IdentificationVariable() |
- EntityValuedParameter())
- [<NOT> { jjtThis.not=true; } ] <MEMBER> [<OF>] CollectionValuedPath()
-}
-
-
-void ComparisonExpression() #void :
-{}
-{
-////////////////////// New or changed elements /////////////////////////////
- LOOKAHEAD(StringValue() ( <EQ> | <GT> | <GE> | <LT> | <LE> | <NE> ) )
- (
- StringValue()
- (
- <EQ> { jjtThis.opp="="; } |
- <GT> { jjtThis.opp=">"; } |
- <GE> { jjtThis.opp=">="; } |
- <LT> { jjtThis.opp="<"; } |
- <LE> { jjtThis.opp="<="; } |
- <NE> { jjtThis.opp="<>"; }
- )
- StringExpression()
- ) #StringComparison
-////////////////////////////////////////////////////////////////////////////
-|
- LOOKAHEAD(BooleanValue() ( <EQ> | <NE> ) )
- (
- BooleanValue()
- [
- (
- <EQ> { jjtThis.opp="="; } |
- <NE> { jjtThis.opp="<>"; }
- ) BooleanExpression()
- ]
- ) #BooleanComparison
-|
-////////////////////// New or changed elements /////////////////////////////
- LOOKAHEAD(DatetimeValue() ( <EQ> | <GT> | <GE> | <LT> | <LE> | <NE> ) )
- (
- DatetimeValue()
- (
- <EQ> { jjtThis.opp="="; } |
- <GT> { jjtThis.opp=">"; } |
- <GE> { jjtThis.opp=">="; } |
- <LT> { jjtThis.opp="<"; } |
- <LE> { jjtThis.opp="<="; } |
- <NE> { jjtThis.opp="<>"; }
- )
- DatetimeExpression()
- ) #DatetimeComparison
-|
- LOOKAHEAD(ValueClassValue() ( <EQ> | <GT> | <GE> | <LT> | <LE> | <NE> ) )
- (
- ValueClassValue()
- (
- <EQ> { jjtThis.opp="="; } |
- <GT> { jjtThis.opp=">"; } |
- <GE> { jjtThis.opp=">="; } |
- <LT> { jjtThis.opp="<"; } |
- <LE> { jjtThis.opp="<="; } |
- <NE> { jjtThis.opp="<>"; }
- )
- ValueClassExpression()
- ) #ValueClassComparison
-////////////////////////////////////////////////////////////////////////////
-|
- LOOKAHEAD(EntityBeanValue() ( <EQ> | <NE> ) )
- (
- EntityBeanValue()
- (
- <EQ> { jjtThis.opp="="; } |
- <NE> { jjtThis.opp="<>"; }
- )
- EntityBeanExpression()
- ) #EntityComparison
-|
- LOOKAHEAD(ArithmeticValue() ( <EQ> | <GT> | <GE> | <LT> | <LE> | <NE> ) )
- (
- ArithmeticValue()
- (
- <EQ> { jjtThis.opp="="; } |
- <GT> { jjtThis.opp=">"; } |
- <GE> { jjtThis.opp=">="; } |
- <LT> { jjtThis.opp="<"; } |
- <LE> { jjtThis.opp="<="; } |
- <NE> { jjtThis.opp="<>"; }
- )
- SingleValueDesignator()
- ) #ArithmeticComparison
-|
- BetweenExpression()
-}
-
-////////////////////// New or changed elements /////////////////////////////
-void ArithmeticValue() #void :
-{}
-{
- NumericValuedPath() | FunctionsReturningNumerics() |
- NumericLiteral() | NumericValuedParameter()
-}
-////////////////////////////////////////////////////////////////////////////
-
-void SingleValueDesignator() #void :
-{}
-{
- ScalarExpression()
-}
-
-void ScalarExpression() #void :
-{}
-{
- ArithmeticExpression()
-}
-
-void ArithmeticExpression() #void :
-{}
-{
- (
- ArithmeticTerm()
- (
- (
- <PLUS> { jjtThis.addOpp("+"); } |
- <MINUS> { jjtThis.addOpp("-"); }
- ) ArithmeticTerm()
- )*
- ) #PlusMinus(>1)
-}
-
-void ArithmeticTerm() #void :
-{}
-{
- (
- ArithmeticFactor()
- (
- (
- <MULT> { jjtThis.addOpp("*"); } |
- <DIV> { jjtThis.addOpp("/"); }
- ) ArithmeticFactor()
- )*
- ) #MultDiv(>1)
-}
-
-void ArithmeticFactor() #void :
-{ boolean negation = false; }
-{
- (
- [<PLUS>|<MINUS>{negation=true;}] ArithmeticPrimary()
- ) #Negation(negation)
-}
-
-void ArithmeticPrimary() #void :
-{}
-{
- NumericValuedPath() |
- NumericLiteral() |
- (<LPAREN> ArithmeticExpression() <RPAREN>) #ArithmeticParenthetical |
- NumericValuedParameter() |
- FunctionsReturningNumerics()
-}
-
-////////////////////// New or changed elements /////////////////////////////
-void StringValue() #void :
-{}
-{
- StringValuedPath() | FunctionsReturningStrings() |
- StringLiteral()| StringValuedParameter()
-}
-////////////////////////////////////////////////////////////////////////////
-
-void StringExpression() #void :
-{}
-{
- StringPrimary() | StringValuedParameter()
-}
-
-void StringPrimary() #void :
-{}
-{
- StringValuedPath() |
- StringLiteral() |
- (<LPAREN> StringExpression() <RPAREN>) #StringParenthetical |
- FunctionsReturningStrings()
-}
-
-////////////////////// New or changed elements /////////////////////////////
-
-void DatetimeValue() #void :
-{}
-{
- DatetimeValuedPath() | DatetimeValuedParameter()
-}
-
-void DatetimeExpression() #void :
-{}
-{
- DatetimeValue()
-}
-
-void BooleanValue() #void :
-{}
-{
- BooleanValuedPath() | BooleanValuedParameter() | BooleanLiteral()
-}
-
-void BooleanExpression() #void :
-{}
-{
- BooleanValue()
-}
-
-void ValueClassValue() #void :
-{}
-{
- ValueClassValuedPath() | ValueClassValuedParameter()
-}
-
-void ValueClassExpression() #void :
-{}
-{
- ValueClassValue()
-}
-
-
-void EntityBeanValue() #void :
-{}
-{
- EntityValuedPath() | IdentificationVariable() | EntityValuedParameter()
-}
-
-void EntityBeanExpression() #void :
-{}
-{
- EntityBeanValue()
-}
-
-////////////////////////////////////////////////////////////////////////////
-
-void FunctionsReturningStrings() #void :
-{}
-{
- (
- <CONCAT> <LPAREN> StringExpression() <COMMA> StringExpression() <RPAREN>
- ) #Concat
-|
- (
- <SUBSTRING> <LPAREN>
- StringExpression() <COMMA>
- ArithmeticExpression() <COMMA>
- ArithmeticExpression() <RPAREN>
- ) #Substring
-////////////////////// New or changed elements /////////////////////////////
-|
- (
- <UCASE> <LPAREN> StringExpression() <RPAREN>
- ) #UCase
-|
- (
- <LCASE> <LPAREN> StringExpression() <RPAREN>
- ) #LCase
-////////////////////////////////////////////////////////////////////////////
-}
-
-void FunctionsReturningNumerics() #void :
-{}
-{
- (
- <LENGTH> <LPAREN> StringExpression() <RPAREN>
- ) #Length
-|
- (
- <LOCATE> <LPAREN>
- StringExpression() <COMMA> StringExpression()
- [ <COMMA> ArithmeticExpression()] <RPAREN>
- ) #Locate
-|
- (
- <ABS> <LPAREN> ArithmeticExpression() <RPAREN>
- ) #Abs
-|
- (
- <SQRT> <LPAREN> ArithmeticExpression() <RPAREN>
- ) #Sqrt
-|
- (
- <MOD> <LPAREN>
- ArithmeticExpression() <COMMA>
- ArithmeticExpression() <RPAREN>
- ) #Mod
-|
- AggregateFunctions()
-////////////////////////////////////////////////////////////////////////////
-}
-
-void AggregateFunctions() #void:
-{}
-{
- (
- <AVG> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
- ) #Avg
-|
- (
- <MAX> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
- ) #Max
-|
- (
- <MIN> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
- ) #Min
-|
- (
- <SUM> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
- ) #Sum
-|
- (
- <COUNT> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}]
- (
- SingleValuedPath() | EntityBeanValue()
- )
- <RPAREN>
- ) #Count
-}
-
-Token CollectionValuedPath() #Path :
-{ Token t; }
-{
- t=<COLLECTION_VALUED_PATH>
- {
- initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE);
- return t;
- }
-}
-
-Token IdentificationVariable() #Path :
-{ Token t; }
-{
- t=<IDENTIFICATION_VARIABLE>
- {
- t.image = t.image.toLowerCase();
- initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE);
- return t;
- }
-}
-
-Token AbstractSchema() #AbstractSchema :
-{ Token t; }
-{
- t=<ABSTRACT_SCHEMA>
- {
- jjtThis.abstractSchemaName = t.image;
- jjtThis.entity = catalog.getEntityByAbstractSchemaName(t.image);
- return t;
- }
- |
- t=<ORDER>
- {
- jjtThis.abstractSchemaName = t.image;
- jjtThis.entity = catalog.getEntityByAbstractSchemaName(t.image);
- return t;
- }
-}
-
-Token Identifier() #Identifier :
-{ Token t; }
-{
- t=<IDENTIFIER>
- {
- t.image = t.image.toLowerCase();
- jjtThis.identifier = t.image;
- return t;
- }
-}
-
-void SingleValuedPath() #void :
-{}
-{
- NumericValuedPath()
-| StringValuedPath()
-| DatetimeValuedPath()
-| BooleanValuedPath()
-| EntityValuedPath()
-| ValueClassValuedPath()
-}
-
-void NumericValuedPath() #Path :
-{ Token t; }
-{
- t=<NUMERIC_VALUED_PATH>
- { initPathNode(jjtThis, t.image, EJBQLTypes.NUMERIC_TYPE); }
-}
-
-void StringValuedPath() #Path :
-{ Token t; }
-{
- t=<STRING_VALUED_PATH>
- { initPathNode(jjtThis, t.image, EJBQLTypes.STRING_TYPE); }
-}
-
-void DatetimeValuedPath() #Path :
-{ Token t; }
-{
- t=<DATETIME_VALUED_PATH>
- { initPathNode(jjtThis, t.image, EJBQLTypes.DATETIME_TYPE); }
-}
-
-void BooleanValuedPath() #Path :
-{ Token t; }
-{
- t=<BOOLEAN_VALUED_PATH>
- { initPathNode(jjtThis, t.image, EJBQLTypes.BOOLEAN_TYPE); }
-}
-
-void EntityValuedPath() #Path :
-{ Token t; }
-{
- t=<ENTITY_VALUED_PATH>
- { initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE); }
-}
-
-void ValueClassValuedPath() #Path :
-{ Token t; }
-{
- t=<VALUE_CLASS_VALUED_PATH>
- { initPathNode(jjtThis, t.image, EJBQLTypes.VALUE_CLASS_TYPE); }
-}
-
-void NumericValuedParameter() #Parameter :
-{ Token t; }
-{
- t=<NUMERIC_VALUED_PARAMETER>
- { initParameterNode(jjtThis, t.image, EJBQLTypes.NUMERIC_TYPE); }
-}
-
-void StringValuedParameter() #Parameter :
-{ Token t; }
-{
- t=<STRING_VALUED_PARAMETER>
- { initParameterNode(jjtThis, t.image, EJBQLTypes.STRING_TYPE); }
-}
-
-void DatetimeValuedParameter() #Parameter :
-{ Token t; }
-{
- t=<DATETIME_VALUED_PARAMETER>
- { initParameterNode(jjtThis, t.image, EJBQLTypes.DATETIME_TYPE); }
-}
-
-void BooleanValuedParameter() #Parameter :
-{ Token t; }
-{
- t=<BOOLEAN_VALUED_PARAMETER>
- { initParameterNode(jjtThis, t.image, EJBQLTypes.BOOLEAN_TYPE); }
-}
-
-void EntityValuedParameter() #Parameter :
-{ Token t; }
-{
- t=<ENTITY_VALUED_PARAMETER>
- { initParameterNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE); }
-}
-
-void ValueClassValuedParameter() #Parameter :
-{ Token t; }
-{
- t=<VALUE_CLASS_VALUED_PARAMETER>
- { initParameterNode(jjtThis, t.image, EJBQLTypes.VALUE_CLASS_TYPE); }
-}
-
-void NumericLiteral() #void :
-{ Token t; }
-{
- (
- t=<INTEGER_LITERAL> { jjtThis.setValue(t.image); }
- ) #ExactNumericLiteral
-|
- (
- t=<FLOATING_POINT_LITERAL> { jjtThis.setValue(t.image); }
- ) #ApproximateNumericLiteral
-}
-
-void StringLiteral() #StringLiteral :
-{ Token t; }
-{
- t=<STRING_LITERAL>
- { jjtThis.value=t.image; }
-}
-
-void BooleanLiteral() #BooleanLiteral :
-{ Token t; }
-{
- <TRUE> { jjtThis.value=true; } | <FALSE> { jjtThis.value=false; }
-}
-
-/////////////////////////
-// Tokens
-/////////////////////////
-
-TOKEN_MGR_DECLS :
-{
- public Catalog catalog;
- public Class[] argumentTypes;
- public IdentifierManager idManager;
-
- // used for navigation building
- private List pathList;
- private List fieldList;
- private String path;
-
- private void resetPath() {
- path = "";
- pathList = new ArrayList();
- fieldList = new ArrayList();
- }
-
- private void throwUnknownPath(
- String reason,
- String fieldName) {
-
- throw new UnknownPathException(
- reason,
- path,
- fieldName,
- input_stream.getEndLine(),
- input_stream.getEndColumn());
- }
-
- private void addPath(String nav) {
- String fieldName = nav.substring(0, nav.length()-1);
- if(fieldList.size() > 0) {
- FieldBridge field = getCurrentSchema().getFieldByName(fieldName);
- if(field == null) {
- throwUnknownPath("Unknown cmr field in path", fieldName);
- }
- if(!(field instanceof CMRFieldBridge)) {
- throwUnknownPath("In path field is not a cmr field", fieldName);
- }
-
- CMRFieldBridge cmrField = (CMRFieldBridge)field;
- if(!cmrField.isSingleValued()) {
- throwUnknownPath("In path cmr field is collection valued",
- fieldName);
- }
- fieldList.add(cmrField);
- } else {
- EntityBridge entityBridge = idManager.getEntity(fieldName);
- if(entityBridge == null) {
- throwUnknownPath("Unknown initial identifier", fieldName);
- }
- fieldList.add(entityBridge);
- }
- pathList.add(path + fieldName);
- path += nav;
- }
-
- private EntityBridge getCurrentSchema() {
- Object lastElement = fieldList.get(fieldList.size()-1);
- if(lastElement instanceof EntityBridge) {
- return (EntityBridge)lastElement;
- } else if(lastElement instanceof CMRFieldBridge) {
- return ((CMRFieldBridge)lastElement).getRelatedEntity();
- }
- // should never happen
- throw new IllegalStateException("Unknown path element type: " +
- lastElement);
- }
-}
-
-<DEFAULT> SKIP :
-{
- " "
-| "\t"
-| "\n"
-| "\r"
-}
-
-<DEFAULT> TOKEN [IGNORE_CASE] : /* RESERVED WORDS */
-{
- < ABS: "ABS" >
-| < AND: "AND" >
-| < AS: "AS" >
-| < BETWEEN: "BETWEEN" >
-| < CONCAT: "CONCAT" >
-| < COUNT: "COUNT" >
-| < MAX: "MAX" >
-| < MIN: "MIN" >
-| < AVG: "AVG" >
-| < SUM: "SUM" >
-| < DISTINCT: "DISTINCT" >
-| < EMPTY: "EMPTY" >
-| < ESCAPE: "ESCAPE" >
-| < FROM: "FROM" >
-| < IN: "IN" >
-| < IS: "IS" >
-| < LENGTH: "LENGTH" >
-| < LIKE: "LIKE" >
-| < LOCATE: "LOCATE" >
-| < NOT: "NOT" >
-| < NULL: "NULL" >
-| < OBJECT: "OBJECT" >
-| < OF: "OF " >
-| < OR: "OR" >
-| < SELECT: "SELECT" >
-| < SUBSTRING: "SUBSTRING" >
-| < SQRT: "SQRT" >
-| < UNKNOWN: "UNKNOWN" >
-| < WHERE: "WHERE" >
-| < MEMBER: "MEMBER" >
-| < ASC: "ASC" >
-| < DESC: "DESC" >
-| < LCASE: "LCASE" >
-| < LIMIT: "LIMIT" >
-| < OFFSET: "OFFSET" >
-| < ORDER: "ORDER" >
-| < BY: "BY" >
-| < UCASE: "UCASE" >
-| < MOD: "MOD" >
-}
-
-<DEFAULT> TOKEN : /* SEPARATORS */
-{
- < LPAREN: "(" >
-| < RPAREN: ")" >
-| < COMMA: "," >
-| < DOT: "." >
-}
-
-<DEFAULT> TOKEN : /* OPERATORS */
-{
- < GT: ">" >
-| < LT: "<" >
-| < EQ: "=" >
-| < LE: "<=" >
-| < GE: ">=" >
-| < NE: "<>" >
-| < PLUS: "+" >
-| < MINUS: "-" >
-| < MULT: "*" >
-| < DIV: "/" >
-}
-
-<DEFAULT> TOKEN : /* String Literal */
-{
- < STRING_LITERAL: "'" (~["'"])* ( "''" (~["'"])* )* "'" >
-}
-
-<DEFAULT> TOKEN : /* Numeric Literal */
-{
- < INTEGER_LITERAL:
- <DECIMAL_LITERAL> (["l","L"])?
- | <HEX_LITERAL> (["l","L"])?
- | <OCTAL_LITERAL> (["l","L"])?
- >
-|
- < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
-|
- < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
-|
- < #OCTAL_LITERAL: "0" (["0"-"7"])* >
-|
- < FLOATING_POINT_LITERAL:
- (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
- | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
- | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
- | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
- >
-|
- < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
-}
-
-<DEFAULT> TOKEN [IGNORE_CASE] : /* Boolean Literal */
-{
- < FALSE: "FALSE" >
-| < TRUE: "TRUE" >
-}
-
-<DEFAULT> TOKEN : /* IDENTIFIERS */
-{
- < IDENTIFIER: <NAME> >
- {
- if(catalog.getEntityByAbstractSchemaName(matchedToken.image) != null) {
- matchedToken.kind = ABSTRACT_SCHEMA;
- } else if(idManager.getEntity(matchedToken.image.toLowerCase()) != null) {
- matchedToken.kind = IDENTIFICATION_VARIABLE;
- matchedToken.image = matchedToken.image.toLowerCase();
-
- List pathList = new ArrayList();
- pathList.add(matchedToken.image);
- List fieldList = new ArrayList();
- fieldList.add(idManager.getEntity(matchedToken.image));
- idManager.registerPath(matchedToken.image, pathList, fieldList);
- }
- }
-|
- < ABSTRACT_SCHEMA: [] >
-|
- < IDENTIFICATION_VARIABLE: [] >
-|
- < #NAME: <LETTER> (<LETTER>|<DIGIT>)* >
-|
- < #LETTER:
- [
- "\u0024",
- "\u0041"-"\u005a",
- "\u005f",
- "\u0061"-"\u007a",
- "\u00c0"-"\u00d6",
- "\u00d8"-"\u00f6",
- "\u00f8"-"\u00ff",
- "\u0100"-"\u1fff",
- "\u3040"-"\u318f",
- "\u3300"-"\u337f",
- "\u3400"-"\u3d2d",
- "\u4e00"-"\u9fff",
- "\uf900"-"\ufaff"
- ]
- >
-|
- < #DIGIT:
- [
- "\u0030"-"\u0039",
- "\u0660"-"\u0669",
- "\u06f0"-"\u06f9",
- "\u0966"-"\u096f",
- "\u09e6"-"\u09ef",
- "\u0a66"-"\u0a6f",
- "\u0ae6"-"\u0aef",
- "\u0b66"-"\u0b6f",
- "\u0be7"-"\u0bef",
- "\u0c66"-"\u0c6f",
- "\u0ce6"-"\u0cef",
- "\u0d66"-"\u0d6f",
- "\u0e50"-"\u0e59",
- "\u0ed0"-"\u0ed9",
- "\u1040"-"\u1049"
- ]
- >
-}
-
-<DEFAULT> TOKEN : /* PARAMETERS */
-{
- < UNKNOWN_PARAMETER: "?" <INTEGER_LITERAL> >
- {
- int n = EJBQLTypes.UNKNOWN_TYPE;
- try {
- n = Integer.parseInt(matchedToken.image.substring(1, lengthOfMatch));
- } catch(Exception e) { /* Should never come here. */ }
-
- matchedToken.image = "" + n;
-
- // zero base the index
- n--;
-
- if(n < argumentTypes.length) {
- switch(EJBQLTypes.getEJBQLType(argumentTypes[n])) {
- case EJBQLTypes.NUMERIC_TYPE:
- matchedToken.kind = NUMERIC_VALUED_PARAMETER;
- break;
- case EJBQLTypes.STRING_TYPE:
- matchedToken.kind = STRING_VALUED_PARAMETER;
- break;
- case EJBQLTypes.DATETIME_TYPE:
- matchedToken.kind = DATETIME_VALUED_PARAMETER;
- break;
- case EJBQLTypes.BOOLEAN_TYPE:
- matchedToken.kind = BOOLEAN_VALUED_PARAMETER;
- break;
- case EJBQLTypes.ENTITY_TYPE:
- matchedToken.kind = ENTITY_VALUED_PARAMETER;
- break;
- case EJBQLTypes.VALUE_CLASS_TYPE:
- matchedToken.kind = VALUE_CLASS_VALUED_PARAMETER;
- break;
- }
- }
- }
-| < NUMERIC_VALUED_PARAMETER: [] >
-| < STRING_VALUED_PARAMETER: [] >
-| < DATETIME_VALUED_PARAMETER: [] >
-| < BOOLEAN_VALUED_PARAMETER: [] >
-| < ENTITY_VALUED_PARAMETER: [] >
-| < VALUE_CLASS_VALUED_PARAMETER: [] >
-}
-
-/**
- * WARNING: Be careful here. If look ahead is to high in the from clause, it
- * is possible that the identification varible is not registered before it
- * is used here.
- */
-<DEFAULT> SPECIAL_TOKEN : /* Navigation */
-{
- < <NAME> <DOT> > {
- resetPath();
- addPath(matchedToken.image.toLowerCase());
- } : IN_NAVIGATION
-}
-
-<IN_NAVIGATION> SPECIAL_TOKEN :
-{
- < <NAME> <DOT> > { addPath(matchedToken.image); } : IN_NAVIGATION
-}
-
-<IN_NAVIGATION> TOKEN :
-{
- < PART: <NAME> > {
- String fieldName = matchedToken.image;
- matchedToken.image = path + fieldName;
-
- FieldBridge field = getCurrentSchema().getFieldByName(fieldName);
- if(field == null) {
- throwUnknownPath("Unknown terminal field", fieldName);
- }
- if(field instanceof CMPFieldBridge) {
- CMPFieldBridge cmpField = (CMPFieldBridge)field;
- switch(EJBQLTypes.getEJBQLType(cmpField.getFieldType())) {
- case EJBQLTypes.NUMERIC_TYPE:
- matchedToken.kind = NUMERIC_VALUED_PATH;
- break;
- case EJBQLTypes.STRING_TYPE:
- matchedToken.kind = STRING_VALUED_PATH;
- break;
- case EJBQLTypes.DATETIME_TYPE:
- matchedToken.kind = DATETIME_VALUED_PATH;
- break;
- case EJBQLTypes.BOOLEAN_TYPE:
- matchedToken.kind = BOOLEAN_VALUED_PATH;
- break;
- case EJBQLTypes.ENTITY_TYPE:
- matchedToken.kind = ENTITY_VALUED_PATH;
- break;
- case EJBQLTypes.VALUE_CLASS_TYPE:
- matchedToken.kind = VALUE_CLASS_VALUED_PATH;
- break;
- default:
- throwUnknownPath("Unknown cmp field type", fieldName);
- }
- } else {
- CMRFieldBridge cmrField = (CMRFieldBridge)field;
- if(cmrField.isSingleValued()) {
- matchedToken.kind = ENTITY_VALUED_PATH;
- } else {
- matchedToken.kind = COLLECTION_VALUED_PATH;
- }
- }
- pathList.add(matchedToken.image);
- fieldList.add(field);
- idManager.registerPath(matchedToken.image, pathList, fieldList);
- resetPath();
- } : DEFAULT
-| < NUMERIC_VALUED_PATH: [] >
-| < STRING_VALUED_PATH: [] >
-| < DATETIME_VALUED_PATH: [] >
-| < BOOLEAN_VALUED_PATH: [] >
-| < ENTITY_VALUED_PATH: [] >
-| < VALUE_CLASS_VALUED_PATH: [] >
-| < UNKNOWN_PATH: [] >
-| < COLLECTION_VALUED_PATH: [] >
-}
-
-
Copied: trunk/server/src/main/jjtree/org/jboss/ejb/plugins/cmp/ejbql/EJBQLParser.jjt (from rev 94157, trunk/server/src/main/java/org/jboss/ejb/plugins/cmp/ejbql/EJBQLParser.jjt)
===================================================================
--- trunk/server/src/main/jjtree/org/jboss/ejb/plugins/cmp/ejbql/EJBQLParser.jjt (rev 0)
+++ trunk/server/src/main/jjtree/org/jboss/ejb/plugins/cmp/ejbql/EJBQLParser.jjt 2009-09-30 19:05:48 UTC (rev 94178)
@@ -0,0 +1,1235 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+options {
+ BUILD_NODE_FILES=false;
+ MULTI=true;
+
+ JAVA_UNICODE_ESCAPE = true;
+ STATIC = false;
+
+ CHOICE_AMBIGUITY_CHECK = 5;
+ OTHER_AMBIGUITY_CHECK = 5;
+
+ LOOKAHEAD = 1;
+ DEBUG_PARSER = false;
+ DEBUG_LOOKAHEAD = false;
+ DEBUG_TOKEN_MANAGER = false;
+ ERROR_REPORTING = true;
+ UNICODE_INPUT = false;
+ IGNORE_CASE = false;
+ USER_TOKEN_MANAGER = false;
+ USER_CHAR_STREAM = false;
+ BUILD_PARSER = true;
+ BUILD_TOKEN_MANAGER = true;
+ SANITY_CHECK = true;
+ FORCE_LA_CHECK = false;
+}
+
+PARSER_BEGIN(EJBQLParser)
+package org.jboss.ejb.plugins.cmp.ejbql;
+
+import java.io.CharArrayReader;
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.ejb.plugins.cmp.bridge.EntityBridge;
+import org.jboss.ejb.plugins.cmp.bridge.CMPFieldBridge;
+import org.jboss.ejb.plugins.cmp.bridge.CMRFieldBridge;
+import org.jboss.ejb.plugins.cmp.bridge.FieldBridge;
+
+/**
+ * This class parses EJB-QL into an abstract syntax tree.
+ *
+ * @author <a href="mailto:dain at daingroup.com">Dain Sundstrom</a>
+ * @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
+ * @version $Revision$
+ */
+public class EJBQLParser {
+ private Catalog catalog;
+ private Class[] argumentTypes;
+ private IdentifierManager idManager;
+ private boolean selectDistinct;
+ private String selectPath;
+
+ public ASTEJBQL parse(Catalog catalog, Class[] argumentTypes, String ejbql)
+ throws ParseException {
+
+ this.catalog = catalog;
+ token_source.catalog = catalog;
+ this.argumentTypes = argumentTypes;
+ token_source.argumentTypes = argumentTypes;
+ idManager = new IdentifierManager(catalog);
+ token_source.idManager = idManager;
+
+ String lowerCase = ejbql.toLowerCase();
+ int fromBeginIndex = indexOf(lowerCase, "from");
+ if(fromBeginIndex < 0) {
+ throw new ParseException("FROM not found");
+ }
+
+ int fromEndIndex = indexOf(lowerCase, "where");
+ if(fromEndIndex < 0) {
+ fromEndIndex = indexOfOrderBy(lowerCase);
+ }
+ if(fromEndIndex < 0) {
+ fromEndIndex = ejbql.length();
+ }
+
+ // just the from clause
+ char[] from = ejbql.toCharArray();
+ clear(from, 0, fromBeginIndex);
+ clear(from, fromEndIndex, from.length);
+
+ // everything except for the from clause
+ char[] sansFrom = ejbql.toCharArray();
+ clear(sansFrom, fromBeginIndex + 4, fromEndIndex);
+
+ // From clause
+ ReInit(new CharArrayReader(from));
+ ASTFrom fromNode = ParseFromClause();
+
+ // Everything else
+ ReInit(new CharArrayReader(sansFrom));
+ ASTEJBQL ejbqlNode = EJBQL();
+
+ // replace the dummy from clause in the EJBQL
+ // node with the real from node
+ ejbqlNode.jjtAddChild(fromNode, 1);
+
+ return ejbqlNode;
+ }
+
+ /**
+ * Returns the first index of the word (surrounded with whitespaces) in the string
+ * or -1 if the word was not found.
+ */
+ private static final int indexOf(String ql, String word)
+ {
+ return indexOf(ql, word, 0);
+ }
+
+ /**
+ * Returns the first index of the word (surrounded with whitespaces) in the string
+ * starting with startInd position or -1 if the word was not found.
+ */
+ private static final int indexOf(String ql, String word, int startInd)
+ {
+ int i = ql.indexOf(word, startInd);
+ if(i < 0)
+ {
+ return -1;
+ }
+
+ int qlLength = ql.length();
+ int wordLength = word.length();
+ while(i >= 0)
+ {
+ int endInd = i + wordLength;
+ if((i == 0 || Character.isWhitespace(ql.charAt(i - 1))) &&
+ (endInd == qlLength || endInd < qlLength && Character.isWhitespace(ql.charAt(endInd))))
+ {
+ break;
+ }
+
+ i = ql.indexOf(word, i + 1);
+ }
+ return i;
+ }
+
+ private static final int indexOfOrderBy(String ql)
+ {
+ int orderInd = indexOf(ql, "order", 0);
+ int byInd = -1;
+ while(orderInd > 0)
+ {
+ if(byInd < orderInd)
+ {
+ byInd = indexOf(ql, "by", orderInd + 5);
+ }
+
+ if(byInd > 0)
+ {
+ int i = byInd - 1;
+ while(i >= orderInd + 5 && Character.isWhitespace(ql.charAt(i--)));
+ if(i == orderInd + 4)
+ {
+ break;
+ }
+ else
+ {
+ orderInd = indexOf(ql, "order", orderInd + 5);
+ }
+ }
+ else
+ {
+ orderInd = -1;
+ }
+ }
+ return orderInd;
+ }
+
+ private final void clear(char[] c, int beginIndex, int endIndex) {
+ for(int i=beginIndex; i < endIndex; i++) {
+ if(c[i]!='\r' && c[i]!='\n' && c[i]!='\t') {
+ c[i] = ' ';
+ }
+ }
+ }
+
+ private final void initPathNode(ASTPath pathNode, String path, int type) {
+ pathNode.pathList = idManager.getPathList(path);
+ pathNode.fieldList = idManager.getFieldList(path);
+ pathNode.type = type;
+ }
+
+ private final void initParameterNode(
+ ASTParameter parameterNode,
+ String number,
+ int type) {
+
+ parameterNode.number = Integer.parseInt(number);
+ parameterNode.type = type;
+ }
+}
+
+PARSER_END(EJBQLParser)
+
+ASTEJBQL EJBQL() #EJBQL :
+{}
+{
+ SelectClause() FromKeyword() [WhereClause()] [OrderByClause()] <EOF>
+ { return jjtThis; }
+}
+
+ASTOrderBy OrderByClause() #OrderBy :
+{}
+{
+ <ORDER> <BY> OrderByPathExpression() ( <COMMA> OrderByPathExpression() ) *
+ { return jjtThis; }
+}
+
+void OrderByPathExpression() #OrderByPath :
+{}
+{
+ ( NumericValuedPath() | StringValuedPath() | DatetimeValuedPath() )
+ [<ASC> | <DESC> { jjtThis.ascending=false; } ]
+}
+
+void FromKeyword() #From :
+{}
+{
+ <FROM>
+}
+
+ASTFrom ParseFromClause() #void :
+{ ASTFrom node; }
+{
+ node = FromClause() <EOF>
+ { return node; }
+}
+
+ASTFrom FromClause() #From :
+{}
+{
+ (
+ <FROM> IdentificationVariableDeclaration()
+ ( <COMMA> IdentificationVariableDeclaration() )*
+ ) { return jjtThis; }
+}
+
+void IdentificationVariableDeclaration() #void :
+{}
+{
+ (CollectionMemberDeclaration() | RangeVariableDeclaration())
+}
+
+void CollectionMemberDeclaration() :
+{
+ Token path;
+ Token id;
+}
+{
+ ( <IN> <LPAREN> path=CollectionValuedPath() <RPAREN>
+ [<AS>] id=Identifier() )
+ { idManager.declareCollectionMember(id.image, path.image); }
+}
+
+void RangeVariableDeclaration() :
+{
+ Token schema;
+ Token id;
+}
+{
+ ( schema=AbstractSchema() [<AS>] id=Identifier() )
+ { idManager.declareRangeVariable(id.image, schema.image); }
+}
+
+ASTSelect SelectClause() #Select :
+{}
+{
+ (
+ <SELECT> [<DISTINCT> { jjtThis.distinct=true; }]
+ (
+ <OBJECT> <LPAREN> IdentificationVariable() <RPAREN> |
+ SelectExpression()
+ )
+ ) { return jjtThis; }
+}
+
+void SelectExpression() #void :
+{}
+{
+ SingleValuedPath() | AggregateSelectExpression()
+}
+
+ASTWhere WhereClause() #Where :
+{}
+{
+ <WHERE> WhereExpression()
+ { return jjtThis; }
+}
+
+//
+// ASTWhereExpression and ASTWhereConditionalTerm mimic
+// ConditionalExpression and ConditionalTerm.
+// They are added to support joins per WhereConditionalTerm.
+//
+void WhereExpression() #void :
+{}
+{
+ (
+ WhereConditionalTerm() ( <OR> WhereConditionalTerm() )*
+ ) #Or(>1)
+}
+
+ASTWhereConditionalTerm WhereConditionalTerm() #WhereConditionalTerm :
+{}
+{
+ (
+ ConditionalFactor() ( <AND> ConditionalFactor() )*
+ ) #And(>1)
+ {return jjtThis;}
+}
+
+void ConditionalExpression() #void :
+{}
+{
+ (
+ ConditionalTerm() ( <OR> ConditionalTerm() )*
+ ) #Or(>1)
+}
+
+void ConditionalTerm() #void :
+{}
+{
+ (
+ ConditionalFactor() ( <AND> ConditionalFactor() )*
+ ) #And(>1)
+}
+
+void ConditionalFactor() #void :
+{ boolean not = false; }
+{
+ (
+ [<NOT>{ not=true; }] ConditionalTest()
+ ) #Not(not)
+}
+
+void ConditionalTest() #void :
+{}
+{
+ ConditionalPrimary()
+}
+
+void ConditionalPrimary() #void :
+{}
+{
+ LOOKAHEAD(<LPAREN> ConditionalExpression() <RPAREN>)
+ (<LPAREN> ConditionalExpression() <RPAREN>) #ConditionalParenthetical
+|
+ SimpleCondExpression()
+}
+
+void SimpleCondExpression() #void :
+{}
+{
+ EmptyCollectionComparisonExpression()
+|
+ LOOKAHEAD({ getToken(2).kind==IS })
+ NullComparisonExpression()
+|
+ LOOKAHEAD({ getToken(2).kind==MEMBER || getToken(3).kind==MEMBER })
+ CollectionMemberExpression()
+|
+ LOOKAHEAD({ getToken(2).kind==LIKE || getToken(3).kind==LIKE })
+ LikeExpression()
+|
+ LOOKAHEAD({ getToken(2).kind==IN || getToken(3).kind==IN })
+ InExpression()
+|
+ ComparisonExpression()
+}
+
+void BetweenExpression() #Between :
+{}
+{
+ ArithmeticExpression() [<NOT> { jjtThis.not=true; } ] <BETWEEN>
+ ArithmeticExpression() <AND> ArithmeticExpression()
+}
+
+void InExpression() #In :
+{}
+{
+ (StringExpression() [<NOT> { jjtThis.not=true; } ] <IN>
+ <LPAREN> StringExpression() ( <COMMA> StringExpression() )* <RPAREN>)
+|
+ (ArithmeticPrimary() [<NOT> { jjtThis.not=true; } ] <IN>
+ <LPAREN> ArithmeticPrimary() ( <COMMA> ArithmeticPrimary() )* <RPAREN>)
+}
+
+void LikeExpression() #Like :
+{}
+{
+ StringValuedPath() [<NOT> { jjtThis.not=true; } ] <LIKE>
+ StringExpression() [<ESCAPE> (StringLiteral() | NumericValuedParameter())]
+}
+
+void NullComparisonExpression() #NullComparison :
+{}
+{
+ (
+ SingleValuedPath() |
+ NumericValuedParameter() |
+ EntityValuedParameter() |
+ StringValuedParameter() |
+ DatetimeValuedParameter() |
+ BooleanValuedParameter()
+ )
+ <IS> [<NOT> { jjtThis.not=true; } ] <NULL>
+}
+
+void EmptyCollectionComparisonExpression() #IsEmpty :
+{}
+{
+ CollectionValuedPath() <IS> [<NOT> { jjtThis.not=true; } ] <EMPTY>
+}
+
+void CollectionMemberExpression() #MemberOf :
+{}
+{
+ (EntityValuedPath() |
+ IdentificationVariable() |
+ EntityValuedParameter())
+ [<NOT> { jjtThis.not=true; } ] <MEMBER> [<OF>] CollectionValuedPath()
+}
+
+
+void ComparisonExpression() #void :
+{}
+{
+ (
+ StringValue()
+ (
+ <EQ> { jjtThis.opp="="; } |
+ <GT> { jjtThis.opp=">"; } |
+ <GE> { jjtThis.opp=">="; } |
+ <LT> { jjtThis.opp="<"; } |
+ <LE> { jjtThis.opp="<="; } |
+ <NE> { jjtThis.opp="<>"; }
+ )
+ StringExpression()
+ ) #StringComparison
+|
+ (
+ BooleanValue()
+ [
+ (
+ <EQ> { jjtThis.opp="="; } |
+ <NE> { jjtThis.opp="<>"; }
+ ) BooleanExpression()
+ ]
+ ) #BooleanComparison
+|
+ (
+ DatetimeValue()
+ (
+ <EQ> { jjtThis.opp="="; } |
+ <GT> { jjtThis.opp=">"; } |
+ <LT> { jjtThis.opp="<"; } |
+ <NE> { jjtThis.opp="<>"; } |
+ <GE> { jjtThis.opp=">="; } |
+ <LE> { jjtThis.opp="<="; }
+ )
+ DatetimeExpression()
+ ) #DatetimeComparison
+|
+ (
+ EntityBeanValue()
+ (
+ <EQ> { jjtThis.opp="="; } |
+ <NE> { jjtThis.opp="<>"; }
+ )
+ EntityBeanExpression()
+ ) #EntityComparison
+|
+ LOOKAHEAD(ArithmeticValue() ( <EQ> | <GT> | <GE> | <LT> | <LE> | <NE> ) )
+ (
+ ArithmeticValue()
+ (
+ <EQ> { jjtThis.opp="="; } |
+ <GT> { jjtThis.opp=">"; } |
+ <GE> { jjtThis.opp=">="; } |
+ <LT> { jjtThis.opp="<"; } |
+ <LE> { jjtThis.opp="<="; } |
+ <NE> { jjtThis.opp="<>"; }
+ )
+ SingleValueDesignator()
+ ) #ArithmeticComparison
+|
+ BetweenExpression()
+}
+
+void ArithmeticValue() #void :
+{}
+{
+ NumericValuedPath() | FunctionsReturningNumerics()
+}
+
+void SingleValueDesignator() #void :
+{}
+{
+ ScalarExpression()
+}
+
+void ScalarExpression() #void :
+{}
+{
+ ArithmeticExpression()
+}
+
+void ArithmeticExpression() #void :
+{}
+{
+ (
+ ArithmeticTerm()
+ (
+ (
+ <PLUS> { jjtThis.addOpp("+"); } |
+ <MINUS> { jjtThis.addOpp("-"); }
+ ) ArithmeticTerm()
+ )*
+ ) #PlusMinus(>1)
+}
+
+void ArithmeticTerm() #void :
+{}
+{
+ (
+ ArithmeticFactor()
+ (
+ (
+ <MULT> { jjtThis.addOpp("*"); } |
+ <DIV> { jjtThis.addOpp("/"); }
+ ) ArithmeticFactor()
+ )*
+ ) #MultDiv(>1)
+}
+
+void ArithmeticFactor() #void :
+{ boolean negation = false; }
+{
+ (
+ [<PLUS>|<MINUS>{negation=true;}] ArithmeticPrimary()
+ ) #Negation(negation)
+}
+
+void ArithmeticPrimary() #void :
+{}
+{
+ NumericValuedPath() |
+ NumericLiteral() |
+ (<LPAREN> ArithmeticExpression() <RPAREN>) #ArithmeticParenthetical |
+ NumericValuedParameter() |
+ FunctionsReturningNumerics()
+}
+
+void StringValue() #void :
+{}
+{
+ StringValuedPath() | FunctionsReturningStrings()
+}
+
+void StringExpression() #void :
+{}
+{
+ StringPrimary() | StringValuedParameter()
+}
+
+void StringPrimary() #void :
+{}
+{
+ StringValuedPath() |
+ StringLiteral() |
+ (<LPAREN> StringExpression() <RPAREN>) #StringParenthetical |
+ FunctionsReturningStrings()
+}
+
+void DatetimeValue() #void :
+{}
+{
+ DatetimeValuedPath()
+}
+
+void DatetimeExpression() #void :
+{}
+{
+ DatetimeValue() | DatetimeValuedParameter()
+}
+
+void BooleanValue() #void :
+{}
+{
+ BooleanValuedPath()
+}
+
+void BooleanExpression() #void :
+{}
+{
+ BooleanValue() | BooleanValuedParameter() | BooleanLiteral()
+}
+
+void EntityBeanValue() #void :
+{}
+{
+ EntityValuedPath() | IdentificationVariable()
+}
+
+void EntityBeanExpression() #void :
+{}
+{
+ EntityBeanValue() | EntityValuedParameter()
+}
+
+void FunctionsReturningStrings() #void :
+{}
+{
+ (
+ <CONCAT> <LPAREN> StringExpression() <COMMA> StringExpression() <RPAREN>
+ ) #Concat
+|
+ (
+ <SUBSTRING> <LPAREN>
+ StringExpression() <COMMA>
+ ArithmeticExpression() <COMMA>
+ ArithmeticExpression() <RPAREN>
+ ) #Substring
+}
+
+void FunctionsReturningNumerics() #void :
+{}
+{
+ (
+ <LENGTH> <LPAREN> StringExpression() <RPAREN>
+ ) #Length
+|
+ (
+ <LOCATE> <LPAREN>
+ StringExpression() <COMMA> StringExpression()
+ [ <COMMA> ArithmeticExpression()] <RPAREN>
+ ) #Locate
+|
+ (
+ <ABS> <LPAREN> ArithmeticExpression() <RPAREN>
+ ) #Abs
+|
+ (
+ <SQRT> <LPAREN> ArithmeticExpression() <RPAREN>
+ ) #Sqrt
+|
+ (
+ <MOD> <LPAREN> ArithmeticExpression() <COMMA> ArithmeticExpression() <RPAREN>
+ ) #Mod
+}
+
+Token CollectionValuedPath() #Path :
+{ Token t; }
+{
+ t=<COLLECTION_VALUED_PATH>
+ {
+ initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE);
+ return t;
+ }
+}
+
+Token IdentificationVariable() #Path :
+{ Token t; }
+{
+ t=<IDENTIFICATION_VARIABLE>
+ {
+ t.image = t.image.toLowerCase();
+ initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE);
+ return t;
+ }
+}
+
+Token AbstractSchema() #AbstractSchema :
+{ Token t; }
+{
+ t=<ABSTRACT_SCHEMA>
+ {
+ jjtThis.abstractSchemaName = t.image;
+ jjtThis.entity = catalog.getEntityByAbstractSchemaName(t.image);
+ return t;
+ }
+ |
+ t=<ORDER>
+ {
+ jjtThis.abstractSchemaName = t.image;
+ jjtThis.entity = catalog.getEntityByAbstractSchemaName(t.image);
+ return t;
+ }
+}
+
+Token Identifier() #Identifier :
+{ Token t; }
+{
+ t=<IDENTIFIER>
+ {
+ t.image = t.image.toLowerCase();
+ jjtThis.identifier = t.image;
+ return t;
+ }
+}
+
+void SingleValuedPath() #void :
+{}
+{
+ NumericValuedPath()
+| StringValuedPath()
+| DatetimeValuedPath()
+| BooleanValuedPath()
+| EntityValuedPath()
+| ValueClassValuedPath()
+}
+
+void NumericValuedPath() #Path :
+{ Token t; }
+{
+ t=<NUMERIC_VALUED_PATH>
+ { initPathNode(jjtThis, t.image, EJBQLTypes.NUMERIC_TYPE); }
+}
+
+void StringValuedPath() #Path :
+{ Token t; }
+{
+ t=<STRING_VALUED_PATH>
+ { initPathNode(jjtThis, t.image, EJBQLTypes.STRING_TYPE); }
+}
+
+void DatetimeValuedPath() #Path :
+{ Token t; }
+{
+ t=<DATETIME_VALUED_PATH>
+ { initPathNode(jjtThis, t.image, EJBQLTypes.DATETIME_TYPE); }
+}
+
+void BooleanValuedPath() #Path :
+{ Token t; }
+{
+ t=<BOOLEAN_VALUED_PATH>
+ { initPathNode(jjtThis, t.image, EJBQLTypes.BOOLEAN_TYPE); }
+}
+
+void EntityValuedPath() #Path :
+{ Token t; }
+{
+ t=<ENTITY_VALUED_PATH>
+ { initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE); }
+}
+
+void ValueClassValuedPath() #Path :
+{ Token t; }
+{
+ t=<VALUE_CLASS_VALUED_PATH>
+ { initPathNode(jjtThis, t.image, EJBQLTypes.VALUE_CLASS_TYPE); }
+}
+
+void NumericValuedParameter() #Parameter :
+{ Token t; }
+{
+ t=<NUMERIC_VALUED_PARAMETER>
+ { initParameterNode(jjtThis, t.image, EJBQLTypes.NUMERIC_TYPE); }
+}
+
+void StringValuedParameter() #Parameter :
+{ Token t; }
+{
+ t=<STRING_VALUED_PARAMETER>
+ { initParameterNode(jjtThis, t.image, EJBQLTypes.STRING_TYPE); }
+}
+
+void DatetimeValuedParameter() #Parameter :
+{ Token t; }
+{
+ t=<DATETIME_VALUED_PARAMETER>
+ { initParameterNode(jjtThis, t.image, EJBQLTypes.DATETIME_TYPE); }
+}
+
+void BooleanValuedParameter() #Parameter :
+{ Token t; }
+{
+ t=<BOOLEAN_VALUED_PARAMETER>
+ { initParameterNode(jjtThis, t.image, EJBQLTypes.BOOLEAN_TYPE); }
+}
+
+void EntityValuedParameter() #Parameter :
+{ Token t; }
+{
+ t=<ENTITY_VALUED_PARAMETER>
+ { initParameterNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE); }
+}
+
+void ValueClassValuedParameter() #Parameter :
+{ Token t; }
+{
+ t=<VALUE_CLASS_VALUED_PARAMETER>
+ { initParameterNode(jjtThis, t.image, EJBQLTypes.VALUE_CLASS_TYPE); }
+}
+
+void NumericLiteral() #void :
+{ Token t; }
+{
+ (
+ t=<INTEGER_LITERAL> { jjtThis.setValue(t.image); }
+ ) #ExactNumericLiteral
+|
+ (
+ t=<FLOATING_POINT_LITERAL> { jjtThis.setValue(t.image); }
+ ) #ApproximateNumericLiteral
+}
+
+void StringLiteral() #StringLiteral :
+{ Token t; }
+{
+ t=<STRING_LITERAL>
+ { jjtThis.value=t.image; }
+}
+
+void BooleanLiteral() #BooleanLiteral :
+{ Token t; }
+{
+ <TRUE> { jjtThis.value=true; } | <FALSE> { jjtThis.value=false; }
+}
+
+void AggregateSelectExpression() #void:
+{}
+{
+ (
+ <AVG> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
+ ) #Avg
+|
+ (
+ <MAX> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
+ ) #Max
+|
+ (
+ <MIN> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
+ ) #Min
+|
+ (
+ <SUM> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
+ ) #Sum
+|
+ (
+ <COUNT> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}]
+ (
+ SingleValuedPath() | EntityBeanValue()
+ )
+ <RPAREN>
+ ) #Count
+}
+
+/////////////////////////
+// Tokens
+/////////////////////////
+
+TOKEN_MGR_DECLS :
+{
+ public Catalog catalog;
+ public Class[] argumentTypes;
+ public IdentifierManager idManager;
+
+ // used for navigation building
+ private List pathList;
+ private List fieldList;
+ private String path;
+
+ private void resetPath() {
+ path = "";
+ pathList = new ArrayList();
+ fieldList = new ArrayList();
+ }
+
+ private void throwUnknownPath(
+ String reason,
+ String fieldName) {
+
+ throw new UnknownPathException(
+ reason,
+ path,
+ fieldName,
+ input_stream.getEndLine(),
+ input_stream.getEndColumn());
+ }
+
+ private void addPath(String nav) {
+ String fieldName = nav.substring(0, nav.length()-1);
+ if(fieldList.size() > 0) {
+ FieldBridge field = getCurrentSchema().getFieldByName(fieldName);
+ if(field == null) {
+ throwUnknownPath("Unknown cmr field in path", fieldName);
+ }
+ if(!(field instanceof CMRFieldBridge)) {
+ throwUnknownPath("In path field is not a cmr field", fieldName);
+ }
+
+ CMRFieldBridge cmrField = (CMRFieldBridge)field;
+ if(!cmrField.isSingleValued()) {
+ throwUnknownPath("In path cmr field is collection valued",
+ fieldName);
+ }
+ fieldList.add(cmrField);
+ } else {
+ EntityBridge entityBridge = idManager.getEntity(fieldName);
+ if(entityBridge == null) {
+ throwUnknownPath("Unknown initial identifier", fieldName);
+ }
+ fieldList.add(entityBridge);
+ }
+ pathList.add(path + fieldName);
+ path += nav;
+ }
+
+ private EntityBridge getCurrentSchema() {
+ Object lastElement = fieldList.get(fieldList.size()-1);
+ if(lastElement instanceof EntityBridge) {
+ return (EntityBridge)lastElement;
+ } else if(lastElement instanceof CMRFieldBridge) {
+ return ((CMRFieldBridge)lastElement).getRelatedEntity();
+ }
+ // should never happen
+ throw new IllegalStateException("Unknown path element type: " +
+ lastElement);
+ }
+}
+
+<DEFAULT> SKIP :
+{
+ " "
+| "\t"
+| "\n"
+| "\r"
+}
+
+<DEFAULT> TOKEN [IGNORE_CASE] : /* RESERVED WORDS */
+{
+ < ABS: "ABS" >
+| < AND: "AND" >
+| < AS: "AS" >
+| < BETWEEN: "BETWEEN" >
+| < CONCAT: "CONCAT" >
+| < DISTINCT: "DISTINCT" >
+| < EMPTY: "EMPTY" >
+| < ESCAPE: "ESCAPE" >
+| < FROM: "FROM" >
+| < IN: "IN" >
+| < IS: "IS" >
+| < LENGTH: "LENGTH" >
+| < LIKE: "LIKE" >
+| < LOCATE: "LOCATE" >
+| < NOT: "NOT" >
+| < NULL: "NULL" >
+| < OBJECT: "OBJECT" >
+| < OF: "OF " >
+| < OR: "OR" >
+| < SELECT: "SELECT" >
+| < SUBSTRING: "SUBSTRING" >
+| < SQRT: "SQRT" >
+| < UNKNOWN: "UNKNOWN" >
+| < WHERE: "WHERE" >
+| < MEMBER: "MEMBER" >
+
+// EJB QL 2.1 tokens
+
+| < ORDER: "ORDER" >
+| < BY: "BY" >
+| < ASC: "ASC" >
+| < DESC: "DESC" >
+| < COUNT: "COUNT" >
+| < MAX: "MAX" >
+| < MIN: "MIN" >
+| < AVG: "AVG" >
+| < SUM: "SUM" >
+| < MOD: "MOD" >
+}
+
+<DEFAULT> TOKEN : /* SEPARATORS */
+{
+ < LPAREN: "(" >
+| < RPAREN: ")" >
+| < COMMA: "," >
+| < DOT: "." >
+}
+
+<DEFAULT> TOKEN : /* OPERATORS */
+{
+ < GT: ">" >
+| < LT: "<" >
+| < EQ: "=" >
+| < LE: "<=" >
+| < GE: ">=" >
+| < NE: "<>" >
+| < PLUS: "+" >
+| < MINUS: "-" >
+| < MULT: "*" >
+| < DIV: "/" >
+}
+
+<DEFAULT> TOKEN : /* String Literal */
+{
+ < STRING_LITERAL: "'" (~["'"])* ( "''" (~["'"])* )* "'" >
+}
+
+<DEFAULT> TOKEN : /* Numeric Literal */
+{
+ < INTEGER_LITERAL:
+ <DECIMAL_LITERAL> (["l","L"])?
+ | <HEX_LITERAL> (["l","L"])?
+ | <OCTAL_LITERAL> (["l","L"])?
+ >
+|
+ < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
+|
+ < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
+|
+ < #OCTAL_LITERAL: "0" (["0"-"7"])* >
+|
+ < FLOATING_POINT_LITERAL:
+ (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
+ | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
+ | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
+ | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
+ >
+|
+ < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
+}
+
+<DEFAULT> TOKEN [IGNORE_CASE] : /* Boolean Literal */
+{
+ < FALSE: "FALSE" >
+| < TRUE: "TRUE" >
+}
+
+<DEFAULT> TOKEN : /* IDENTIFIERS */
+{
+ < IDENTIFIER: <NAME> >
+ {
+ if(catalog.getEntityByAbstractSchemaName(matchedToken.image) != null) {
+ matchedToken.kind = ABSTRACT_SCHEMA;
+ } else if(idManager.getEntity(matchedToken.image.toLowerCase()) != null) {
+ matchedToken.kind = IDENTIFICATION_VARIABLE;
+ matchedToken.image = matchedToken.image.toLowerCase();
+
+ List pathList = new ArrayList();
+ pathList.add(matchedToken.image);
+ List fieldList = new ArrayList();
+ fieldList.add(idManager.getEntity(matchedToken.image));
+ idManager.registerPath(matchedToken.image, pathList, fieldList);
+ }
+ }
+|
+ < ABSTRACT_SCHEMA: [] >
+|
+ < IDENTIFICATION_VARIABLE: [] >
+|
+ < #NAME: <LETTER> (<LETTER>|<DIGIT>)* >
+|
+ < #LETTER:
+ [
+ "\u0024",
+ "\u0041"-"\u005a",
+ "\u005f",
+ "\u0061"-"\u007a",
+ "\u00c0"-"\u00d6",
+ "\u00d8"-"\u00f6",
+ "\u00f8"-"\u00ff",
+ "\u0100"-"\u1fff",
+ "\u3040"-"\u318f",
+ "\u3300"-"\u337f",
+ "\u3400"-"\u3d2d",
+ "\u4e00"-"\u9fff",
+ "\uf900"-"\ufaff"
+ ]
+ >
+|
+ < #DIGIT:
+ [
+ "\u0030"-"\u0039",
+ "\u0660"-"\u0669",
+ "\u06f0"-"\u06f9",
+ "\u0966"-"\u096f",
+ "\u09e6"-"\u09ef",
+ "\u0a66"-"\u0a6f",
+ "\u0ae6"-"\u0aef",
+ "\u0b66"-"\u0b6f",
+ "\u0be7"-"\u0bef",
+ "\u0c66"-"\u0c6f",
+ "\u0ce6"-"\u0cef",
+ "\u0d66"-"\u0d6f",
+ "\u0e50"-"\u0e59",
+ "\u0ed0"-"\u0ed9",
+ "\u1040"-"\u1049"
+ ]
+ >
+}
+
+<DEFAULT> TOKEN : /* PARAMETERS */
+{
+ < UNKNOWN_PARAMETER: "?" <INTEGER_LITERAL> >
+ {
+ int n = EJBQLTypes.UNKNOWN_TYPE;
+ try {
+ n = Integer.parseInt(matchedToken.image.substring(1, lengthOfMatch));
+ } catch(Exception e) { /* Should never come here. */ }
+
+ matchedToken.image = "" + n;
+
+ // zero base the index
+ n--;
+
+ if(n < argumentTypes.length) {
+ switch(EJBQLTypes.getEJBQLType(argumentTypes[n])) {
+ case EJBQLTypes.NUMERIC_TYPE:
+ matchedToken.kind = NUMERIC_VALUED_PARAMETER;
+ break;
+ case EJBQLTypes.STRING_TYPE:
+ matchedToken.kind = STRING_VALUED_PARAMETER;
+ break;
+ case EJBQLTypes.DATETIME_TYPE:
+ matchedToken.kind = DATETIME_VALUED_PARAMETER;
+ break;
+ case EJBQLTypes.BOOLEAN_TYPE:
+ matchedToken.kind = BOOLEAN_VALUED_PARAMETER;
+ break;
+ case EJBQLTypes.ENTITY_TYPE:
+ matchedToken.kind = ENTITY_VALUED_PARAMETER;
+ break;
+ case EJBQLTypes.VALUE_CLASS_TYPE:
+ matchedToken.kind = VALUE_CLASS_VALUED_PARAMETER;
+ break;
+ }
+ }
+ }
+| < NUMERIC_VALUED_PARAMETER: [] >
+| < STRING_VALUED_PARAMETER: [] >
+| < DATETIME_VALUED_PARAMETER: [] >
+| < BOOLEAN_VALUED_PARAMETER: [] >
+| < ENTITY_VALUED_PARAMETER: [] >
+| < VALUE_CLASS_VALUED_PARAMETER: [] >
+}
+
+/**
+ * WARNING: Be careful here. If look ahead is to high in the from clause, it
+ * is possible that the identification varible is not registered before it
+ * is used here.
+ */
+<DEFAULT> SPECIAL_TOKEN : /* Navigation */
+{
+ < <NAME> <DOT> > {
+ resetPath();
+ addPath(matchedToken.image.toLowerCase());
+ } : IN_NAVIGATION
+}
+
+<IN_NAVIGATION> SPECIAL_TOKEN :
+{
+ < <NAME> <DOT> > { addPath(matchedToken.image); } : IN_NAVIGATION
+}
+
+<IN_NAVIGATION> TOKEN :
+{
+ < PART: <NAME> > {
+ String fieldName = matchedToken.image;
+ matchedToken.image = path + fieldName;
+
+ FieldBridge field = getCurrentSchema().getFieldByName(fieldName);
+ if(field == null) {
+ throwUnknownPath("Unknown terminal field", fieldName);
+ }
+ if(field instanceof CMPFieldBridge) {
+ CMPFieldBridge cmpField = (CMPFieldBridge)field;
+ switch(EJBQLTypes.getEJBQLType(cmpField.getFieldType())) {
+ case EJBQLTypes.NUMERIC_TYPE:
+ matchedToken.kind = NUMERIC_VALUED_PATH;
+ break;
+ case EJBQLTypes.STRING_TYPE:
+ matchedToken.kind = STRING_VALUED_PATH;
+ break;
+ case EJBQLTypes.DATETIME_TYPE:
+ matchedToken.kind = DATETIME_VALUED_PATH;
+ break;
+ case EJBQLTypes.BOOLEAN_TYPE:
+ matchedToken.kind = BOOLEAN_VALUED_PATH;
+ break;
+ case EJBQLTypes.ENTITY_TYPE:
+ matchedToken.kind = ENTITY_VALUED_PATH;
+ break;
+ case EJBQLTypes.VALUE_CLASS_TYPE:
+ matchedToken.kind = VALUE_CLASS_VALUED_PATH;
+ break;
+ default:
+ throwUnknownPath("Unknown cmp field type", fieldName);
+ }
+ } else {
+ CMRFieldBridge cmrField = (CMRFieldBridge)field;
+ if(cmrField.isSingleValued()) {
+ matchedToken.kind = ENTITY_VALUED_PATH;
+ } else {
+ matchedToken.kind = COLLECTION_VALUED_PATH;
+ }
+ }
+ pathList.add(matchedToken.image);
+ fieldList.add(field);
+ idManager.registerPath(matchedToken.image, pathList, fieldList);
+ resetPath();
+ } : DEFAULT
+| < NUMERIC_VALUED_PATH: [] >
+| < STRING_VALUED_PATH: [] >
+| < DATETIME_VALUED_PATH: [] >
+| < BOOLEAN_VALUED_PATH: [] >
+| < ENTITY_VALUED_PATH: [] >
+| < VALUE_CLASS_VALUED_PATH: [] >
+| < UNKNOWN_PATH: [] >
+| < COLLECTION_VALUED_PATH: [] >
+}
+
+
Property changes on: trunk/server/src/main/jjtree/org/jboss/ejb/plugins/cmp/ejbql/EJBQLParser.jjt
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
Copied: trunk/server/src/main/jjtree/org/jboss/ejb/plugins/cmp/ejbql/JBossQLParser.jjt (from rev 94157, trunk/server/src/main/java/org/jboss/ejb/plugins/cmp/ejbql/JBossQLParser.jjt)
===================================================================
--- trunk/server/src/main/jjtree/org/jboss/ejb/plugins/cmp/ejbql/JBossQLParser.jjt (rev 0)
+++ trunk/server/src/main/jjtree/org/jboss/ejb/plugins/cmp/ejbql/JBossQLParser.jjt 2009-09-30 19:05:48 UTC (rev 94178)
@@ -0,0 +1,1331 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+options {
+ BUILD_NODE_FILES=false;
+ MULTI=true;
+ VISITOR=true;
+
+ JAVA_UNICODE_ESCAPE = true;
+ STATIC = false;
+
+ CHOICE_AMBIGUITY_CHECK = 5;
+ OTHER_AMBIGUITY_CHECK = 5;
+
+ LOOKAHEAD = 1;
+ DEBUG_PARSER = false;
+ DEBUG_LOOKAHEAD = false;
+ DEBUG_TOKEN_MANAGER = false;
+ ERROR_REPORTING = true;
+ UNICODE_INPUT = false;
+ IGNORE_CASE = false;
+ USER_TOKEN_MANAGER = false;
+ USER_CHAR_STREAM = false;
+ BUILD_PARSER = true;
+ BUILD_TOKEN_MANAGER = true;
+ SANITY_CHECK = true;
+ FORCE_LA_CHECK = false;
+}
+
+PARSER_BEGIN(JBossQLParser)
+package org.jboss.ejb.plugins.cmp.ejbql;
+
+import java.io.CharArrayReader;
+import java.util.ArrayList;
+import java.util.List;
+import org.jboss.ejb.plugins.cmp.bridge.EntityBridge;
+import org.jboss.ejb.plugins.cmp.bridge.CMPFieldBridge;
+import org.jboss.ejb.plugins.cmp.bridge.CMRFieldBridge;
+import org.jboss.ejb.plugins.cmp.bridge.FieldBridge;
+
+/**
+ * This class parses JBossQL into an abstract syntax tree.
+ *
+ * @author <a href="mailto:dain at daingroup.com">Dain Sundstrom</a>
+ * @author <a href="mailto:alex at jboss.org">Alex Loubyansky</a>
+ * @version $Revision$
+ */
+public class JBossQLParser {
+ private Catalog catalog;
+ private Class[] argumentTypes;
+ private IdentifierManager idManager;
+ private boolean selectDistinct;
+ private String selectPath;
+
+ public ASTEJBQL parse(Catalog catalog, Class[] argumentTypes, String ejbql)
+ throws ParseException {
+
+ this.catalog = catalog;
+ token_source.catalog = catalog;
+ this.argumentTypes = argumentTypes;
+ token_source.argumentTypes = argumentTypes;
+ idManager = new IdentifierManager(catalog);
+ token_source.idManager = idManager;
+
+ String lowerCase = ejbql.toLowerCase();
+ int fromBeginIndex = indexOf(lowerCase, "from");
+ if(fromBeginIndex < 0) {
+ throw new ParseException("FROM not found");
+ }
+
+ int fromEndIndex = indexOf(lowerCase, "where");
+ ///////////////////// CHANGED //////////////////////////////
+ if(fromEndIndex < 0) {
+ fromEndIndex = indexOfOrderBy(lowerCase);
+ }
+ if(fromEndIndex < 0) {
+ fromEndIndex = indexOf(lowerCase, "offset");
+ }
+ if(fromEndIndex < 0) {
+ fromEndIndex = indexOf(lowerCase, "limit");
+ }
+ if(fromEndIndex < 0) {
+ fromEndIndex = ejbql.length();
+ }
+ ////////////////////////////////////////////////////////////
+
+ // just the from clause
+ char[] from = ejbql.toCharArray();
+ clear(from, 0, fromBeginIndex);
+ clear(from, fromEndIndex, from.length);
+
+ // everything except for the from clause
+ char[] sansFrom = ejbql.toCharArray();
+ clear(sansFrom, fromBeginIndex + 4, fromEndIndex);
+
+ // From clause
+ ReInit(new CharArrayReader(from));
+ ASTFrom fromNode = ParseFromClause();
+
+ // Everything else
+ ReInit(new CharArrayReader(sansFrom));
+ ASTEJBQL ejbqlNode = EJBQL();
+
+ // replace the dummy from clause in the EJBQL
+ // node with the real from node
+ ejbqlNode.jjtAddChild(fromNode, 1);
+
+ return ejbqlNode;
+ }
+
+ /**
+ * Returns the first index of the word (surrounded with whitespaces) in the string
+ * or -1 if the word was not found.
+ */
+ private static final int indexOf(String ql, String word)
+ {
+ return indexOf(ql, word, 0);
+ }
+
+ /**
+ * Returns the first index of the word (surrounded with whitespaces) in the string
+ * starting with startInd position or -1 if the word was not found.
+ */
+ private static final int indexOf(String ql, String word, int startInd)
+ {
+ int i = ql.indexOf(word, startInd);
+ if(i < 0)
+ {
+ return -1;
+ }
+
+ int qlLength = ql.length();
+ int wordLength = word.length();
+ while(i >= 0)
+ {
+ int endInd = i + wordLength;
+ if((i == 0 || Character.isWhitespace(ql.charAt(i - 1))) &&
+ (endInd == qlLength || endInd < qlLength && Character.isWhitespace(ql.charAt(endInd))))
+ {
+ break;
+ }
+
+ i = ql.indexOf(word, i + 1);
+ }
+ return i;
+ }
+
+ private static final int indexOfOrderBy(String ql)
+ {
+ int orderInd = indexOf(ql, "order", 0);
+ int byInd = -1;
+ while(orderInd > 0)
+ {
+ if(byInd < orderInd)
+ {
+ byInd = indexOf(ql, "by", orderInd + 5);
+ }
+
+ if(byInd > 0)
+ {
+ int i = byInd - 1;
+ while(i >= orderInd + 5 && Character.isWhitespace(ql.charAt(i--)));
+ if(i == orderInd + 4)
+ {
+ break;
+ }
+ else
+ {
+ orderInd = indexOf(ql, "order", orderInd + 5);
+ }
+ }
+ else
+ {
+ orderInd = -1;
+ }
+ }
+ return orderInd;
+ }
+
+ private final void clear(char[] c, int beginIndex, int endIndex) {
+ for(int i=beginIndex; i < endIndex; i++) {
+ if(c[i]!='\r' && c[i]!='\n' && c[i]!='\t') {
+ c[i] = ' ';
+ }
+ }
+ }
+
+ private final void initPathNode(ASTPath pathNode, String path, int type) {
+ pathNode.pathList = idManager.getPathList(path);
+ pathNode.fieldList = idManager.getFieldList(path);
+ pathNode.type = type;
+ }
+
+ private final void initParameterNode(
+ ASTParameter parameterNode,
+ String number,
+ int type) {
+
+ parameterNode.number = Integer.parseInt(number);
+ parameterNode.type = type;
+ }
+}
+
+PARSER_END(JBossQLParser)
+
+////////////////////// New or changed elements /////////////////////////////
+
+ASTEJBQL EJBQL() #EJBQL :
+{}
+{
+ SelectClause() FromKeyword() [WhereClause()] [OrderByClause()] [LimitClause()] <EOF>
+ { return jjtThis; }
+}
+
+ASTOrderBy OrderByClause() #OrderBy :
+{}
+{
+ <ORDER> <BY> OrderByPathExpression() ( <COMMA> OrderByPathExpression() ) *
+ { return jjtThis; }
+}
+
+void OrderByPathExpression() #OrderByPath :
+{}
+{
+ ( NumericValuedPath() | StringValuedPath() | DatetimeValuedPath() | ValueClassExpression())
+ [<ASC> | <DESC> { jjtThis.ascending=false; } ]
+}
+
+void LimitClause() #LimitOffset :
+{}
+{
+ <OFFSET> ArithmeticValue() { jjtThis.hasOffset = true; } [<LIMIT> ArithmeticValue() { jjtThis.hasLimit = true; }]
+ | <LIMIT> ArithmeticValue() { jjtThis.hasLimit = true; }
+}
+
+////////////////////////////////////////////////////////////////////////////
+
+void FromKeyword() #From :
+{}
+{
+ <FROM>
+}
+
+ASTFrom ParseFromClause() #void :
+{ ASTFrom node; }
+{
+ node = FromClause() <EOF>
+ { return node; }
+}
+
+ASTFrom FromClause() #From :
+{}
+{
+ (
+ <FROM> IdentificationVariableDeclaration()
+ ( <COMMA> IdentificationVariableDeclaration() )*
+ ) { return jjtThis; }
+}
+
+void IdentificationVariableDeclaration() #void :
+{}
+{
+ (CollectionMemberDeclaration() | RangeVariableDeclaration())
+}
+
+void CollectionMemberDeclaration() :
+{
+ Token path;
+ Token id;
+}
+{
+ ( <IN> <LPAREN> path=CollectionValuedPath() <RPAREN>
+ [<AS>] id=Identifier() )
+ { idManager.declareCollectionMember(id.image, path.image); }
+}
+
+void RangeVariableDeclaration() :
+{
+ Token schema;
+ Token id;
+}
+{
+ ( schema=AbstractSchema() [<AS>] id=Identifier() )
+ { idManager.declareRangeVariable(id.image, schema.image); }
+}
+
+ASTSelect SelectClause() #Select :
+{}
+{
+ (
+ <SELECT> [<DISTINCT> { jjtThis.distinct=true; }]
+ (
+ <OBJECT> <LPAREN> IdentificationVariable() <RPAREN> |
+ SingleValuedPath() |
+ FunctionsAllowedInSelect()
+ )
+ ) { return jjtThis; }
+}
+
+ASTWhere WhereClause() #Where :
+{}
+{
+ <WHERE> WhereExpression()
+ { return jjtThis; }
+}
+
+//
+// ASTWhereExpression and ASTWhereConditionalTerm mimic
+// ConditionalExpression and ConditionalTerm.
+// They are added to support joins per WhereConditionalTerm.
+//
+void WhereExpression() #void :
+{}
+{
+ (
+ WhereConditionalTerm() ( <OR> WhereConditionalTerm() )*
+ ) #Or(>1)
+}
+
+ASTWhereConditionalTerm WhereConditionalTerm() #WhereConditionalTerm :
+{}
+{
+ (
+ ConditionalFactor() ( <AND> ConditionalFactor() )*
+ ) #And(>1)
+ {return jjtThis;}
+}
+
+void ConditionalExpression() #void :
+{}
+{
+ (
+ ConditionalTerm() ( <OR> ConditionalTerm() )*
+ ) #Or(>1)
+}
+
+void ConditionalTerm() #void :
+{}
+{
+ (
+ ConditionalFactor() ( <AND> ConditionalFactor() )*
+ ) #And(>1)
+}
+
+void ConditionalFactor() #void :
+{ boolean not = false; }
+{
+ (
+ [<NOT>{ not=true; }] ConditionalTest()
+ ) #Not(not)
+}
+
+void ConditionalTest() #void :
+{}
+{
+ ConditionalPrimary()
+}
+
+void ConditionalPrimary() #void :
+{}
+{
+ LOOKAHEAD(<LPAREN> ConditionalExpression() <RPAREN>)
+ (<LPAREN> ConditionalExpression() <RPAREN>) #ConditionalParenthetical
+|
+ SimpleCondExpression()
+}
+
+////////////////////// New or changed elements /////////////////////////////
+
+void FunctionsAllowedInSelect() #void :
+{}
+{
+ FunctionsReturningNumerics() |
+ FunctionsReturningStrings()
+}
+
+void SimpleCondExpression() #void :
+{}
+{
+ EmptyCollectionComparisonExpression()
+|
+ LOOKAHEAD({ getToken(2).kind==IS })
+ NullComparisonExpression()
+|
+ LOOKAHEAD({ getToken(2).kind==MEMBER || getToken(3).kind==MEMBER })
+ CollectionMemberExpression()
+|
+ LOOKAHEAD(StringValue() [<NOT>] <LIKE>)
+ LikeExpression()
+|
+ LOOKAHEAD((StringValue() | ArithmeticValue() | DatetimeValue()) [<NOT>] <IN>)
+ InExpression()
+|
+ ComparisonExpression()
+}
+
+void BetweenExpression() #Between :
+{}
+{
+ (ArithmeticExpression() [<NOT> { jjtThis.not=true; } ] <BETWEEN>
+ ArithmeticExpression() <AND> ArithmeticExpression())
+|
+ (DatetimeValue() [<NOT> { jjtThis.not=true; } ] <BETWEEN>
+ DatetimeValue() <AND> DatetimeValue())
+|
+ (StringValue() [<NOT> { jjtThis.not=true; } ] <BETWEEN>
+ StringValue() <AND> StringValue())
+}
+
+void InExpression() #In :
+{}
+{
+ (StringExpression() [<NOT> { jjtThis.not=true; } ] <IN>
+ <LPAREN> StringExpression() ( <COMMA> StringExpression() )* <RPAREN>)
+|
+ (ArithmeticPrimary() [<NOT> { jjtThis.not=true; } ] <IN>
+ <LPAREN> ArithmeticPrimary() ( <COMMA> ArithmeticPrimary() )* <RPAREN>)
+|
+ (DatetimeValue() [<NOT> { jjtThis.not=true; } ] <IN>
+ <LPAREN> DatetimeValue() ( <COMMA> DatetimeValue() )* <RPAREN>)
+}
+
+void LikeExpression() #Like :
+{}
+{
+ StringValue() [<NOT> { jjtThis.not=true; } ] <LIKE>
+ StringExpression() [<ESCAPE> (StringLiteral() | NumericValuedParameter())]
+}
+
+////////////////////////////////////////////////////////////////////////////
+
+void NullComparisonExpression() #NullComparison :
+{}
+{
+ (
+ SingleValuedPath() |
+ NumericValuedParameter() |
+ EntityValuedParameter() |
+ StringValuedParameter() |
+ DatetimeValuedParameter() |
+ BooleanValuedParameter()
+ )
+ <IS> [<NOT> { jjtThis.not=true; } ] <NULL>
+}
+
+void EmptyCollectionComparisonExpression() #IsEmpty :
+{}
+{
+ CollectionValuedPath() <IS> [<NOT> { jjtThis.not=true; } ] <EMPTY>
+}
+
+void CollectionMemberExpression() #MemberOf :
+{}
+{
+ (EntityValuedPath() |
+ IdentificationVariable() |
+ EntityValuedParameter())
+ [<NOT> { jjtThis.not=true; } ] <MEMBER> [<OF>] CollectionValuedPath()
+}
+
+
+void ComparisonExpression() #void :
+{}
+{
+////////////////////// New or changed elements /////////////////////////////
+ LOOKAHEAD(StringValue() ( <EQ> | <GT> | <GE> | <LT> | <LE> | <NE> ) )
+ (
+ StringValue()
+ (
+ <EQ> { jjtThis.opp="="; } |
+ <GT> { jjtThis.opp=">"; } |
+ <GE> { jjtThis.opp=">="; } |
+ <LT> { jjtThis.opp="<"; } |
+ <LE> { jjtThis.opp="<="; } |
+ <NE> { jjtThis.opp="<>"; }
+ )
+ StringExpression()
+ ) #StringComparison
+////////////////////////////////////////////////////////////////////////////
+|
+ LOOKAHEAD(BooleanValue() ( <EQ> | <NE> ) )
+ (
+ BooleanValue()
+ [
+ (
+ <EQ> { jjtThis.opp="="; } |
+ <NE> { jjtThis.opp="<>"; }
+ ) BooleanExpression()
+ ]
+ ) #BooleanComparison
+|
+////////////////////// New or changed elements /////////////////////////////
+ LOOKAHEAD(DatetimeValue() ( <EQ> | <GT> | <GE> | <LT> | <LE> | <NE> ) )
+ (
+ DatetimeValue()
+ (
+ <EQ> { jjtThis.opp="="; } |
+ <GT> { jjtThis.opp=">"; } |
+ <GE> { jjtThis.opp=">="; } |
+ <LT> { jjtThis.opp="<"; } |
+ <LE> { jjtThis.opp="<="; } |
+ <NE> { jjtThis.opp="<>"; }
+ )
+ DatetimeExpression()
+ ) #DatetimeComparison
+|
+ LOOKAHEAD(ValueClassValue() ( <EQ> | <GT> | <GE> | <LT> | <LE> | <NE> ) )
+ (
+ ValueClassValue()
+ (
+ <EQ> { jjtThis.opp="="; } |
+ <GT> { jjtThis.opp=">"; } |
+ <GE> { jjtThis.opp=">="; } |
+ <LT> { jjtThis.opp="<"; } |
+ <LE> { jjtThis.opp="<="; } |
+ <NE> { jjtThis.opp="<>"; }
+ )
+ ValueClassExpression()
+ ) #ValueClassComparison
+////////////////////////////////////////////////////////////////////////////
+|
+ LOOKAHEAD(EntityBeanValue() ( <EQ> | <NE> ) )
+ (
+ EntityBeanValue()
+ (
+ <EQ> { jjtThis.opp="="; } |
+ <NE> { jjtThis.opp="<>"; }
+ )
+ EntityBeanExpression()
+ ) #EntityComparison
+|
+ LOOKAHEAD(ArithmeticValue() ( <EQ> | <GT> | <GE> | <LT> | <LE> | <NE> ) )
+ (
+ ArithmeticValue()
+ (
+ <EQ> { jjtThis.opp="="; } |
+ <GT> { jjtThis.opp=">"; } |
+ <GE> { jjtThis.opp=">="; } |
+ <LT> { jjtThis.opp="<"; } |
+ <LE> { jjtThis.opp="<="; } |
+ <NE> { jjtThis.opp="<>"; }
+ )
+ SingleValueDesignator()
+ ) #ArithmeticComparison
+|
+ BetweenExpression()
+}
+
+////////////////////// New or changed elements /////////////////////////////
+void ArithmeticValue() #void :
+{}
+{
+ NumericValuedPath() | FunctionsReturningNumerics() |
+ NumericLiteral() | NumericValuedParameter()
+}
+////////////////////////////////////////////////////////////////////////////
+
+void SingleValueDesignator() #void :
+{}
+{
+ ScalarExpression()
+}
+
+void ScalarExpression() #void :
+{}
+{
+ ArithmeticExpression()
+}
+
+void ArithmeticExpression() #void :
+{}
+{
+ (
+ ArithmeticTerm()
+ (
+ (
+ <PLUS> { jjtThis.addOpp("+"); } |
+ <MINUS> { jjtThis.addOpp("-"); }
+ ) ArithmeticTerm()
+ )*
+ ) #PlusMinus(>1)
+}
+
+void ArithmeticTerm() #void :
+{}
+{
+ (
+ ArithmeticFactor()
+ (
+ (
+ <MULT> { jjtThis.addOpp("*"); } |
+ <DIV> { jjtThis.addOpp("/"); }
+ ) ArithmeticFactor()
+ )*
+ ) #MultDiv(>1)
+}
+
+void ArithmeticFactor() #void :
+{ boolean negation = false; }
+{
+ (
+ [<PLUS>|<MINUS>{negation=true;}] ArithmeticPrimary()
+ ) #Negation(negation)
+}
+
+void ArithmeticPrimary() #void :
+{}
+{
+ NumericValuedPath() |
+ NumericLiteral() |
+ (<LPAREN> ArithmeticExpression() <RPAREN>) #ArithmeticParenthetical |
+ NumericValuedParameter() |
+ FunctionsReturningNumerics()
+}
+
+////////////////////// New or changed elements /////////////////////////////
+void StringValue() #void :
+{}
+{
+ StringValuedPath() | FunctionsReturningStrings() |
+ StringLiteral()| StringValuedParameter()
+}
+////////////////////////////////////////////////////////////////////////////
+
+void StringExpression() #void :
+{}
+{
+ StringPrimary() | StringValuedParameter()
+}
+
+void StringPrimary() #void :
+{}
+{
+ StringValuedPath() |
+ StringLiteral() |
+ (<LPAREN> StringExpression() <RPAREN>) #StringParenthetical |
+ FunctionsReturningStrings()
+}
+
+////////////////////// New or changed elements /////////////////////////////
+
+void DatetimeValue() #void :
+{}
+{
+ DatetimeValuedPath() | DatetimeValuedParameter()
+}
+
+void DatetimeExpression() #void :
+{}
+{
+ DatetimeValue()
+}
+
+void BooleanValue() #void :
+{}
+{
+ BooleanValuedPath() | BooleanValuedParameter() | BooleanLiteral()
+}
+
+void BooleanExpression() #void :
+{}
+{
+ BooleanValue()
+}
+
+void ValueClassValue() #void :
+{}
+{
+ ValueClassValuedPath() | ValueClassValuedParameter()
+}
+
+void ValueClassExpression() #void :
+{}
+{
+ ValueClassValue()
+}
+
+
+void EntityBeanValue() #void :
+{}
+{
+ EntityValuedPath() | IdentificationVariable() | EntityValuedParameter()
+}
+
+void EntityBeanExpression() #void :
+{}
+{
+ EntityBeanValue()
+}
+
+////////////////////////////////////////////////////////////////////////////
+
+void FunctionsReturningStrings() #void :
+{}
+{
+ (
+ <CONCAT> <LPAREN> StringExpression() <COMMA> StringExpression() <RPAREN>
+ ) #Concat
+|
+ (
+ <SUBSTRING> <LPAREN>
+ StringExpression() <COMMA>
+ ArithmeticExpression() <COMMA>
+ ArithmeticExpression() <RPAREN>
+ ) #Substring
+////////////////////// New or changed elements /////////////////////////////
+|
+ (
+ <UCASE> <LPAREN> StringExpression() <RPAREN>
+ ) #UCase
+|
+ (
+ <LCASE> <LPAREN> StringExpression() <RPAREN>
+ ) #LCase
+////////////////////////////////////////////////////////////////////////////
+}
+
+void FunctionsReturningNumerics() #void :
+{}
+{
+ (
+ <LENGTH> <LPAREN> StringExpression() <RPAREN>
+ ) #Length
+|
+ (
+ <LOCATE> <LPAREN>
+ StringExpression() <COMMA> StringExpression()
+ [ <COMMA> ArithmeticExpression()] <RPAREN>
+ ) #Locate
+|
+ (
+ <ABS> <LPAREN> ArithmeticExpression() <RPAREN>
+ ) #Abs
+|
+ (
+ <SQRT> <LPAREN> ArithmeticExpression() <RPAREN>
+ ) #Sqrt
+|
+ (
+ <MOD> <LPAREN>
+ ArithmeticExpression() <COMMA>
+ ArithmeticExpression() <RPAREN>
+ ) #Mod
+|
+ AggregateFunctions()
+////////////////////////////////////////////////////////////////////////////
+}
+
+void AggregateFunctions() #void:
+{}
+{
+ (
+ <AVG> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
+ ) #Avg
+|
+ (
+ <MAX> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
+ ) #Max
+|
+ (
+ <MIN> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
+ ) #Min
+|
+ (
+ <SUM> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}] SingleValuedPath() <RPAREN>
+ ) #Sum
+|
+ (
+ <COUNT> <LPAREN> [<DISTINCT> {jjtThis.distinct="DISTINCT";}]
+ (
+ SingleValuedPath() | EntityBeanValue()
+ )
+ <RPAREN>
+ ) #Count
+}
+
+Token CollectionValuedPath() #Path :
+{ Token t; }
+{
+ t=<COLLECTION_VALUED_PATH>
+ {
+ initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE);
+ return t;
+ }
+}
+
+Token IdentificationVariable() #Path :
+{ Token t; }
+{
+ t=<IDENTIFICATION_VARIABLE>
+ {
+ t.image = t.image.toLowerCase();
+ initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE);
+ return t;
+ }
+}
+
+Token AbstractSchema() #AbstractSchema :
+{ Token t; }
+{
+ t=<ABSTRACT_SCHEMA>
+ {
+ jjtThis.abstractSchemaName = t.image;
+ jjtThis.entity = catalog.getEntityByAbstractSchemaName(t.image);
+ return t;
+ }
+ |
+ t=<ORDER>
+ {
+ jjtThis.abstractSchemaName = t.image;
+ jjtThis.entity = catalog.getEntityByAbstractSchemaName(t.image);
+ return t;
+ }
+}
+
+Token Identifier() #Identifier :
+{ Token t; }
+{
+ t=<IDENTIFIER>
+ {
+ t.image = t.image.toLowerCase();
+ jjtThis.identifier = t.image;
+ return t;
+ }
+}
+
+void SingleValuedPath() #void :
+{}
+{
+ NumericValuedPath()
+| StringValuedPath()
+| DatetimeValuedPath()
+| BooleanValuedPath()
+| EntityValuedPath()
+| ValueClassValuedPath()
+}
+
+void NumericValuedPath() #Path :
+{ Token t; }
+{
+ t=<NUMERIC_VALUED_PATH>
+ { initPathNode(jjtThis, t.image, EJBQLTypes.NUMERIC_TYPE); }
+}
+
+void StringValuedPath() #Path :
+{ Token t; }
+{
+ t=<STRING_VALUED_PATH>
+ { initPathNode(jjtThis, t.image, EJBQLTypes.STRING_TYPE); }
+}
+
+void DatetimeValuedPath() #Path :
+{ Token t; }
+{
+ t=<DATETIME_VALUED_PATH>
+ { initPathNode(jjtThis, t.image, EJBQLTypes.DATETIME_TYPE); }
+}
+
+void BooleanValuedPath() #Path :
+{ Token t; }
+{
+ t=<BOOLEAN_VALUED_PATH>
+ { initPathNode(jjtThis, t.image, EJBQLTypes.BOOLEAN_TYPE); }
+}
+
+void EntityValuedPath() #Path :
+{ Token t; }
+{
+ t=<ENTITY_VALUED_PATH>
+ { initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE); }
+}
+
+void ValueClassValuedPath() #Path :
+{ Token t; }
+{
+ t=<VALUE_CLASS_VALUED_PATH>
+ { initPathNode(jjtThis, t.image, EJBQLTypes.VALUE_CLASS_TYPE); }
+}
+
+void NumericValuedParameter() #Parameter :
+{ Token t; }
+{
+ t=<NUMERIC_VALUED_PARAMETER>
+ { initParameterNode(jjtThis, t.image, EJBQLTypes.NUMERIC_TYPE); }
+}
+
+void StringValuedParameter() #Parameter :
+{ Token t; }
+{
+ t=<STRING_VALUED_PARAMETER>
+ { initParameterNode(jjtThis, t.image, EJBQLTypes.STRING_TYPE); }
+}
+
+void DatetimeValuedParameter() #Parameter :
+{ Token t; }
+{
+ t=<DATETIME_VALUED_PARAMETER>
+ { initParameterNode(jjtThis, t.image, EJBQLTypes.DATETIME_TYPE); }
+}
+
+void BooleanValuedParameter() #Parameter :
+{ Token t; }
+{
+ t=<BOOLEAN_VALUED_PARAMETER>
+ { initParameterNode(jjtThis, t.image, EJBQLTypes.BOOLEAN_TYPE); }
+}
+
+void EntityValuedParameter() #Parameter :
+{ Token t; }
+{
+ t=<ENTITY_VALUED_PARAMETER>
+ { initParameterNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE); }
+}
+
+void ValueClassValuedParameter() #Parameter :
+{ Token t; }
+{
+ t=<VALUE_CLASS_VALUED_PARAMETER>
+ { initParameterNode(jjtThis, t.image, EJBQLTypes.VALUE_CLASS_TYPE); }
+}
+
+void NumericLiteral() #void :
+{ Token t; }
+{
+ (
+ t=<INTEGER_LITERAL> { jjtThis.setValue(t.image); }
+ ) #ExactNumericLiteral
+|
+ (
+ t=<FLOATING_POINT_LITERAL> { jjtThis.setValue(t.image); }
+ ) #ApproximateNumericLiteral
+}
+
+void StringLiteral() #StringLiteral :
+{ Token t; }
+{
+ t=<STRING_LITERAL>
+ { jjtThis.value=t.image; }
+}
+
+void BooleanLiteral() #BooleanLiteral :
+{ Token t; }
+{
+ <TRUE> { jjtThis.value=true; } | <FALSE> { jjtThis.value=false; }
+}
+
+/////////////////////////
+// Tokens
+/////////////////////////
+
+TOKEN_MGR_DECLS :
+{
+ public Catalog catalog;
+ public Class[] argumentTypes;
+ public IdentifierManager idManager;
+
+ // used for navigation building
+ private List pathList;
+ private List fieldList;
+ private String path;
+
+ private void resetPath() {
+ path = "";
+ pathList = new ArrayList();
+ fieldList = new ArrayList();
+ }
+
+ private void throwUnknownPath(
+ String reason,
+ String fieldName) {
+
+ throw new UnknownPathException(
+ reason,
+ path,
+ fieldName,
+ input_stream.getEndLine(),
+ input_stream.getEndColumn());
+ }
+
+ private void addPath(String nav) {
+ String fieldName = nav.substring(0, nav.length()-1);
+ if(fieldList.size() > 0) {
+ FieldBridge field = getCurrentSchema().getFieldByName(fieldName);
+ if(field == null) {
+ throwUnknownPath("Unknown cmr field in path", fieldName);
+ }
+ if(!(field instanceof CMRFieldBridge)) {
+ throwUnknownPath("In path field is not a cmr field", fieldName);
+ }
+
+ CMRFieldBridge cmrField = (CMRFieldBridge)field;
+ if(!cmrField.isSingleValued()) {
+ throwUnknownPath("In path cmr field is collection valued",
+ fieldName);
+ }
+ fieldList.add(cmrField);
+ } else {
+ EntityBridge entityBridge = idManager.getEntity(fieldName);
+ if(entityBridge == null) {
+ throwUnknownPath("Unknown initial identifier", fieldName);
+ }
+ fieldList.add(entityBridge);
+ }
+ pathList.add(path + fieldName);
+ path += nav;
+ }
+
+ private EntityBridge getCurrentSchema() {
+ Object lastElement = fieldList.get(fieldList.size()-1);
+ if(lastElement instanceof EntityBridge) {
+ return (EntityBridge)lastElement;
+ } else if(lastElement instanceof CMRFieldBridge) {
+ return ((CMRFieldBridge)lastElement).getRelatedEntity();
+ }
+ // should never happen
+ throw new IllegalStateException("Unknown path element type: " +
+ lastElement);
+ }
+}
+
+<DEFAULT> SKIP :
+{
+ " "
+| "\t"
+| "\n"
+| "\r"
+}
+
+<DEFAULT> TOKEN [IGNORE_CASE] : /* RESERVED WORDS */
+{
+ < ABS: "ABS" >
+| < AND: "AND" >
+| < AS: "AS" >
+| < BETWEEN: "BETWEEN" >
+| < CONCAT: "CONCAT" >
+| < COUNT: "COUNT" >
+| < MAX: "MAX" >
+| < MIN: "MIN" >
+| < AVG: "AVG" >
+| < SUM: "SUM" >
+| < DISTINCT: "DISTINCT" >
+| < EMPTY: "EMPTY" >
+| < ESCAPE: "ESCAPE" >
+| < FROM: "FROM" >
+| < IN: "IN" >
+| < IS: "IS" >
+| < LENGTH: "LENGTH" >
+| < LIKE: "LIKE" >
+| < LOCATE: "LOCATE" >
+| < NOT: "NOT" >
+| < NULL: "NULL" >
+| < OBJECT: "OBJECT" >
+| < OF: "OF " >
+| < OR: "OR" >
+| < SELECT: "SELECT" >
+| < SUBSTRING: "SUBSTRING" >
+| < SQRT: "SQRT" >
+| < UNKNOWN: "UNKNOWN" >
+| < WHERE: "WHERE" >
+| < MEMBER: "MEMBER" >
+| < ASC: "ASC" >
+| < DESC: "DESC" >
+| < LCASE: "LCASE" >
+| < LIMIT: "LIMIT" >
+| < OFFSET: "OFFSET" >
+| < ORDER: "ORDER" >
+| < BY: "BY" >
+| < UCASE: "UCASE" >
+| < MOD: "MOD" >
+}
+
+<DEFAULT> TOKEN : /* SEPARATORS */
+{
+ < LPAREN: "(" >
+| < RPAREN: ")" >
+| < COMMA: "," >
+| < DOT: "." >
+}
+
+<DEFAULT> TOKEN : /* OPERATORS */
+{
+ < GT: ">" >
+| < LT: "<" >
+| < EQ: "=" >
+| < LE: "<=" >
+| < GE: ">=" >
+| < NE: "<>" >
+| < PLUS: "+" >
+| < MINUS: "-" >
+| < MULT: "*" >
+| < DIV: "/" >
+}
+
+<DEFAULT> TOKEN : /* String Literal */
+{
+ < STRING_LITERAL: "'" (~["'"])* ( "''" (~["'"])* )* "'" >
+}
+
+<DEFAULT> TOKEN : /* Numeric Literal */
+{
+ < INTEGER_LITERAL:
+ <DECIMAL_LITERAL> (["l","L"])?
+ | <HEX_LITERAL> (["l","L"])?
+ | <OCTAL_LITERAL> (["l","L"])?
+ >
+|
+ < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
+|
+ < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
+|
+ < #OCTAL_LITERAL: "0" (["0"-"7"])* >
+|
+ < FLOATING_POINT_LITERAL:
+ (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
+ | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
+ | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
+ | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
+ >
+|
+ < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
+}
+
+<DEFAULT> TOKEN [IGNORE_CASE] : /* Boolean Literal */
+{
+ < FALSE: "FALSE" >
+| < TRUE: "TRUE" >
+}
+
+<DEFAULT> TOKEN : /* IDENTIFIERS */
+{
+ < IDENTIFIER: <NAME> >
+ {
+ if(catalog.getEntityByAbstractSchemaName(matchedToken.image) != null) {
+ matchedToken.kind = ABSTRACT_SCHEMA;
+ } else if(idManager.getEntity(matchedToken.image.toLowerCase()) != null) {
+ matchedToken.kind = IDENTIFICATION_VARIABLE;
+ matchedToken.image = matchedToken.image.toLowerCase();
+
+ List pathList = new ArrayList();
+ pathList.add(matchedToken.image);
+ List fieldList = new ArrayList();
+ fieldList.add(idManager.getEntity(matchedToken.image));
+ idManager.registerPath(matchedToken.image, pathList, fieldList);
+ }
+ }
+|
+ < ABSTRACT_SCHEMA: [] >
+|
+ < IDENTIFICATION_VARIABLE: [] >
+|
+ < #NAME: <LETTER> (<LETTER>|<DIGIT>)* >
+|
+ < #LETTER:
+ [
+ "\u0024",
+ "\u0041"-"\u005a",
+ "\u005f",
+ "\u0061"-"\u007a",
+ "\u00c0"-"\u00d6",
+ "\u00d8"-"\u00f6",
+ "\u00f8"-"\u00ff",
+ "\u0100"-"\u1fff",
+ "\u3040"-"\u318f",
+ "\u3300"-"\u337f",
+ "\u3400"-"\u3d2d",
+ "\u4e00"-"\u9fff",
+ "\uf900"-"\ufaff"
+ ]
+ >
+|
+ < #DIGIT:
+ [
+ "\u0030"-"\u0039",
+ "\u0660"-"\u0669",
+ "\u06f0"-"\u06f9",
+ "\u0966"-"\u096f",
+ "\u09e6"-"\u09ef",
+ "\u0a66"-"\u0a6f",
+ "\u0ae6"-"\u0aef",
+ "\u0b66"-"\u0b6f",
+ "\u0be7"-"\u0bef",
+ "\u0c66"-"\u0c6f",
+ "\u0ce6"-"\u0cef",
+ "\u0d66"-"\u0d6f",
+ "\u0e50"-"\u0e59",
+ "\u0ed0"-"\u0ed9",
+ "\u1040"-"\u1049"
+ ]
+ >
+}
+
+<DEFAULT> TOKEN : /* PARAMETERS */
+{
+ < UNKNOWN_PARAMETER: "?" <INTEGER_LITERAL> >
+ {
+ int n = EJBQLTypes.UNKNOWN_TYPE;
+ try {
+ n = Integer.parseInt(matchedToken.image.substring(1, lengthOfMatch));
+ } catch(Exception e) { /* Should never come here. */ }
+
+ matchedToken.image = "" + n;
+
+ // zero base the index
+ n--;
+
+ if(n < argumentTypes.length) {
+ switch(EJBQLTypes.getEJBQLType(argumentTypes[n])) {
+ case EJBQLTypes.NUMERIC_TYPE:
+ matchedToken.kind = NUMERIC_VALUED_PARAMETER;
+ break;
+ case EJBQLTypes.STRING_TYPE:
+ matchedToken.kind = STRING_VALUED_PARAMETER;
+ break;
+ case EJBQLTypes.DATETIME_TYPE:
+ matchedToken.kind = DATETIME_VALUED_PARAMETER;
+ break;
+ case EJBQLTypes.BOOLEAN_TYPE:
+ matchedToken.kind = BOOLEAN_VALUED_PARAMETER;
+ break;
+ case EJBQLTypes.ENTITY_TYPE:
+ matchedToken.kind = ENTITY_VALUED_PARAMETER;
+ break;
+ case EJBQLTypes.VALUE_CLASS_TYPE:
+ matchedToken.kind = VALUE_CLASS_VALUED_PARAMETER;
+ break;
+ }
+ }
+ }
+| < NUMERIC_VALUED_PARAMETER: [] >
+| < STRING_VALUED_PARAMETER: [] >
+| < DATETIME_VALUED_PARAMETER: [] >
+| < BOOLEAN_VALUED_PARAMETER: [] >
+| < ENTITY_VALUED_PARAMETER: [] >
+| < VALUE_CLASS_VALUED_PARAMETER: [] >
+}
+
+/**
+ * WARNING: Be careful here. If look ahead is to high in the from clause, it
+ * is possible that the identification varible is not registered before it
+ * is used here.
+ */
+<DEFAULT> SPECIAL_TOKEN : /* Navigation */
+{
+ < <NAME> <DOT> > {
+ resetPath();
+ addPath(matchedToken.image.toLowerCase());
+ } : IN_NAVIGATION
+}
+
+<IN_NAVIGATION> SPECIAL_TOKEN :
+{
+ < <NAME> <DOT> > { addPath(matchedToken.image); } : IN_NAVIGATION
+}
+
+<IN_NAVIGATION> TOKEN :
+{
+ < PART: <NAME> > {
+ String fieldName = matchedToken.image;
+ matchedToken.image = path + fieldName;
+
+ FieldBridge field = getCurrentSchema().getFieldByName(fieldName);
+ if(field == null) {
+ throwUnknownPath("Unknown terminal field", fieldName);
+ }
+ if(field instanceof CMPFieldBridge) {
+ CMPFieldBridge cmpField = (CMPFieldBridge)field;
+ switch(EJBQLTypes.getEJBQLType(cmpField.getFieldType())) {
+ case EJBQLTypes.NUMERIC_TYPE:
+ matchedToken.kind = NUMERIC_VALUED_PATH;
+ break;
+ case EJBQLTypes.STRING_TYPE:
+ matchedToken.kind = STRING_VALUED_PATH;
+ break;
+ case EJBQLTypes.DATETIME_TYPE:
+ matchedToken.kind = DATETIME_VALUED_PATH;
+ break;
+ case EJBQLTypes.BOOLEAN_TYPE:
+ matchedToken.kind = BOOLEAN_VALUED_PATH;
+ break;
+ case EJBQLTypes.ENTITY_TYPE:
+ matchedToken.kind = ENTITY_VALUED_PATH;
+ break;
+ case EJBQLTypes.VALUE_CLASS_TYPE:
+ matchedToken.kind = VALUE_CLASS_VALUED_PATH;
+ break;
+ default:
+ throwUnknownPath("Unknown cmp field type", fieldName);
+ }
+ } else {
+ CMRFieldBridge cmrField = (CMRFieldBridge)field;
+ if(cmrField.isSingleValued()) {
+ matchedToken.kind = ENTITY_VALUED_PATH;
+ } else {
+ matchedToken.kind = COLLECTION_VALUED_PATH;
+ }
+ }
+ pathList.add(matchedToken.image);
+ fieldList.add(field);
+ idManager.registerPath(matchedToken.image, pathList, fieldList);
+ resetPath();
+ } : DEFAULT
+| < NUMERIC_VALUED_PATH: [] >
+| < STRING_VALUED_PATH: [] >
+| < DATETIME_VALUED_PATH: [] >
+| < BOOLEAN_VALUED_PATH: [] >
+| < ENTITY_VALUED_PATH: [] >
+| < VALUE_CLASS_VALUED_PATH: [] >
+| < UNKNOWN_PATH: [] >
+| < COLLECTION_VALUED_PATH: [] >
+}
+
+
Property changes on: trunk/server/src/main/jjtree/org/jboss/ejb/plugins/cmp/ejbql/JBossQLParser.jjt
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:mergeinfo
+
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list