public class BindVariable extends ValueExpression
Query
object via: Query.setVariable(String,Object)
.
The parser used (javacc generated) is a little picky about "reserved keywords" and as
such you cannot use the following as the names of bind variables: select, from, limit,
execute, on, all, results, where, having, order, by, group. If you must use one of
reserved names then suffix it with "$", i.e. "execute$", "limit$" and so on.Query
object via: Query.setVariable(int,Object)
.
Anonymous variables are assigned an internal integer index starting at 1 and they increase
by 1.Special bind variables are mainly used in function calls however they can also be used just about anywhere.
SELECT :_query, :_allobjs, :_currobj FROM java.lang.Object SELECT name FROM java.io.File WHERE length(:_currobj, name) > :length AND length > avg(:_query,:_allobjs,length) AND path LIKE '%' + ?
It is also possible for bind variables (including the special variables) to have accessors. For example:
SELECT :_query.variables FROM java.lang.Object
Would cause all the bind variables in the query to be returned.
Also, if the ? in the next query is an instance of java.lang.String
.
SELECT ?.length FROM java.lang.Object
Modifier and Type | Field and Description |
---|---|
static String |
SPECIAL_NAME_PREFIX |
Constructor and Description |
---|
BindVariable() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
Object |
evaluate(Object o,
Query q)
Evaluates the value of this bind variable.
|
String |
getAccessor() |
Class |
getExpectedReturnType(Query q)
Get the expected return type.
|
String |
getName() |
Object |
getValue(Object o,
Query q)
Gets the value of this bind variable.
|
boolean |
hasFixedResult(Query q)
Will always return false since a bind variable cannot be fixed.
|
void |
init(Query q)
Initialises this bind variable.
|
boolean |
isAnonymous() |
boolean |
isTrue(Object o,
Query q)
Returns whether the value of this bind variable represents a
true
value. |
void |
setAccessor(String a) |
void |
setAnonymous(boolean v) |
void |
setName(String name) |
String |
toString()
Returns a string version of this bind variable.
|
isBracketed, setBracketed
public static final String SPECIAL_NAME_PREFIX
public String getAccessor()
public void setAccessor(String a)
public Class getExpectedReturnType(Query q) throws QueryParseException
Query.parse(String)
method to ensure that the correct class is returned here.getExpectedReturnType
in class Expression
q
- The Query object.java.lang.Object.class
if the class
cannot be determined.QueryParseException
- If the type cannot be determined.public void init(Query q) throws QueryParseException
init
in class Expression
q
- The Query object.QueryParseException
- If the bind variable cannot be inited.public String getName()
public boolean isAnonymous()
public void setAnonymous(boolean v)
public void setName(String name)
public Object getValue(Object o, Query q) throws QueryExecutionException
getValue
in class ValueExpression
o
- The current object. Note that this variable isn't used in this method.q
- The Query object.QueryExecutionException
- If something goes wrong during the accessing
of the value.public boolean isTrue(Object o, Query q) throws QueryExecutionException
true
value. See: ArithmeticExpression.isTrue(Object,Query)
for details of how
the return value is determined.isTrue
in class Expression
o
- The current object. Not used in this method.q
- The Query object.true
if the bind variable evaluates to true
.QueryExecutionException
- If a problem occurs during evaluation.public Object evaluate(Object o, Query q) throws QueryExecutionException
getValue(Object,Query)
.evaluate
in class ValueExpression
o
- The current object, not used in this method.q
- The Query object.QueryExecutionException
- If there is a problem getting the value.public String toString()
toString
in class Expression
public boolean hasFixedResult(Query q)
hasFixedResult
in class Expression
q
- The Query object.false
always.