Class PredicateParser
- java.lang.Object
-
- org.linuxforhealth.fhir.database.utils.query.node.PredicateParser
-
public class PredicateParser extends java.lang.ObjectBasically follows Dijkstra's shunting yard algorithm to ensure correct handling of operator precedence as the expression nodes are added
-
-
Constructor Summary
Constructors Constructor Description PredicateParser()Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd()Add an addition + node to the expressionvoidaddToken(ExpNode token)Allow expression nodes to be added directly to the list of tokens.voidand()Push an AND node to the stack, taking into account precedencevoidbetween()Add a BETWEEN node to the expressionvoidbindMarker(BindMarkerNode node)Add a bind marker ? and its value to the expressionvoidcolumn(java.lang.String columnName)Push a node representing the column reference onto the stackvoidcolumn(java.lang.String tableAlias, java.lang.String columnName)Add a column to the expressionvoiddiv()Add a division node to the expressionvoideq()Add an EQ node to the expressionvoidescape()Add an ESCAPE node to the expressionvoidgt()Add a GT > node to the expressionvoidgte()Add a GTE >= node to the expressionvoidinLiteral(java.lang.Long[] inList)Convenience function to add an IN list of literal long values.voidinLiteral(java.lang.String[] inList)Convenience function to add an IN list of literal string values.voidinLong(java.util.List<java.lang.Long> inList)Convenience function to add an IN list of `` bind markers voidinString(java.util.List<java.lang.String> inList)Convenience function to add an IN list of `` bind markers booleanisEmpty()Check if anything has been added to this parservoidisNotNull()Add an IS NOT NULL node to the expression tokensvoidisNull()Add an IS NULL node to the expression tokensvoidleftParen()Add a LEFT PAREN ( node to the expressionvoidlike()Add a LIKE node to the expressionvoidliteral(java.lang.Double dbl)Add a Double literal to the expressionvoidliteral(java.lang.Long lng)Add a Long literal to the expressionvoidliteral(java.lang.String str)Add a string literal to the expressionvoidlt()Add a LT < node to the expressionvoidlte()Add a LTE <= node to the expressionvoidmult()Add a multiplication node to the expressionvoidneq()Add a NEQ node to the expressionvoidnot()Add a NOT node to the expressionvoidor()Push an or node to the stack, taking into account precedenceExpNodeparse()Applies the shunting-yard algorithm, collapsing the operatorStack as much as possible.java.lang.StringparserState()Get a list of the nodes as a string, to help debug expression building and parsing.voidrightParen()Add a RIGHT PAREN ) node to the expressionvoidsub()Add a subtraction node to the expression
-
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Check if anything has been added to this parser- Returns:
- true if nothing has been added
-
parse
public ExpNode parse()
Applies the shunting-yard algorithm, collapsing the operatorStack as much as possible. If the expression is valid, there should be a single node sitting on the operandStack.- Returns:
-
parserState
public java.lang.String parserState()
Get a list of the nodes as a string, to help debug expression building and parsing. We don't use the visitor, because the expression node might not be fully configured- Returns:
-
column
public void column(java.lang.String columnName)
Push a node representing the column reference onto the stack- Parameters:
columnName-
-
column
public void column(java.lang.String tableAlias, java.lang.String columnName)Add a column to the expression- Parameters:
tableAlias-columnName-
-
literal
public void literal(java.lang.String str)
Add a string literal to the expression- Parameters:
str-
-
literal
public void literal(java.lang.Double dbl)
Add a Double literal to the expression- Parameters:
dbl-
-
literal
public void literal(java.lang.Long lng)
Add a Long literal to the expression- Parameters:
lng-
-
and
public void and()
Push an AND node to the stack, taking into account precedence
-
or
public void or()
Push an or node to the stack, taking into account precedence
-
eq
public void eq()
Add an EQ node to the expression
-
like
public void like()
Add a LIKE node to the expression
-
escape
public void escape()
Add an ESCAPE node to the expression
-
neq
public void neq()
Add a NEQ node to the expression
-
gt
public void gt()
Add a GT > node to the expression
-
gte
public void gte()
Add a GTE >= node to the expression
-
lt
public void lt()
Add a LT < node to the expression
-
lte
public void lte()
Add a LTE <= node to the expression
-
not
public void not()
Add a NOT node to the expression
-
between
public void between()
Add a BETWEEN node to the expression
-
add
public void add()
Add an addition + node to the expression
-
sub
public void sub()
Add a subtraction node to the expression
-
mult
public void mult()
Add a multiplication node to the expression
-
div
public void div()
Add a division node to the expression
-
leftParen
public void leftParen()
Add a LEFT PAREN ( node to the expression
-
rightParen
public void rightParen()
Add a RIGHT PAREN ) node to the expression
-
bindMarker
public void bindMarker(BindMarkerNode node)
Add a bind marker ? and its value to the expression- Parameters:
node-
-
inLiteral
public void inLiteral(java.lang.String[] inList)
Convenience function to add an IN list of literal string values. This should be used only where the string values are internal values, never input data. If the values come from input data, then for security it is important to use bind markers instead.- Parameters:
inList-
-
inLiteral
public void inLiteral(java.lang.Long[] inList)
Convenience function to add an IN list of literal long values.- Parameters:
inList-
-
inString
public void inString(java.util.List<java.lang.String> inList)
Convenience function to add an IN list of `` bind markers - Parameters:
bindMarkerCount-
-
inLong
public void inLong(java.util.List<java.lang.Long> inList)
Convenience function to add an IN list of `` bind markers - Parameters:
bindMarkerCount-
-
addToken
public void addToken(ExpNode token)
Allow expression nodes to be added directly to the list of tokens. Wrap non-operands in a paren to ensure the expression is treated atomically, which is the intent of this method.- Parameters:
node-
-
isNotNull
public void isNotNull()
Add an IS NOT NULL node to the expression tokens
-
isNull
public void isNull()
Add an IS NULL node to the expression tokens
-
-