|
|||||||||
| Home >> All >> org >> josql >> [ expressions overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.josql.expressions
Class BindVariable

java.lang.Objectorg.josql.expressions.Expression
org.josql.expressions.ValueExpression
org.josql.expressions.BindVariable
- public class BindVariable
- extends ValueExpression
This class represents a "bind variable" used within a SQL statement. A bind variable can be either:
- Named - a named bind variable is prefixed with ":", the value of the
variable is set in the org.josql.Query object via: Query.setVariable(String,Object)>
Query.setVariable(String,Object)55 . 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. - Anonymous - an anonymous bind variable is represented as "?". The value of the
variable is set in the org.josql.Query object via: Query.setVariable(int,Object)>
Query.setVariable(int,Object)55 . Anonymous variables are assigned an internal integer index starting at 1 and they increase by 1. - Special - there are 3 types of "special" bind variable:
- :_currobj - Indicates the current object within the execution scope.
- :_allobjs - Indicates the current set of objects within the execution scope.
- :_query - Indicates the Query object.
- :_grpby - Indicates the Group By object. If there are more than 1 group by objects then :_grpby1 ... :_grpby2 ... :_grpbyX can be used to identify which group by object you mean. Remember that the group by object only has meaning if there is a group by statement.
- :_grpbys - Indicates the set of group bys, this will be a list of lists, one list for each group by key, and each group by column will be in that list.
- :_groupby - A synonym for :_grpby.
- :_groupbys - A synonym for :_grpbys.
Special bind variables are mainly used in function calls however they can also be used just about anywhere.
Examples
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 '%' + ?
Accessors
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
Last Modified By: $Author: barrygently $
Last Modified On: $Date: 2004/12/20 16:22:43 $
Current Revision: $Revision: 1.2 $
| Field Summary | |
private java.lang.String |
acc
|
private boolean |
anon
|
private Getter |
get
|
private int |
groupByInd
|
private boolean |
groupByVar
|
private java.lang.String |
name
|
static java.lang.String |
SPECIAL_NAME_PREFIX
|
private static java.util.Map |
SPECIAL_VAR_NAMES
|
private java.lang.Object |
val
|
| Fields inherited from class org.josql.expressions.Expression |
|
| Constructor Summary | |
BindVariable()
|
|
| Method Summary | |
java.lang.Object |
evaluate(java.lang.Object o,
org.josql.Query q)
Evaluates the value of this bind variable. |
java.lang.Class |
getExpectedReturnType(org.josql.Query q)
Get the expected return type. |
java.lang.String |
getName()
|
java.lang.Object |
getValue(java.lang.Object o,
org.josql.Query q)
Gets the value of this bind variable. |
boolean |
hasFixedResult(org.josql.Query q)
Will always return false since a bind variable cannot be fixed. |
void |
init(org.josql.Query q)
Initialises this bind variable. |
private void |
initGetter(java.lang.Class c)
|
private void |
initGetter(java.lang.Object o)
|
boolean |
isAnonymous()
|
boolean |
isTrue(java.lang.Object o,
org.josql.Query q)
Returns whether the value of this bind variable represents a true
value. |
void |
setAccessor(java.lang.String a)
|
void |
setAnonymous(boolean v)
|
void |
setName(java.lang.String name)
|
java.lang.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, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
SPECIAL_NAME_PREFIX
public static final java.lang.String SPECIAL_NAME_PREFIX
- See Also:
- Constant Field Values
SPECIAL_VAR_NAMES
private static java.util.Map SPECIAL_VAR_NAMES
name
private java.lang.String name
val
private java.lang.Object val
anon
private boolean anon
acc
private java.lang.String acc
get
private Getter get
groupByVar
private boolean groupByVar
groupByInd
private int groupByInd
| Constructor Detail |
BindVariable
public BindVariable()
| Method Detail |
setAccessor
public void setAccessor(java.lang.String a)
getExpectedReturnType
public java.lang.Class getExpectedReturnType(org.josql.Query q) throws org.josql.QueryParseException
- Get the expected return type.
The exact class returned here is dependent (obviously) on what the bind variable
represents. Wherever possible it attempts to get the most specific class for the
variable. It is generally better to set the variables prior to executing the:
Query.parse(String)>
Query.parse(String)55 method to ensure that the correct class is returned here.- Specified by:
getExpectedReturnTypein classExpression
init
public void init(org.josql.Query q) throws org.josql.QueryParseException
- Initialises this bind variable.
If the bind variable is "anonymous" then a name is gained for it from the
Query object. If there is a value then it is gained from the Query object and
cached. Also, if there is an accessor defined then it is inited where possible.
- Specified by:
initin classExpression
getName
public java.lang.String getName()
isAnonymous
public boolean isAnonymous()
setAnonymous
public void setAnonymous(boolean v)
setName
public void setName(java.lang.String name)
initGetter
private void initGetter(java.lang.Object o)
initGetter
private void initGetter(java.lang.Class c)
getValue
public java.lang.Object getValue(java.lang.Object o, org.josql.Query q) throws org.josql.QueryExecutionException
- Gets the value of this bind variable.
- Overrides:
getValuein classValueExpression
isTrue
public boolean isTrue(java.lang.Object o, org.josql.Query q) throws org.josql.QueryExecutionException
- Returns whether the value of this bind variable represents a
truevalue. See:ArithmeticExpression.isTrue(Object,Query)55 for details of how the return value is determined.- Specified by:
isTruein classExpression
evaluate
public java.lang.Object evaluate(java.lang.Object o, org.josql.Query q) throws org.josql.QueryExecutionException
- Evaluates the value of this bind variable. This is just a thin-wrapper around:
getValue(Object,Query)55 .- Specified by:
evaluatein classValueExpression
toString
public java.lang.String toString()
- Returns a string version of this bind variable.
Returns in the form: ? | ":" [ "_" ] Name
- Specified by:
toStringin classExpression
hasFixedResult
public boolean hasFixedResult(org.josql.Query q)
- Will always return false since a bind variable cannot be fixed.
- Specified by:
hasFixedResultin classExpression
|
|||||||||
| Home >> All >> org >> josql >> [ expressions overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC