Class BaseWhereAdapter<T>
- java.lang.Object
-
- com.ibm.fhir.database.utils.query.BaseWhereAdapter<T>
-
- Direct Known Subclasses:
WhereAdapter,WhereFragment
public abstract class BaseWhereAdapter<T> extends Object
A piece of a where clause which isn't attached to aSelectstatement allowing getThis() bit to be reused where the statement/whereClause isn't yet established.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseWhereAdapter()For building standalone predicates like filtersprotectedBaseWhereAdapter(PredicateParser pp)Adopts an existing predicate parser
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Tacos(ColumnRef arg)Add ACOS(arg) to the expressionTacos(ExpNode arg)Add ACOS(arg) to the expressionTadd()Add + to the expressionTand()Add an AND to the list of expression tokensTand(ColumnRef ref)Add AND {ref} to the expressionTand(ExpNode predicate)Add AND {predicate} to the expressionTand(String element)Add AND {element} to the expression where {element} is typically a simple column nameTand(String tableAlias, String columnName)Add AND {tableAlias}.{columnName} to the expressionTbind(Double param)Add a bind marker and Double value to the expression.Tbind(Integer param)Add a bind marker and Integer value to the expression.Tbind(Long param)Add a bind marker and Long value to the expression.Tbind(String param)Add a bind marker and its string value to the expression.Tbind(BigDecimal value)Add a bind marker and BigDecimal value to the expression.Tbind(Instant param)Add a bind marker and Instant value to the expression.Tcoalesce(ColumnRef... columnRefs)Add a COALESCE(c1, c2, ...) function.Tcol(String expression)Add a column expression or referenceTcol(String tableAlias, String expression)Add the qualified name {tableAlias}.{expression} to the expressionTcos(ColumnRef arg)Add COS(arg) to the expressionTcos(ExpNode arg)Add COS(arg) to the expressionTdiv()Add / to the expressionTeq()Add an equals '=' node to the expressionTeq(int literalValue)Add '= {literalValue}' to the expressionTeq(long literalValue)Add '= {literalValue}' to the expressionTeq(ColumnRef ref)Add '= {ref}' to the expressionTeq(LiteralString str)Add '= {str}' to the expressionTeq(BindMarkerNode bindMarker)Add a bind marker and value to the expressionTeq(String columnExpression)Add '= {columnExpression}' to the expressionTeq(String tableAlias, String columnExpression)Add '= {tableAlias}.{columnExpression}' to the expressionTescape()Add ESCAPE to the expressionTescape(ColumnRef ref)Add ESCAPE {ref} to the expressionTescape(BindMarkerNode bindMarker)Add ESCAPE ? to the expressionTescape(String str)Add ESCAPE {str} to the expressionTescape(String tableAlias, String columnExpression)Add ESCAPE {tableAlias}.{columnExpression} to the expressionTexists(Select correlatedSubSelect)Add an exists clause using the given correlated sub-select statementTfilter(ExpNode filter)Add the expression directly without any other operatorExpNodegetExpression()Get the expression that has been builtprotected PredicateParsergetPredicateParser()Getter for the predicate parserprotected abstract TgetThis()Returns the sub-class type-specific instance of the class.Tgt()Add > to the expressionTgt(int literalValue)Add > {literalValue} to the expressionTgt(long literalValue)Add > {literalValue} to the expressionTgt(ColumnRef ref)Add > {ref} to the expressionTgt(BindMarkerNode bindMarker)Add a bind marker and its value to the expressionTgt(String literalValue)Add > {literalValue} to the expressionTgte()Add >= to the expressionTgte(int literalValue)Add >= {literalValue} to the expressionTgte(long literalValue)Add >= {literalValue} to the expressionTgte(ColumnRef ref)Add >= {ref} to the expressionTgte(BindMarkerNode bindMarker)Add >= {bindMarker} to the expressionTgte(String literalValue)Add >= {literalValue} to the expressionTin(Long[] inList)Add IN (?, ?, ...) for a list of Long valuesTin(String[] inList)Add IN (?, ?, ...) for a list of String valuesTin(List<String> inList)Thanks to type erasure we can only have one type of list here.TinLiteral(Long[] inList)Add IN (123, 124, ...) for a literal list of Long valuesTinLiteralLong(List<Long> inList)Add IN (123, 124, ...) for a literal list of Long valuesTisNotNull()Add an IS NOT NULL operator to the expressionTisNull()Add an IS NULL operator to the expressionTleftParen()Add a left paren(to the expressionTlike()Add LIKE to the expressionTlike(ColumnRef ref)Add LIKE {ref} to the expressionTlike(BindMarkerNode bindMarker)Add LIKE ? to the expressionTlike(String str)Add LIKE {str} to the expressionTlike(String tableAlias, String columnExpression)Add LIKE {tableAlias}.{columnExpression} to the expressionTliteral(double value)Add a literal double value to the expressionTliteral(long value)Add a literal long value to the expressionTliteral(String value)Add a literal String value to the expressionTlt()Add < to the expressionTlt(int literalValue)Add < {literalValue} to the expressionTlt(long literalValue)Add < {literalValue} to the expressionTlt(ColumnRef ref)Add < {ref} to the expressionTlt(BindMarkerNode bindMarker)Add < {bindMarker} to the expressionTlt(String literalValue)Add < {literalValue} to the expressionTlte()Add <= to the expressionTlte(int literalValue)Add <= {literalValue} to the expressionTlte(long literalValue)Add <= {literalValue} to the expressionTlte(ColumnRef ref)Add <= ref to the expressionTlte(BindMarkerNode bindMarker)Add <= {bindMarker} to the expressionTlte(String literalValue)Add <= {literalValue} to the expressionTmult()Add * to the expressionTneq()Add != to the expressionTneq(int literalValue)Add != {literalValue} to the expressionTneq(long literalValue)Add != {literalValue} to the expressionTneq(ColumnRef ref)Add != {ref} to the expressionTneq(LiteralString str)Add != {str} to the expressionTneq(BindMarkerNode bindMarker)Add a bind marker and its value to the expressionTneq(String literalValue)Add != {literalValue} to the expressionTnot(ExpNode expr)Add NOT to the expressionTnotExists(Select correlatedSubSelect)Add a NOT EXISTS clause using the given correlated sub-select statementToperator(Operator op)Add the operator op to the expressionTor()Add OR to the expressionTor(ColumnRef ref)Add OR {ref} to the expressionTor(ExpNode predicate)Add OR {predicate} to the expressionTor(String element)Add OR {element} to the expression where element is typically a column nameTor(String tableAlias, String columnName)Add OR {tableAlias}.{columnName} to the expressionTradians(ColumnRef arg)Add RADIANS(arg) to the expressionTradians(ExpNode arg)Add RADIANS(arg) to the expressionTrightParen()Add a right paren)to the expressionTsin(ColumnRef arg)Add SIN(arg) to the expressionTsin(ExpNode arg)Add SIN(arg) to the expressionTsub()Add - to the expressionTwhere(String columnName)To simplify code, support multiple where clauses, treating each as an ANDTwhere(String tableAlias, String columnName)To simplify code, support multiple where clauses, treating each as an AND
-
-
-
Constructor Detail
-
BaseWhereAdapter
protected BaseWhereAdapter()
For building standalone predicates like filters
-
BaseWhereAdapter
protected BaseWhereAdapter(PredicateParser pp)
Adopts an existing predicate parser- Parameters:
pp-
-
-
Method Detail
-
getThis
protected abstract T getThis()
Returns the sub-class type-specific instance of the class. Used as the return value in fluent methods.- Returns:
-
getPredicateParser
protected PredicateParser getPredicateParser()
Getter for the predicate parser- Returns:
-
getExpression
public ExpNode getExpression()
Get the expression that has been built- Returns:
-
literal
public T literal(String value)
Add a literal String value to the expression- Parameters:
value-- Returns:
-
literal
public T literal(long value)
Add a literal long value to the expression- Parameters:
value-- Returns:
-
literal
public T literal(double value)
Add a literal double value to the expression- Parameters:
value-- Returns:
-
eq
public T eq()
Add an equals '=' node to the expression- Returns:
-
eq
public T eq(long literalValue)
Add '= {literalValue}' to the expression- Parameters:
literalValue-- Returns:
-
eq
public T eq(int literalValue)
Add '= {literalValue}' to the expression- Parameters:
literalValue-- Returns:
-
eq
public T eq(String columnExpression)
Add '= {columnExpression}' to the expression- Parameters:
literalValue-- Returns:
-
eq
public T eq(LiteralString str)
Add '= {str}' to the expression- Parameters:
str-- Returns:
-
eq
public T eq(String tableAlias, String columnExpression)
Add '= {tableAlias}.{columnExpression}' to the expression- Parameters:
literalValue-- Returns:
-
eq
public T eq(BindMarkerNode bindMarker)
Add a bind marker and value to the expression- Parameters:
bindMarker-- Returns:
-
where
public T where(String columnName)
To simplify code, support multiple where clauses, treating each as an AND- Parameters:
columnName-- Returns:
-
where
public T where(String tableAlias, String columnName)
To simplify code, support multiple where clauses, treating each as an AND- Parameters:
tableAlias-columnName-- Returns:
-
and
public T and()
Add an AND to the list of expression tokens- Returns:
-
and
public T and(ExpNode predicate)
Add AND {predicate} to the expression- Parameters:
predicate-- Returns:
-
and
public T and(String element)
Add AND {element} to the expression where {element} is typically a simple column name
-
and
public T and(String tableAlias, String columnName)
Add AND {tableAlias}.{columnName} to the expression- Parameters:
tableAlias-columnName-- Returns:
-
and
public T and(ColumnRef ref)
Add AND {ref} to the expression- Parameters:
ref- the column reference- Returns:
-
or
public T or()
Add OR to the expression- Returns:
-
or
public T or(ExpNode predicate)
Add OR {predicate} to the expression- Parameters:
predicate-- Returns:
-
or
public T or(String element)
Add OR {element} to the expression where element is typically a column name- Parameters:
element-- Returns:
-
or
public T or(String tableAlias, String columnName)
Add OR {tableAlias}.{columnName} to the expression- Parameters:
tableAlias-columnName-- Returns:
-
or
public T or(ColumnRef ref)
Add OR {ref} to the expression- Parameters:
ref- the column reference- Returns:
-
neq
public T neq()
Add != to the expression- Returns:
-
neq
public T neq(ColumnRef ref)
Add != {ref} to the expression- Parameters:
ref- the column reference- Returns:
-
neq
public T neq(long literalValue)
Add != {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
neq
public T neq(int literalValue)
Add != {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
neq
public T neq(String literalValue)
Add != {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
neq
public T neq(LiteralString str)
Add != {str} to the expression- Parameters:
str- a literal string value- Returns:
-
neq
public T neq(BindMarkerNode bindMarker)
Add a bind marker and its value to the expression- Parameters:
bindMarker-- Returns:
-
gt
public T gt()
Add > to the expression- Returns:
-
gt
public T gt(ColumnRef ref)
Add > {ref} to the expression- Parameters:
ref- the column reference- Returns:
-
gt
public T gt(long literalValue)
Add > {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
gt
public T gt(int literalValue)
Add > {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
gt
public T gt(String literalValue)
Add > {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
gt
public T gt(BindMarkerNode bindMarker)
Add a bind marker and its value to the expression- Parameters:
bindMarker-- Returns:
-
gte
public T gte()
Add >= to the expression- Returns:
-
gte
public T gte(ColumnRef ref)
Add >= {ref} to the expression- Parameters:
ref- the column reference- Returns:
-
gte
public T gte(long literalValue)
Add >= {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
gte
public T gte(int literalValue)
Add >= {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
gte
public T gte(String literalValue)
Add >= {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
gte
public T gte(BindMarkerNode bindMarker)
Add >= {bindMarker} to the expression- Parameters:
bindMarker-- Returns:
-
lt
public T lt()
Add < to the expression- Returns:
-
lt
public T lt(ColumnRef ref)
Add < {ref} to the expression- Parameters:
ref- the column reference- Returns:
-
lt
public T lt(long literalValue)
Add < {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
lt
public T lt(int literalValue)
Add < {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
lt
public T lt(String literalValue)
Add < {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
lt
public T lt(BindMarkerNode bindMarker)
Add < {bindMarker} to the expression- Parameters:
bindMarker-- Returns:
-
lte
public T lte()
Add <= to the expression- Returns:
-
lte
public T lte(long literalValue)
Add <= {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
lte
public T lte(int literalValue)
Add <= {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
lte
public T lte(String literalValue)
Add <= {literalValue} to the expression- Parameters:
literalValue-- Returns:
-
lte
public T lte(BindMarkerNode bindMarker)
Add <= {bindMarker} to the expression- Parameters:
bindMarker-- Returns:
-
col
public T col(String expression)
Add a column expression or reference- Parameters:
expression-- Returns:
-
col
public T col(String tableAlias, String expression)
Add the qualified name {tableAlias}.{expression} to the expression- Parameters:
tableAlias-expression-- Returns:
-
exists
public T exists(Select correlatedSubSelect)
Add an exists clause using the given correlated sub-select statement- Parameters:
correlatedSubSelect-- Returns:
-
notExists
public T notExists(Select correlatedSubSelect)
Add a NOT EXISTS clause using the given correlated sub-select statement- Parameters:
correlatedSubSelect-- Returns:
-
mult
public T mult()
Add * to the expression- Returns:
-
add
public T add()
Add + to the expression- Returns:
-
sub
public T sub()
Add - to the expression- Returns:
-
div
public T div()
Add / to the expression- Returns:
-
coalesce
public T coalesce(ColumnRef... columnRefs)
Add a COALESCE(c1, c2, ...) function. These should actually be column expressions, but for now we only need to model them as table.col values- Parameters:
columnRefs-- Returns:
-
radians
public T radians(ExpNode arg)
Add RADIANS(arg) to the expression- Parameters:
arg-- Returns:
-
radians
public T radians(ColumnRef arg)
Add RADIANS(arg) to the expression- Parameters:
arg-- Returns:
-
isNotNull
public T isNotNull()
Add an IS NOT NULL operator to the expression- Returns:
-
isNull
public T isNull()
Add an IS NULL operator to the expression- Returns:
-
leftParen
public T leftParen()
Add a left paren(to the expression
-
rightParen
public T rightParen()
Add a right paren)to the expression
-
in
public T in(String[] inList)
Add IN (?, ?, ...) for a list of String values- Parameters:
inList-- Returns:
-
in
public T in(List<String> inList)
Thanks to type erasure we can only have one type of list here. No overloading. String is the most likely type of field, so we go with that. Uses bind-markers, not literals.- Parameters:
inList-- Returns:
-
in
public T in(Long[] inList)
Add IN (?, ?, ...) for a list of Long values- Parameters:
inList-- Returns:
-
inLiteral
public T inLiteral(Long[] inList)
Add IN (123, 124, ...) for a literal list of Long values- Parameters:
inList-- Returns:
-
inLiteralLong
public T inLiteralLong(List<Long> inList)
Add IN (123, 124, ...) for a literal list of Long values- Parameters:
inList-- Returns:
-
like
public T like()
Add LIKE to the expression- Returns:
-
like
public T like(String tableAlias, String columnExpression)
Add LIKE {tableAlias}.{columnExpression} to the expression- Parameters:
tableAlias-columnExpression-- Returns:
-
like
public T like(BindMarkerNode bindMarker)
Add LIKE ? to the expression- Parameters:
bindMarker-- Returns:
-
escape
public T escape()
Add ESCAPE to the expression- Returns:
-
escape
public T escape(ColumnRef ref)
Add ESCAPE {ref} to the expression- Parameters:
ref-- Returns:
-
escape
public T escape(String tableAlias, String columnExpression)
Add ESCAPE {tableAlias}.{columnExpression} to the expression- Parameters:
tableAlias-columnExpression-- Returns:
-
escape
public T escape(BindMarkerNode bindMarker)
Add ESCAPE ? to the expression- Parameters:
bindMarker-- Returns:
-
filter
public T filter(ExpNode filter)
Add the expression directly without any other operator- Parameters:
filter-- Returns:
-
bind
public T bind(String param)
Add a bind marker and its string value to the expression. Handles null.- Parameters:
param-- Returns:
-
bind
public T bind(Long param)
Add a bind marker and Long value to the expression. Handles null.- Parameters:
param-- Returns:
-
bind
public T bind(Integer param)
Add a bind marker and Integer value to the expression. Handles null.- Parameters:
param-- Returns:
-
bind
public T bind(Double param)
Add a bind marker and Double value to the expression. Handles null.- Parameters:
param-- Returns:
-
bind
public T bind(Instant param)
Add a bind marker and Instant value to the expression. Handles null.- Parameters:
param-- Returns:
-
bind
public T bind(BigDecimal value)
Add a bind marker and BigDecimal value to the expression. Handles null.- Parameters:
param-- Returns:
-
-