// BNF used to write the JJT file
// $Id: bnf_ejbql_2_1.txt 15428 2008-10-07 11:20:29Z sauthieg $
// @author Helene Joanin [Helene.Joanin@bull.net]

EJB_QL ::= select_clause from_clause  [ where_clause ] [ orderby_clause ] <EOF>

from_clause ::= FROM identification_variable_declaration  [ , identification_variable_declaration ] *

identification_variable_declaration ::= collection_member_declaration | range_variable_declaration

collection_member_declaration ::= IN (collection_valued_path_expression) [ AS ] identifier

range_variable_declaration ::= abstract_schema_name  [ AS ] identifier

//single_valued_path_expression ::= cmp_path_expression | single_value_cmr_path_expression
single_valued_path_expression ::= path

//cmp_path_expression ::= {identification_variable | single_valued_cmr_path_expression}.cmp_field
cmp_path_expression ::= path

//single_valued_cmr_path_expression ::= {identification_variable | single_valued_cmr_path_expression}.single_valued_cmr_field
single_valued_cmr_path_expression ::= path

// collection_valued_path_expression ::= identification_variable. [ single_valued_cmr_field. ] *collection_valued_cmr_field
collection_valued_path_expression ::= path

select_clause ::= SELECT  [ DISTINCT ] {select_expression | OBJECT (identification_variable)}

select_expression ::= single_valued_path_expression | aggregate_select_expression

//aggregate_select_expression ::= {AVG | MAX | MIN | SUM | COUNT} ( [DISTRINCT] cmp_path_expression )
//  | COUNT ( [DISTINCT] identification_variable | single_valued_cmr_path_expression )
aggregate_select_expression ::= {AVG | MAX | MIN | SUM} ( [DISTRINCT] cmp_path_expression )
  | COUNT ( [DISTINCT] identification_variable | single_valued_path_expression )

orderby_clause ::= ORDER BY orderby_item [ , orderby_item ] *

orderby_item ::= cmp_path_expression [ ASC | DESC ]

where_clause ::= WHERE conditional_expression

conditional_expression ::= conditional_term [ OR conditional_term ]*

conditional_term ::= conditional_factor [ AND conditional_factor ]*

conditional_factor ::= [ NOT ] conditional_primary

conditional_primary ::= simple_cond_expression | (conditional_expression)

simple_cond_expression ::= comparison_expression
  | between_expression | like_expression
  | in_expression | null_comparison_expression
  | empty_collection_comparison_expression | collection_member_expression

between_expression ::= arithmetic_expression  [ NOT ] BETWEEN arithmetic_expression AND arithmetic_expression

in_expression ::= cmp_path_expression  [ NOT ] IN ( {literal | input_parameter}  [ , {literal | input_parameter} ] * )

like_expression ::= cmp_path_expression  [ NOT ] LIKE pattern_value  [ ESCAPE escape_character ]

null_comparison_expression ::= {single_valued_path_expression | input_parameter} IS  [ NOT ] NULL

empty_collection_comparison_expression ::= collection_valued_path_expression IS  [ NOT ] EMPTY

collection_member_expression ::= {single_valued_cmr_path_expression | identification_variable | input_parameter}
  [ NOT ] MEMBER  [ OF ] collection_valued_path_expression

comparison_expression ::= string_value { = | > | >= | < | <= | <> } string_expression
  | boolean_value { =|<>} boolean_expression
  | datetime_value { = | > | >= | < | <= | <> } datetime_expression
  | entity_bean_value { = | <> } entity_bean_expression
  | arithmetic_value { = | > | >= | < | <= | <> } arithmetic_expression

arithmetic_value ::= cmp_path_expression | functions_returning_numerics

arithmetic_expression ::= arithmetic_term [ { + | - } arithmetic_term ] *

arithmetic_term ::= arithmetic_factor [ { * | / } arithmetic_factor ]*

arithmetic_factor ::= [ + |- ] arithmetic_primary

arithmetic_primary ::= cmp_path_expression | arithmetic_literal | (arithmetic_expression)
  | input_parameter | functions_returning_numerics

string_value ::= cmp_path_expression | functions_returning_strings

string_expression ::= string_primary | input_parameter

string_primary ::= cmp_path_expression | string_literal | (string_expression) | functions_returning_strings

datetime_value ::= cmp_path_expression

datetime_expression ::= datetime_value | input_parameter

boolean_value ::= cmp_path_expression

boolean_expression ::= cmp_path_expression | boolean_literal | input_parameter

entity_bean_value ::= single_valued_cmr_path_expression | identification_variable

entity_bean_expression ::= entity_bean_value | input_parameter

functions_returning_strings ::= CONCAT (string_expression, string_expression)
  | SUBSTRING (string_expression, arithmetic_expression, arithmetic_expression)

functions_returning_numerics ::= LENGTH (string_expression)
  | LOCATE (string_expression, string_expression [ , arithmetic_expression ] )
  | ABS (arithmetic_expression)
  | SQRT (arithmetic_expression)
  | MOD (arithmetic_expression , arithmetic_expression)


// additional definitions
literal ::= string_literal | arithmetic_literal | boolean_literal
pattern_value ::= string_literal | input_parameter
boolean_literal ::= TRUE|FALSE
abstract_schema_name ::= id
identification_variable ::= id
identifier ::= id

