org.objectweb.jonas_ejb.lib
Class EjbqlQueryFilterVisitor

java.lang.Object
  extended by org.objectweb.jonas_ejb.lib.EjbqlAbstractVisitor
      extended by org.objectweb.jonas_ejb.lib.EjbqlQueryFilterVisitor
All Implemented Interfaces:
EJBQLVisitor

public class EjbqlQueryFilterVisitor
extends EjbqlAbstractVisitor

Implementation of a visitor that creates the filter corresponding to the WHERE clause. Created on Sep 6, 2002

Author:
Christophe Ney [cney@batisseurs.com] : Intial developer, Helene Joanin: Take into account the following operators abs(x), sqrt(x), length(str), substring(s, start, length), locate(str1, str2), locate(str1, str2, start)., Helene Joanin: EJBLocalObject as parameter of a EJB-QL query., Helene Joanin: Take into account the InExpression (IN operator)., Helene Joanin: Take into account the IS NULL operator., Helene Joanin: Fix a bug in the visitor for ASTIdentificationVariable: push a BasicFieldOperand(field) instead of the field itself., Helene Joanin: add '.element' to the path for CollectionValuedPathExpression., Helene Joanin: Convert IsNull(cmr-field) to Equal(cmr-field, PNameNull)., Helene Joanin: Take into account the operators: IS EMPTY / IS NOT EMPTY, Helene Joanin: Take into account the CONCAT operator, Helene Joanin: Take into account the EJBQL version 2.1 syntax., Helene Joanin: Take into account the operator MOD., Helene Joanin: Take into account the operator ISNULL with a parameter.

Nested Class Summary
 
Nested classes/interfaces inherited from class org.objectweb.jonas_ejb.lib.EjbqlAbstractVisitor
EjbqlAbstractVisitor.IdValue, EjbqlAbstractVisitor.VisitorException
 
Constructor Summary
EjbqlQueryFilterVisitor(org.objectweb.jorm.api.PMapper _mapper, java.util.Map _fields, java.lang.Class[] parameterTypes, ASTEJBQL ejbql, org.objectweb.medor.query.jorm.lib.QueryBuilder qb)
          Constructor
 
Method Summary
 org.objectweb.medor.expression.api.Expression getQueryFilter()
          get the query filter that was built from visiting the syntaxic tree
 java.lang.Object visit(ASTArithmeticExpression node, java.lang.Object data)
          Push corresponding Expression to the stack.
arithmetic_expression ::= arithmetic_term [ { + | - } arithmetic_term ] *
 java.lang.Object visit(ASTArithmeticFactor node, java.lang.Object data)
          Push corresponding Expression to the stack.
arithmetic_factor ::= [ + |- ] arithmetic_primary
 java.lang.Object visit(ASTArithmeticLiteral node, java.lang.Object data)
          Visit child nodes arithmetic_literal ::= integer_literal | floatingpoint_literal
 java.lang.Object visit(ASTArithmeticTerm node, java.lang.Object data)
          Push corresponding Expression to the stack.
arithmetic_term ::= arithmetic_factor [ { * | / } arithmetic_factor ]*
 java.lang.Object visit(ASTBetweenExpression node, java.lang.Object data)
          Push corresponding Expression to the stack.
between_expression ::= arithmetic_expression [ NOT ] BETWEEN arithmetic_expression AND arithmetic_expression
 java.lang.Object visit(ASTBooleanExpression node, java.lang.Object data)
          Visit child nodes boolean_expression ::= cmp_path_expression | boolean_literal | input_parameter
 java.lang.Object visit(ASTBooleanLiteral node, java.lang.Object data)
          Node with value set to litteral boolean.
 java.lang.Object visit(ASTCmpPathExpression node, java.lang.Object data)
          Push corresponding MedorField to the stack.
cmp_path_expression ::= path was in initial BNF cmp_path_expression ::= identification_variable.
 java.lang.Object visit(ASTCollectionMemberExpression node, java.lang.Object data)
          Push corresponding Expression to the stack.
collection_member_expression ::= {single_valued_cmr_path_expression | identification_variable | input_parameter} [ NOT ] MEMBER [ OF ] collection_valued_path_expression
 java.lang.Object visit(ASTCollectionValuedPathExpression node, java.lang.Object data)
          Push corresponding MedorField to the stack.
collection_valued_path_expression ::= path was in initial BNF collection_valued_path_expression ::= identification_variable.
 java.lang.Object visit(ASTComparisonExpression node, java.lang.Object data)
          Push corresponding Expression to the stack.
comparison_expression ::= string_value { = | > | >= | < | <= | <> } string_expression | boolean_value { = | <>} boolean_expression | datetime_value { = | > | >= | < | <= | <> } datetime_expression | entity_bean_value { = | <> } entity_bean_expression | arithmetic_value { = | > | >= | < | <= | <> } single_value_designator
 java.lang.Object visit(ASTConditionalExpression node, java.lang.Object data)
          Push corresponding Expression to the stack.
conditional_expression ::= conditional_term [ OR conditional_term ]*
 java.lang.Object visit(ASTConditionalFactor node, java.lang.Object data)
          Push corresponding Expression to the stack.
conditional_factor ::= [ NOT ] conditional_test
 java.lang.Object visit(ASTConditionalTerm node, java.lang.Object data)
          Push corresponding Expression to the stack.
conditional_term ::= conditional_factor [ AND conditional_factor ]*
 java.lang.Object visit(ASTDatetimeExpression node, java.lang.Object data)
          Visit child nodes datetime_expression ::= datetime_value | input_parameter
 java.lang.Object visit(ASTEmptyCollectionComparisonExpression node, java.lang.Object data)
          Nothing to do: Already taken into account in EjbqlVariableVisitor at the variables parsing, so, just push the OP_IGNORE in the stack empty_collection_comparison_expression ::= collection_valued_path_expression IS [ NOT ] EMPTY
 java.lang.Object visit(ASTEntityBeanExpression node, java.lang.Object data)
          Visit child nodes entity_bean_expression ::= entity_bean_value | input_parameter
 java.lang.Object visit(ASTFloatingPointLiteral node, java.lang.Object data)
          Node with value set to integer litteral arithmetic.
 java.lang.Object visit(ASTFunctionsReturningNumerics node, java.lang.Object data)
          visit child nodes Push corresponding Expression to the stack.
functions_returning_numerics ::= LENGTH (string_expression) | LOCATE (string_expression, string_expression [ , arithmetic_expression ] ) | ABS (arithmetic_expression) | SQRT (arithmetic_expression) | MOD (arithmetic_expression , arithmetic_expression)
 java.lang.Object visit(ASTFunctionsReturningStrings node, java.lang.Object data)
          visit child nodes Push corresponding Expression to the stack.
functions_returning_strings ::= CONCAT (string_expression, string_expression) | SUBSTRING (string_expression,arithmetic_expression,arithmetic_expression)
 java.lang.Object visit(ASTIdentificationVariable node, java.lang.Object data)
          Node with value set to identification variable string.
 java.lang.Object visit(ASTInExpression node, java.lang.Object data)
          Push corresponding Expression to the stack.
in_expression ::= cmp_path_expression [ NOT ] IN {literal|input_parameter} [ , {literal|input_parameter} ] * )
 java.lang.Object visit(ASTInputParameter node, java.lang.Object data)
          Node with value set to parameter index (1..n) string.
 java.lang.Object visit(ASTIntegerLiteral node, java.lang.Object data)
          Node with value set to integer litteral arithmetic.
 java.lang.Object visit(ASTLikeExpression node, java.lang.Object data)
          Push corresponding Expression to the stack.
like_expression ::= cmp_path_expression [ NOT ] LIKE pattern_value [ ESCAPE escape_character ]
 java.lang.Object visit(ASTLiteral node, java.lang.Object data)
          Visit child nodes literal ::= string_literal | arithmetic_literal | boolean_literal
 java.lang.Object visit(ASTNullComparisonExpression node, java.lang.Object data)
          Push corresponding Expression to the stack.
null_comparison_expression ::= {single_valued_path_expression|input_parameter} IS [ NOT ] NULL
 java.lang.Object visit(ASTPath node, java.lang.Object data)
          Push the Node to the stack
 java.lang.Object visit(ASTSingleValuedCmrPathExpression node, java.lang.Object data)
          Push corresponding MedorField to the stack.
single_valued_cmr_path_expression ::= path was in initial BNF single_valued_cmr_path_expression ::= identification_variable.
 java.lang.Object visit(ASTSingleValuedPathExpression node, java.lang.Object data)
          Push corresponding MedorField to the stack.
single_valued_path_expression ::= path was in initial BNF single_valued_path_expression ::= cmp_path_expression | single_valued_cmr_path_expression
 java.lang.Object visit(ASTStringExpression node, java.lang.Object data)
          Visit child nodes string_expression ::= string_primary | input_parameter
 java.lang.Object visit(ASTStringLiteral node, java.lang.Object data)
          Node with value set to litteral string.
 java.lang.Object visit(ASTWhereClause node, java.lang.Object data)
          If query contains WHERE clause, visit child nodes
where_clause ::= WHERE conditional_expression
 
Methods inherited from class org.objectweb.jonas_ejb.lib.EjbqlAbstractVisitor
basePath, endsWith, mergePath, mergePath, splitPath, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EjbqlQueryFilterVisitor

public EjbqlQueryFilterVisitor(org.objectweb.jorm.api.PMapper _mapper,
                               java.util.Map _fields,
                               java.lang.Class[] parameterTypes,
                               ASTEJBQL ejbql,
                               org.objectweb.medor.query.jorm.lib.QueryBuilder qb)
                        throws java.lang.Exception
Constructor

Parameters:
_mapper - the mapper of each fields. Needed to build the expression for the IsNull with a reference as an operand. This parameter may be null in case of the GenIC phase
_fields - QueryTreeFields for all defined identifiers and all path expression of the query
parameterTypes - Type of paramaters of the finder/select method
ejbql - root of the lexical tree of the query
Throws:
java.lang.Exception
Method Detail

getQueryFilter

public org.objectweb.medor.expression.api.Expression getQueryFilter()
get the query filter that was built from visiting the syntaxic tree


visit

public java.lang.Object visit(ASTWhereClause node,
                              java.lang.Object data)
If query contains WHERE clause, visit child nodes
where_clause ::= WHERE conditional_expression

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTSingleValuedPathExpression node,
                              java.lang.Object data)
Push corresponding MedorField to the stack.
single_valued_path_expression ::= path was in initial BNF single_valued_path_expression ::= cmp_path_expression | single_valued_cmr_path_expression

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTCmpPathExpression node,
                              java.lang.Object data)
Push corresponding MedorField to the stack.
cmp_path_expression ::= path was in initial BNF cmp_path_expression ::= identification_variable. [ single_valued_cmr_field. ] * cmp_field

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTSingleValuedCmrPathExpression node,
                              java.lang.Object data)
Push corresponding MedorField to the stack.
single_valued_cmr_path_expression ::= path was in initial BNF single_valued_cmr_path_expression ::= identification_variable. [ single_valued_cmr_field. ] * single_valued_cmr_field

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTCollectionValuedPathExpression node,
                              java.lang.Object data)
Push corresponding MedorField to the stack.
collection_valued_path_expression ::= path was in initial BNF collection_valued_path_expression ::= identification_variable. [ single_valued_cmr_field. ] *collection_valued_cmr_field

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTConditionalExpression node,
                              java.lang.Object data)
Push corresponding Expression to the stack.
conditional_expression ::= conditional_term [ OR conditional_term ]*

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTConditionalTerm node,
                              java.lang.Object data)
Push corresponding Expression to the stack.
conditional_term ::= conditional_factor [ AND conditional_factor ]*

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTConditionalFactor node,
                              java.lang.Object data)
Push corresponding Expression to the stack.
conditional_factor ::= [ NOT ] conditional_test

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTBetweenExpression node,
                              java.lang.Object data)
Push corresponding Expression to the stack.
between_expression ::= arithmetic_expression [ NOT ] BETWEEN arithmetic_expression AND arithmetic_expression

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTInExpression node,
                              java.lang.Object data)
Push corresponding Expression to the stack.
in_expression ::= cmp_path_expression [ NOT ] IN {literal|input_parameter} [ , {literal|input_parameter} ] * )

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTLikeExpression node,
                              java.lang.Object data)
Push corresponding Expression to the stack.
like_expression ::= cmp_path_expression [ NOT ] LIKE pattern_value [ ESCAPE escape_character ]

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTNullComparisonExpression node,
                              java.lang.Object data)
Push corresponding Expression to the stack.
null_comparison_expression ::= {single_valued_path_expression|input_parameter} IS [ NOT ] NULL

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTEmptyCollectionComparisonExpression node,
                              java.lang.Object data)
Nothing to do: Already taken into account in EjbqlVariableVisitor at the variables parsing, so, just push the OP_IGNORE in the stack empty_collection_comparison_expression ::= collection_valued_path_expression IS [ NOT ] EMPTY

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTCollectionMemberExpression node,
                              java.lang.Object data)
Push corresponding Expression to the stack.
collection_member_expression ::= {single_valued_cmr_path_expression | identification_variable | input_parameter} [ NOT ] MEMBER [ OF ] collection_valued_path_expression

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTComparisonExpression node,
                              java.lang.Object data)
Push corresponding Expression to the stack.
comparison_expression ::= string_value { = | > | >= | < | <= | <> } string_expression | boolean_value { = | <>} boolean_expression | datetime_value { = | > | >= | < | <= | <> } datetime_expression | entity_bean_value { = | <> } entity_bean_expression | arithmetic_value { = | > | >= | < | <= | <> } single_value_designator

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTArithmeticExpression node,
                              java.lang.Object data)
Push corresponding Expression to the stack.
arithmetic_expression ::= arithmetic_term [ { + | - } arithmetic_term ] *

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTArithmeticTerm node,
                              java.lang.Object data)
Push corresponding Expression to the stack.
arithmetic_term ::= arithmetic_factor [ { * | / } arithmetic_factor ]*

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTArithmeticFactor node,
                              java.lang.Object data)
Push corresponding Expression to the stack.
arithmetic_factor ::= [ + |- ] arithmetic_primary

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTStringExpression node,
                              java.lang.Object data)
Visit child nodes string_expression ::= string_primary | input_parameter

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTDatetimeExpression node,
                              java.lang.Object data)
Visit child nodes datetime_expression ::= datetime_value | input_parameter

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTBooleanExpression node,
                              java.lang.Object data)
Visit child nodes boolean_expression ::= cmp_path_expression | boolean_literal | input_parameter

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTEntityBeanExpression node,
                              java.lang.Object data)
Visit child nodes entity_bean_expression ::= entity_bean_value | input_parameter

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTFunctionsReturningStrings node,
                              java.lang.Object data)
visit child nodes Push corresponding Expression to the stack.
functions_returning_strings ::= CONCAT (string_expression, string_expression) | SUBSTRING (string_expression,arithmetic_expression,arithmetic_expression)

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTFunctionsReturningNumerics node,
                              java.lang.Object data)
visit child nodes Push corresponding Expression to the stack.
functions_returning_numerics ::= LENGTH (string_expression) | LOCATE (string_expression, string_expression [ , arithmetic_expression ] ) | ABS (arithmetic_expression) | SQRT (arithmetic_expression) | MOD (arithmetic_expression , arithmetic_expression)

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTIdentificationVariable node,
                              java.lang.Object data)
Node with value set to identification variable string. Push the Node to the stack

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTLiteral node,
                              java.lang.Object data)
Visit child nodes literal ::= string_literal | arithmetic_literal | boolean_literal

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTStringLiteral node,
                              java.lang.Object data)
Node with value set to litteral string. Push the corresponding Operand to the stack

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTArithmeticLiteral node,
                              java.lang.Object data)
Visit child nodes arithmetic_literal ::= integer_literal | floatingpoint_literal

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTIntegerLiteral node,
                              java.lang.Object data)
Node with value set to integer litteral arithmetic. Push the corresponding Operand to the stack

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTFloatingPointLiteral node,
                              java.lang.Object data)
Node with value set to integer litteral arithmetic. Push the corresponding Operand to the stack

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTBooleanLiteral node,
                              java.lang.Object data)
Node with value set to litteral boolean. Push the corresponding Operand to the stack

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTInputParameter node,
                              java.lang.Object data)
Node with value set to parameter index (1..n) string. Push the corresponding Operand to the stack

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null

visit

public java.lang.Object visit(ASTPath node,
                              java.lang.Object data)
Push the Node to the stack

Specified by:
visit in interface EJBQLVisitor
Overrides:
visit in class EjbqlAbstractVisitor
Parameters:
node - the node to visit
data - the current stack
Returns:
null