com.triactive.jdo.store.sql.expr
Class AbstractSqlExpression

java.lang.Object
  extended bycom.triactive.jdo.store.sql.expr.AbstractSqlExpression
All Implemented Interfaces:
SqlExpression, StatementTextGenerator
Direct Known Subclasses:
BinaryExpression, BooleanExpression, CharacterExpression, MapExpression, NullLiteral, NumericExpression, ObjectExpression, OIDExpression, SetExpression, SqlDateExpression, SqlTimestampExpression, StarLiteral, StringExpression, TypeNameLiteral, UnboundVariable

public abstract class AbstractSqlExpression
extends java.lang.Object
implements SqlExpression


Nested Class Summary
static interface AbstractSqlExpression.Body
          The "body" of an SQL expression.
static interface AbstractSqlExpression.CompoundExpression
          The "body" of an SQL expression made up of one or more component SQL expressions.
static interface AbstractSqlExpression.SimpleColumnReference
          The "body" of an SQL expression which references no more than one column.
static interface AbstractSqlExpression.SubqueryExpression
          The "body" of an SQL expression made up of a subquery.
 
Field Summary
protected  AbstractSqlExpression.Body body
           
protected  QueryStatement qs
           
 
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".
static QueryStatement innermostQuery(java.util.Collection c)
          Returns the innermost query among all the given SqlExpression.
static QueryStatement innermostQuery(SqlExpression expr1, SqlExpression expr2)
          Returns the innermost query between a pair of SqlExpressions.
 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".
static AbstractSqlExpression.Body newBody(MonadicOperator op, SqlExpression operand)
          Constructs an expression body consisting of a single SQL operator applied to an expression.
static AbstractSqlExpression.Body newBody(QueryStatement.QueryColumn qsc)
          Constructs an expression body consisting of a single column reference.
static AbstractSqlExpression.Body newBody(QueryStatement qs, java.lang.Class javaType)
          Constructs an empty expression body.
static AbstractSqlExpression.Body newBody(SqlExpression subexpr)
          Constructs an expression body consisting of a single embedded subexpression.
static AbstractSqlExpression.Body newBody(SqlExpression operand1, DyadicOperator op, SqlExpression operand2)
          Constructs an expression body consisting of a SQL operator applied to a pair of expressions.
static AbstractSqlExpression.Body newBody(SqlFunction function, java.util.List args)
          Constructs an expression body consisting of an SQL function call.
 ResultExpression newResultExpression(PersistenceManager pm)
          SELECTs this expression in the surrounding query statement and returns a corresponding result expression.
static AbstractSqlExpression.Body newSubqueryBody(QueryStatement subquery, java.lang.Class javaType)
          Constructs an expression body consisting of a parenthesized subquery.
 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 mapping)
          Sets the preferred mapping for mapping this expression to/from Java objects.
 SqlExpression sub(SqlExpression expr)
          Returns a new expression representing "this - expr".
 StatementText toStatementText()
          Returns the SQL statement text which this object generates.
 java.lang.String toString()
          Returns the SQL statement text which this object generates as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

body

protected final AbstractSqlExpression.Body body

qs

protected final QueryStatement qs
Method Detail

getQueryStatement

public QueryStatement getQueryStatement()
Description copied from interface: SqlExpression
Returns the query statement to which this expression belongs.

Specified by:
getQueryStatement in interface SqlExpression

getJavaType

public java.lang.Class getJavaType()
Description copied from interface: SqlExpression
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.

Specified by:
getJavaType in interface SqlExpression

getMapping

public final Mapping getMapping()
Description copied from interface: SqlExpression
Returns the preferred mapping for mapping this expression to/from Java objects.

Specified by:
getMapping in interface SqlExpression
Returns:
the mapping for the expression

getColumnMapping

public final ColumnMapping getColumnMapping()
Description copied from interface: SqlExpression
Returns the preferred mapping for this expression if it is a column mapping. Otherwise, throws an exception.

Specified by:
getColumnMapping in interface SqlExpression
Returns:
the column mapping for the expression

setMapping

public SqlExpression setMapping(Mapping mapping)
Description copied from interface: SqlExpression
Sets the preferred mapping for mapping this expression to/from Java objects.

Specified by:
setMapping in interface SqlExpression
Returns:
this expression object

select

public int select()
Description copied from interface: SqlExpression
Adds this expression to the list of those SELECTed in its surrounding query statement.

Specified by:
select in interface SqlExpression
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)
Description copied from interface: SqlExpression
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.

Specified by:
newResultExpression in interface SqlExpression
Parameters:
pm - The persistence manager for the result objects.

getReferencedColumns

public java.util.Set getReferencedColumns()
Description copied from interface: SqlExpression
Returns a set containing all the query columns referenced by this expression.

Specified by:
getReferencedColumns in interface SqlExpression
Returns:
A set of QueryStatement.QueryColumn objects.

and

public BooleanExpression and(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this && expr".

Specified by:
and in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

eor

public BooleanExpression eor(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this ^ expr".

Specified by:
eor in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

ior

public BooleanExpression ior(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this || expr".

Specified by:
ior in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

not

public BooleanExpression not()
Description copied from interface: SqlExpression
Returns a new expression representing "!this".

Specified by:
not in interface SqlExpression

eq

public BooleanExpression eq(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this == expr".

Specified by:
eq in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

noteq

public BooleanExpression noteq(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this != expr".

Specified by:
noteq in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

lt

public BooleanExpression lt(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this < expr".

Specified by:
lt in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

lteq

public BooleanExpression lteq(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this <= expr".

Specified by:
lteq in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

gt

public BooleanExpression gt(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this > expr".

Specified by:
gt in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

gteq

public BooleanExpression gteq(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this >= expr".

Specified by:
gteq in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

add

public SqlExpression add(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this + expr".

Specified by:
add in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

sub

public SqlExpression sub(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this - expr".

Specified by:
sub in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

mul

public SqlExpression mul(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this * expr".

Specified by:
mul in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

div

public SqlExpression div(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this / expr".

Specified by:
div in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

mod

public SqlExpression mod(SqlExpression expr)
Description copied from interface: SqlExpression
Returns a new expression representing "this % expr".

Specified by:
mod in interface SqlExpression
Parameters:
expr - The right-hand side of the operator.

neg

public SqlExpression neg()
Description copied from interface: SqlExpression
Returns a new expression representing "-this".

Specified by:
neg in interface SqlExpression

com

public SqlExpression com()
Description copied from interface: SqlExpression
Returns a new expression representing "~this".

Specified by:
com in interface SqlExpression

cast

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

Specified by:
cast in interface SqlExpression
Parameters:
type - The Java type to which the expression should be cast.

accessField

public SqlExpression accessField(java.lang.String fieldName)
Description copied from interface: SqlExpression
Returns a new expression representing "this.fieldName".

Specified by:
accessField in interface SqlExpression
Parameters:
fieldName - The name of the field to be accessed.

callMethod

public SqlExpression callMethod(java.lang.String methodName,
                                java.util.List arguments)
Description copied from interface: SqlExpression
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).

Specified by:
callMethod in interface SqlExpression
Parameters:
methodName - The name of the method to be invoked.
arguments - A list of SqlExpression objects representing the arguments to the method.

toStatementText

public StatementText toStatementText()
Description copied from interface: StatementTextGenerator
Returns the SQL statement text which this object generates.

Specified by:
toStatementText in interface StatementTextGenerator

toString

public java.lang.String toString()
Description copied from interface: StatementTextGenerator
Returns the SQL statement text which this object generates as a string.

Specified by:
toString in interface StatementTextGenerator

newBody

public static AbstractSqlExpression.Body newBody(QueryStatement qs,
                                                 java.lang.Class javaType)
Constructs an empty expression body. Used by AbstractSqlExpression subclasses which generate all their text in their own toStatementText() method.


newBody

public static AbstractSqlExpression.Body newBody(QueryStatement.QueryColumn qsc)
Constructs an expression body consisting of a single column reference.


newBody

public static AbstractSqlExpression.Body newBody(SqlExpression subexpr)
Constructs an expression body consisting of a single embedded subexpression.


newSubqueryBody

public static AbstractSqlExpression.Body newSubqueryBody(QueryStatement subquery,
                                                         java.lang.Class javaType)
Constructs an expression body consisting of a parenthesized subquery.


newBody

public static AbstractSqlExpression.Body newBody(SqlFunction function,
                                                 java.util.List args)
Constructs an expression body consisting of an SQL function call.


newBody

public static AbstractSqlExpression.Body newBody(MonadicOperator op,
                                                 SqlExpression operand)
Constructs an expression body consisting of a single SQL operator applied to an expression.


newBody

public static AbstractSqlExpression.Body newBody(SqlExpression operand1,
                                                 DyadicOperator op,
                                                 SqlExpression operand2)
Constructs an expression body consisting of a SQL operator applied to a pair of expressions.


innermostQuery

public static QueryStatement innermostQuery(SqlExpression expr1,
                                            SqlExpression expr2)
Returns the innermost query between a pair of SqlExpressions.

Parameters:
expr1 - a SQL expression
expr2 - a SQL expression

innermostQuery

public static QueryStatement innermostQuery(java.util.Collection c)
Returns the innermost query among all the given SqlExpression.

Parameters:
c - A Collection of SqlExpression objects. Cannot be empty.
Throws:
java.util.NoSuchElementException - if the collection is empty


Copyright © 2001-2007 The TJDO Project All Rights Reserved.