com.triactive.jdo.store.sql.expr
Interface SqlExpression

All Superinterfaces:
StatementTextGenerator
All Known Implementing Classes:
AbstractSqlExpression

public interface SqlExpression
extends StatementTextGenerator

An expression within an SQL query statement. Most often used to construct the contents of a statement's WHERE and ORDER BY clauses.

Larger expressions can be built up through combinations of operations performed on smaller expressions. The available operations are modeled after those that are supported in a JDO query filter string, i.e. Java-like operators.

Author:
Mike Martin

Method Summary
 SqlExpression accessField(java.lang.String fieldName)
          Returns a new expression representing "this.fieldName".
 SqlExpression add(SqlExpression expr)
          Returns a new expression representing "this + expr".
 BooleanExpression and(SqlExpression expr)
          Returns a new expression representing "this && expr".
 SqlExpression callMethod(java.lang.String methodName, java.util.List arguments)
          Returns a new expression representing "this.methodName(arguments)".
 SqlExpression cast(java.lang.Class type)
          Returns a new expression representing this expression cast to the given data type.
 SqlExpression com()
          Returns a new expression representing "~this".
 SqlExpression div(SqlExpression expr)
          Returns a new expression representing "this / expr".
 BooleanExpression eor(SqlExpression expr)
          Returns a new expression representing "this ^ expr".
 BooleanExpression eq(SqlExpression expr)
          Returns a new expression representing "this == expr".
 ColumnMapping getColumnMapping()
          Returns the preferred mapping for this expression if it is a column mapping.
 java.lang.Class getJavaType()
          Returns the corresponding Java type of this expression.
 Mapping getMapping()
          Returns the preferred mapping for mapping this expression to/from Java objects.
 QueryStatement getQueryStatement()
          Returns the query statement to which this expression belongs.
 java.util.Set getReferencedColumns()
          Returns a set containing all the query columns referenced by this expression.
 BooleanExpression gt(SqlExpression expr)
          Returns a new expression representing "this > expr".
 BooleanExpression gteq(SqlExpression expr)
          Returns a new expression representing "this >= expr".
 BooleanExpression ior(SqlExpression expr)
          Returns a new expression representing "this || expr".
 BooleanExpression lt(SqlExpression expr)
          Returns a new expression representing "this < expr".
 BooleanExpression lteq(SqlExpression expr)
          Returns a new expression representing "this <= expr".
 SqlExpression mod(SqlExpression expr)
          Returns a new expression representing "this % expr".
 SqlExpression mul(SqlExpression expr)
          Returns a new expression representing "this * expr".
 SqlExpression neg()
          Returns a new expression representing "-this".
 ResultExpression newResultExpression(PersistenceManager pm)
          SELECTs this expression in the surrounding query statement and returns a corresponding result expression.
 BooleanExpression not()
          Returns a new expression representing "!this".
 BooleanExpression noteq(SqlExpression expr)
          Returns a new expression representing "this != expr".
 int select()
          Adds this expression to the list of those SELECTed in its surrounding query statement.
 SqlExpression setMapping(Mapping m)
          Sets the preferred mapping for mapping this expression to/from Java objects.
 SqlExpression sub(SqlExpression expr)
          Returns a new expression representing "this - expr".
 
Methods inherited from interface com.triactive.jdo.store.sql.expr.StatementTextGenerator
toStatementText, toString
 

Method Detail

getQueryStatement

public QueryStatement getQueryStatement()
Returns the query statement to which this expression belongs.


getJavaType

public java.lang.Class getJavaType()
Returns the corresponding Java type of this expression. This is the type that would (should) be produced if loading a result value of the expression into a Java object.


setMapping

public SqlExpression setMapping(Mapping m)
Sets the preferred mapping for mapping this expression to/from Java objects.

Returns:
this expression object

getMapping

public Mapping getMapping()
Returns the preferred mapping for mapping this expression to/from Java objects.

Returns:
the mapping for the expression

getColumnMapping

public ColumnMapping getColumnMapping()
Returns the preferred mapping for this expression if it is a column mapping. Otherwise, throws an exception.

Returns:
the column mapping for the expression
Throws:
javax.jdo.JDOUserException - if not mapped by a column mapping

select

public int select()
Adds this expression to the list of those SELECTed in its surrounding query statement.

Returns:
The resulting column index, left-to-right, of the expression result in the query statement. The first result column is index 1.

newResultExpression

public ResultExpression newResultExpression(PersistenceManager pm)
SELECTs this expression in the surrounding query statement and returns a corresponding result expression. After execution of the statement, the result expression is used to process the JDBC result set into Java objects.

Parameters:
pm - The persistence manager for the result objects.

getReferencedColumns

public java.util.Set getReferencedColumns()
Returns a set containing all the query columns referenced by this expression.

Returns:
A set of QueryStatement.QueryColumn objects.

and

public BooleanExpression and(SqlExpression expr)
Returns a new expression representing "this && expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

eor

public BooleanExpression eor(SqlExpression expr)
Returns a new expression representing "this ^ expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

ior

public BooleanExpression ior(SqlExpression expr)
Returns a new expression representing "this || expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

not

public BooleanExpression not()
Returns a new expression representing "!this".

Throws:
IllegalOperationException - If the operation is not valid on this type of expression.

eq

public BooleanExpression eq(SqlExpression expr)
Returns a new expression representing "this == expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

noteq

public BooleanExpression noteq(SqlExpression expr)
Returns a new expression representing "this != expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

lt

public BooleanExpression lt(SqlExpression expr)
Returns a new expression representing "this < expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

lteq

public BooleanExpression lteq(SqlExpression expr)
Returns a new expression representing "this <= expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

gt

public BooleanExpression gt(SqlExpression expr)
Returns a new expression representing "this > expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

gteq

public BooleanExpression gteq(SqlExpression expr)
Returns a new expression representing "this >= expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

add

public SqlExpression add(SqlExpression expr)
Returns a new expression representing "this + expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

sub

public SqlExpression sub(SqlExpression expr)
Returns a new expression representing "this - expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

mul

public SqlExpression mul(SqlExpression expr)
Returns a new expression representing "this * expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

div

public SqlExpression div(SqlExpression expr)
Returns a new expression representing "this / expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

mod

public SqlExpression mod(SqlExpression expr)
Returns a new expression representing "this % expr".

Parameters:
expr - The right-hand side of the operator.
Throws:
IllegalOperationException - If the operation is not valid between the two expressions based on their type.

neg

public SqlExpression neg()
Returns a new expression representing "-this".

Throws:
IllegalOperationException - If the operation is not valid on this type of expression.

com

public SqlExpression com()
Returns a new expression representing "~this".

Throws:
IllegalOperationException - If the operation is not valid on this type of expression.

cast

public SqlExpression cast(java.lang.Class type)
Returns a new expression representing this expression cast to the given data type.

Parameters:
type - The Java type to which the expression should be cast.
Throws:
IllegalOperationException - If the operation is not valid on this type of expression.

accessField

public SqlExpression accessField(java.lang.String fieldName)
Returns a new expression representing "this.fieldName".

Parameters:
fieldName - The name of the field to be accessed.
Throws:
IllegalOperationException - If the operation is not valid on this type of expression.

callMethod

public SqlExpression callMethod(java.lang.String methodName,
                                java.util.List arguments)
Returns a new expression representing "this.methodName(arguments)". Methods in this context mean JDO query methods, i.e. those methods that can be coded within a JDO query filter.

JDO query methods are implemented via a reflective call to Java methods on the SqlExpression object. Any Java method named as "abcMethod" can be called from a query filter as "abc". The Java method is passed zero or more SqlExpression objects as arguments.

For example, a query method call such as "str.substring(0, 4)" will look to reflectively invoke a Java method on this object having the signature substringMethod(SqlExpression,SqlExpression).

Parameters:
methodName - The name of the method to be invoked.
arguments - A list of SqlExpression objects representing the arguments to the method.
Throws:
MethodInvocationException - If an exception occurs in invoking the method.


Copyright 2001-2007 The TJDO Project All Rights Reserved.