|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.josql.expressions.Expression org.josql.expressions.ValueExpression org.josql.expressions.BindVariable
public class BindVariable
This class represents a "bind variable" used within a SQL statement. A bind variable can be either:
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
Field Summary | |
---|---|
static String |
SPECIAL_NAME_PREFIX
|
Constructor Summary | |
---|---|
BindVariable()
|
Method Summary | |
---|---|
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. |
Methods inherited from class org.josql.expressions.Expression |
---|
isBracketed, setBracketed |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String SPECIAL_NAME_PREFIX
Constructor Detail |
---|
public BindVariable()
Method Detail |
---|
public boolean equals(Object o)
equals
in class Object
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.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |