{ jjtThis.addOpp("/"); }
) ArithmeticFactor()
)*
) #MultDiv(>1)
}
void ArithmeticFactor() #void :
{ boolean negation = false; }
{
(
[
|{negation=true;}] ArithmeticPrimary()
) #Negation(negation)
}
void ArithmeticPrimary() #void :
{}
{
NumericValuedPath() |
NumericLiteral() |
( ArithmeticExpression() ) #ArithmeticParenthetical |
NumericValuedParameter() |
FunctionsReturningNumerics()
}
////////////////////// New or changed elements /////////////////////////////
void StringValue() #void :
{}
{
StringValuedPath() | FunctionsReturningStrings() |
StringLiteral()| StringValuedParameter()
}
////////////////////////////////////////////////////////////////////////////
void StringExpression() #void :
{}
{
StringPrimary() | StringValuedParameter()
}
void StringPrimary() #void :
{}
{
StringValuedPath() |
StringLiteral() |
( StringExpression() ) #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 :
{}
{
(
StringExpression() StringExpression()
) #Concat
|
(
StringExpression()
ArithmeticExpression()
ArithmeticExpression()
) #Substring
////////////////////// New or changed elements /////////////////////////////
|
(
StringExpression()
) #UCase
|
(
StringExpression()
) #LCase
////////////////////////////////////////////////////////////////////////////
}
void FunctionsReturningNumerics() #void :
{}
{
(
StringExpression()
) #Length
|
(
StringExpression() StringExpression()
[ ArithmeticExpression()]
) #Locate
|
(
ArithmeticExpression()
) #Abs
|
(
ArithmeticExpression()
) #Sqrt
|
(
ArithmeticExpression()
ArithmeticExpression()
) #Mod
|
AggregateFunctions()
////////////////////////////////////////////////////////////////////////////
}
void AggregateFunctions() #void:
{}
{
(
[ {jjtThis.distinct="DISTINCT";}] SingleValuedPath()
) #Avg
|
(
[ {jjtThis.distinct="DISTINCT";}] SingleValuedPath()
) #Max
|
(
[ {jjtThis.distinct="DISTINCT";}] SingleValuedPath()
) #Min
|
(
[ {jjtThis.distinct="DISTINCT";}] SingleValuedPath()
) #Sum
|
(
[ {jjtThis.distinct="DISTINCT";}]
(
SingleValuedPath() | EntityBeanValue()
)
) #Count
}
Token CollectionValuedPath() #Path :
{ Token t; }
{
t=
{
initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE);
return t;
}
}
Token IdentificationVariable() #Path :
{ Token t; }
{
t=
{
t.image = t.image.toLowerCase();
initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE);
return t;
}
}
Token AbstractSchema() #AbstractSchema :
{ Token t; }
{
t=
{
jjtThis.abstractSchemaName = t.image;
jjtThis.entity = catalog.getEntityByAbstractSchemaName(t.image);
return t;
}
|
t=
{
jjtThis.abstractSchemaName = t.image;
jjtThis.entity = catalog.getEntityByAbstractSchemaName(t.image);
return t;
}
}
Token Identifier() #Identifier :
{ Token t; }
{
t=
{
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=
{ initPathNode(jjtThis, t.image, EJBQLTypes.NUMERIC_TYPE); }
}
void StringValuedPath() #Path :
{ Token t; }
{
t=
{ initPathNode(jjtThis, t.image, EJBQLTypes.STRING_TYPE); }
}
void DatetimeValuedPath() #Path :
{ Token t; }
{
t=
{ initPathNode(jjtThis, t.image, EJBQLTypes.DATETIME_TYPE); }
}
void BooleanValuedPath() #Path :
{ Token t; }
{
t=
{ initPathNode(jjtThis, t.image, EJBQLTypes.BOOLEAN_TYPE); }
}
void EntityValuedPath() #Path :
{ Token t; }
{
t=
{ initPathNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE); }
}
void ValueClassValuedPath() #Path :
{ Token t; }
{
t=
{ initPathNode(jjtThis, t.image, EJBQLTypes.VALUE_CLASS_TYPE); }
}
void NumericValuedParameter() #Parameter :
{ Token t; }
{
t=
{ initParameterNode(jjtThis, t.image, EJBQLTypes.NUMERIC_TYPE); }
}
void StringValuedParameter() #Parameter :
{ Token t; }
{
t=
{ initParameterNode(jjtThis, t.image, EJBQLTypes.STRING_TYPE); }
}
void DatetimeValuedParameter() #Parameter :
{ Token t; }
{
t=
{ initParameterNode(jjtThis, t.image, EJBQLTypes.DATETIME_TYPE); }
}
void BooleanValuedParameter() #Parameter :
{ Token t; }
{
t=
{ initParameterNode(jjtThis, t.image, EJBQLTypes.BOOLEAN_TYPE); }
}
void EntityValuedParameter() #Parameter :
{ Token t; }
{
t=
{ initParameterNode(jjtThis, t.image, EJBQLTypes.ENTITY_TYPE); }
}
void ValueClassValuedParameter() #Parameter :
{ Token t; }
{
t=
{ initParameterNode(jjtThis, t.image, EJBQLTypes.VALUE_CLASS_TYPE); }
}
void NumericLiteral() #void :
{ Token t; }
{
(
t= { jjtThis.setValue(t.image); }
) #ExactNumericLiteral
|
(
t= { jjtThis.setValue(t.image); }
) #ApproximateNumericLiteral
}
void StringLiteral() #StringLiteral :
{ Token t; }
{
t=
{ jjtThis.value=t.image; }
}
void BooleanLiteral() #BooleanLiteral :
{ Token t; }
{
{ jjtThis.value=true; } | { 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);
}
}
SKIP :
{
" "
| "\t"
| "\n"
| "\r"
}
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" >
}
TOKEN : /* SEPARATORS */
{
< LPAREN: "(" >
| < RPAREN: ")" >
| < COMMA: "," >
| < DOT: "." >
}
TOKEN : /* OPERATORS */
{
< GT: ">" >
| < LT: "<" >
| < EQ: "=" >
| < LE: "<=" >
| < GE: ">=" >
| < NE: "<>" >
| < PLUS: "+" >
| < MINUS: "-" >
| < MULT: "*" >
| < DIV: "/" >
}
TOKEN : /* String Literal */
{
< STRING_LITERAL: "'" (~["'"])* ( "''" (~["'"])* )* "'" >
}
TOKEN : /* Numeric Literal */
{
< INTEGER_LITERAL:
(["l","L"])?
| (["l","L"])?
| (["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"])* ()? (["f","F","d","D"])?
| "." (["0"-"9"])+ ()? (["f","F","d","D"])?
| (["0"-"9"])+ (["f","F","d","D"])?
| (["0"-"9"])+ ()? ["f","F","d","D"]
>
|
< #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
}
TOKEN [IGNORE_CASE] : /* Boolean Literal */
{
< FALSE: "FALSE" >
| < TRUE: "TRUE" >
}
TOKEN : /* IDENTIFIERS */
{
< IDENTIFIER: >
{
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:
[
"\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"
]
>
}
TOKEN : /* PARAMETERS */
{
< UNKNOWN_PARAMETER: "?" >
{
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.
*/
SPECIAL_TOKEN : /* Navigation */
{
< > {
resetPath();
addPath(matchedToken.image.toLowerCase());
} : IN_NAVIGATION
}
SPECIAL_TOKEN :
{
< > { addPath(matchedToken.image); } : IN_NAVIGATION
}
TOKEN :
{
< PART: > {
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: [] >
}