public class QueryTemplate extends QueryBox implements Query
Query that interpolates named parameters inside a template.
Templates are strings with empty XML elements, optionally with a DEFAULT attribute, e.g.:
all results that satisfy <cond1/> or <cond2 def='that'/> <extra/>
Whenever expression() is invoked, the elements in the template are replaced according to the first rule that applies
among the following:
DEFAULT attribute, if one exists
cond1="this", expression() returns:
all results that satisfy this or that
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT |
static String |
STATEMENT |
| Constructor and Description |
|---|
QueryTemplate(String template)
Creates an instance with a template.
|
QueryTemplate(String template,
Map<String,String> parameters)
Creates an instance with a template and an initial set of parameters.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addParameter(String name,
String value)
Adds a parameter to the query, overwriting any value that it may already have.
|
void |
appendParameter(String name,
String value)
Adds a parameter to the query, extending any value that it may already have.
|
String |
expression()
Returns the textual expression of the query.
|
boolean |
hasParameter(String name)
Returns
true if the query has a given parameter. |
String |
parameter(String name)
Returns the current value of a parameter.
|
public static final String DEFAULT
public static final String STATEMENT
public QueryTemplate(String template)
template - the templatepublic String expression()
Queryexpression in interface Queryexpression in class QueryBoxpublic void addParameter(String name, String value)
name - the parameter namevalue - the parameter valueIllegalStateException - if the parameter name or value are nullpublic void appendParameter(String name, String value)
name - the parameter namevalue - the valueIllegalStateException - if the parameter name or value are nullpublic String parameter(String name) throws IllegalStateException
name - the parameter nameIllegalStateException - if the parameter does not existIllegalStateException - if the parameter name is nullpublic boolean hasParameter(String name)
true if the query has a given parameter.name - the parameter nametrue if the query has a given parameter, false otherwiseIllegalStateException - if the parameter name is nullCopyright © 2020. All Rights Reserved.