Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.josql.expressions
Class BindVariable  view BindVariable download BindVariable.java

java.lang.Object
  extended byorg.josql.expressions.Expression
      extended byorg.josql.expressions.ValueExpression
          extended byorg.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:

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:
getExpectedReturnType in class Expression

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:
init in class Expression

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:
getValue in class ValueExpression

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 true value. See: ArithmeticExpression.isTrue(Object,Query) 55 for details of how the return value is determined.

Specified by:
isTrue in class Expression

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:
evaluate in class ValueExpression

toString

public java.lang.String toString()
Returns a string version of this bind variable. Returns in the form: ? | ":" [ "_" ] Name

Specified by:
toString in class Expression

hasFixedResult

public boolean hasFixedResult(org.josql.Query q)
Will always return false since a bind variable cannot be fixed.

Specified by:
hasFixedResult in class Expression