org.apache.openjpa.kernel.exps
Class InMemoryExpressionFactory

java.lang.Object
  extended by org.apache.openjpa.kernel.exps.InMemoryExpressionFactory
All Implemented Interfaces:
ExpressionFactory

public class InMemoryExpressionFactory
extends Object
implements ExpressionFactory

Expression factory implementation that can be used to execute queries in memory.

Author:
Abe White

Constructor Summary
InMemoryExpressionFactory()
           
 
Method Summary
 Value abs(Value val)
          Return a value representing the absolute value of the given one.
 Value add(Value val1, Value val2)
          Return a value representing the two values added together.
 Value all(Value val)
          Return an expression representing the given condition.
 Expression and(Expression exp1, Expression exp2)
          Return the two expressions AND'd together.
 Value any(Value val)
          Return an expression representing the given condition.
 Expression asExpression(Value v)
          Return the given value as an expression.
 Value avg(Value val)
          Return the average of the given value for all matches.
 Expression bindKeyVariable(Value var, Value val)
          Bind the given variable to the key set of the given map value.
 Expression bindValueVariable(Value var, Value val)
          Bind the given variable to the value set of the given map value.
 Expression bindVariable(Value var, Value val)
          Bind the given variable to the given collection value.
 Value cast(Value val, Class cls)
          Cast the value to the given class.
 Value concat(Value val1, Value val2)
          Return a value representing the concatenation of the given target with the given args.
 Expression contains(Value v1, Value v2)
          Return an expression representing the given condition.
 Expression containsKey(Value v1, Value v2)
          Return an expression representing the given condition.
 Expression containsValue(Value v1, Value v2)
          Return an expression representing the given condition.
 Value count(Value val)
          Return the count of the given value for all matches.
 List distinct(QueryExpressions exps, boolean fromExtent, List matches)
          Filter the given list of matches, removing duplicate entries.
 Value distinct(Value val)
          Return distinct values of the given value.
 Value divide(Value val1, Value val2)
          Return a value representing the first value divided by the first one.
 Expression emptyExpression()
          Return a blank expression; this is used when the filter is empty.
 Expression endsWith(Value v1, Value v2)
          Return whether the first string ends with the second.
 Expression equal(Value v1, Value v2)
          Return an expression representing the given condition.
 Value getCurrentDate()
          Return a value representing the current date.
 Value getCurrentTime()
          Return a value representing the current time.
 Value getCurrentTimestamp()
          Return a value representing the current timestamp.
 Value getMapValue(Value map, Value arg)
          Return an expression representing the given condition.
 Value getNull()
          Return a value representing null.
 Value getObjectId(Value val)
          Return the object id of the given value.
 Value getThis()
          Return a value representing this.
 Expression greaterThan(Value v1, Value v2)
          Return an expression representing the given condition.
 Expression greaterThanEqual(Value v1, Value v2)
          Return an expression representing the given condition.
 List group(QueryExpressions exps, List matches, StoreContext ctx, Object[] params)
          Group the list of matches into a list of lists.
 Value indexOf(Value val1, Value val2)
          Return a value representing the String.indexOf(int) function on the given target with the given args.
 Expression isEmpty(Value v1)
          Return an expression representing the given condition.
 Expression isInstance(Value v1, Class c)
          Return whether the first value is an instance of the given class.
 Expression isNotEmpty(Value v1)
          Return an expression representing the given condition.
 Expression lessThan(Value v1, Value v2)
          Return an expression representing the given condition.
 Expression lessThanEqual(Value v1, Value v2)
          Return an expression representing the given condition.
 boolean matches(QueryExpressions exps, ClassMetaData type, boolean subs, Object candidate, StoreContext ctx, Object[] params)
          Tests whether the given candidate matches the given type and this expression.
 boolean matches(QueryExpressions exps, Collection group, StoreContext ctx, Object[] params)
          Return true if the given group matches the having expression.
 Expression matches(Value v1, Value v2, String single, String multi, String esc)
          Return whether the string matches the matching pattern.
 Value max(Value val)
          Return the max of the given value for all matches.
 Value min(Value val)
          Return the max of the given value for all matches.
 Value mod(Value val1, Value val2)
          Return a value representing the first value mod'd by the second one.
 Value multiply(Value val1, Value val2)
          Return a value representing the two values multiplied together.
 Value newAggregate(AggregateListener listener, Value arg)
          Return the value of the given function.
 Arguments newArgumentList(Value val1, Value val2)
          Return a function argument list consisting of the given values, either of which may itself be an argument list.
 Value newBoundVariable(String name, Class type)
          This method will be called only once per variable bound in a contains clause, and the returned value will be reused for any further instances of the variable in subexpression of the filter string.
 Value newExtension(FilterListener listener, Value target, Value arg)
          Return the value of the given extension.
 Literal newLiteral(Object val, int parseType)
          Return a value representing the given constant, which will be a Number, String, or Boolean instance.
 Parameter newParameter(String name, Class type)
          Return a value representing a parameter for the given value.
 Path newPath()
          Return a value representing a path which will consist of a chain of 1 or more field names starting in the namespace of the candidate class.
Example: parent.address.city
 Path newPath(Value val)
          Return a value representing a path which will consist of a chain of 1 or more field names starting in the namespace of the given value.
Example: var.address.city
 Subquery newSubquery(ClassMetaData candidate, boolean subs, String alias)
          Return a subquery.
 Value newUnboundVariable(String name, Class type)
          Return an unbound variable.
 Expression not(Expression exp)
          Return the inverse of this expression.
 Expression notEqual(Value v1, Value v2)
          Return an expression representing the given condition.
 Expression notMatches(Value v1, Value v2, String single, String multi, String esc)
          Return whether the string does not match the given pattern.
 Expression or(Expression exp1, Expression exp2)
          Return the two expressions OR'd together.
 List order(QueryExpressions exps, List matches, StoreContext ctx, Object[] params)
          Order the given list of matches on the given value.
 List project(QueryExpressions exps, List matches, StoreContext ctx, Object[] params)
          Create the projections for the given results.
 Value size(Value val)
          Return an expression representing the given condition.
 Value sqrt(Value val)
          Return the square root of the given value.
 Expression startsWith(Value v1, Value v2)
          Return whether the first string starts with the second.
 Value stringLength(Value str)
          Returns the number of characters in the String value.
 Value substring(Value val1, Value val2)
          Return a value representing the String.substring(int) function on the given target with the given args.
 Value subtract(Value val1, Value val2)
          Return a value representing the second value subtracted from the first.
 Value sum(Value val)
          Return the max of the given value for all matches.
 Value toLowerCase(Value val)
          Return the upper case of the given value.
 Value toUpperCase(Value val)
          Return the upper case of the given value.
 Value trim(Value str, Value trimChar, Boolean where)
          Trims the specified specified trimChar from the specified value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InMemoryExpressionFactory

public InMemoryExpressionFactory()
Method Detail

matches

public boolean matches(QueryExpressions exps,
                       ClassMetaData type,
                       boolean subs,
                       Object candidate,
                       StoreContext ctx,
                       Object[] params)
Tests whether the given candidate matches the given type and this expression.


group

public List group(QueryExpressions exps,
                  List matches,
                  StoreContext ctx,
                  Object[] params)
Group the list of matches into a list of lists.


matches

public boolean matches(QueryExpressions exps,
                       Collection group,
                       StoreContext ctx,
                       Object[] params)
Return true if the given group matches the having expression.


project

public List project(QueryExpressions exps,
                    List matches,
                    StoreContext ctx,
                    Object[] params)
Create the projections for the given results.


order

public List order(QueryExpressions exps,
                  List matches,
                  StoreContext ctx,
                  Object[] params)
Order the given list of matches on the given value.


distinct

public List distinct(QueryExpressions exps,
                     boolean fromExtent,
                     List matches)
Filter the given list of matches, removing duplicate entries.


emptyExpression

public Expression emptyExpression()
Description copied from interface: ExpressionFactory
Return a blank expression; this is used when the filter is empty.

Specified by:
emptyExpression in interface ExpressionFactory

asExpression

public Expression asExpression(Value v)
Description copied from interface: ExpressionFactory
Return the given value as an expression.

Specified by:
asExpression in interface ExpressionFactory

equal

public Expression equal(Value v1,
                        Value v2)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
equal in interface ExpressionFactory

notEqual

public Expression notEqual(Value v1,
                           Value v2)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
notEqual in interface ExpressionFactory

lessThan

public Expression lessThan(Value v1,
                           Value v2)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
lessThan in interface ExpressionFactory

greaterThan

public Expression greaterThan(Value v1,
                              Value v2)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
greaterThan in interface ExpressionFactory

lessThanEqual

public Expression lessThanEqual(Value v1,
                                Value v2)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
lessThanEqual in interface ExpressionFactory

greaterThanEqual

public Expression greaterThanEqual(Value v1,
                                   Value v2)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
greaterThanEqual in interface ExpressionFactory

isEmpty

public Expression isEmpty(Value v1)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
isEmpty in interface ExpressionFactory

isNotEmpty

public Expression isNotEmpty(Value v1)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
isNotEmpty in interface ExpressionFactory

contains

public Expression contains(Value v1,
                           Value v2)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
contains in interface ExpressionFactory

containsKey

public Expression containsKey(Value v1,
                              Value v2)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
containsKey in interface ExpressionFactory

containsValue

public Expression containsValue(Value v1,
                                Value v2)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
containsValue in interface ExpressionFactory

getMapValue

public Value getMapValue(Value map,
                         Value arg)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
getMapValue in interface ExpressionFactory

isInstance

public Expression isInstance(Value v1,
                             Class c)
Description copied from interface: ExpressionFactory
Return whether the first value is an instance of the given class.

Specified by:
isInstance in interface ExpressionFactory

and

public Expression and(Expression exp1,
                      Expression exp2)
Description copied from interface: ExpressionFactory
Return the two expressions AND'd together.

Specified by:
and in interface ExpressionFactory

or

public Expression or(Expression exp1,
                     Expression exp2)
Description copied from interface: ExpressionFactory
Return the two expressions OR'd together.

Specified by:
or in interface ExpressionFactory

not

public Expression not(Expression exp)
Description copied from interface: ExpressionFactory
Return the inverse of this expression.

Specified by:
not in interface ExpressionFactory

bindVariable

public Expression bindVariable(Value var,
                               Value val)
Description copied from interface: ExpressionFactory
Bind the given variable to the given collection value.

Specified by:
bindVariable in interface ExpressionFactory

bindKeyVariable

public Expression bindKeyVariable(Value var,
                                  Value val)
Description copied from interface: ExpressionFactory
Bind the given variable to the key set of the given map value.

Specified by:
bindKeyVariable in interface ExpressionFactory

bindValueVariable

public Expression bindValueVariable(Value var,
                                    Value val)
Description copied from interface: ExpressionFactory
Bind the given variable to the value set of the given map value.

Specified by:
bindValueVariable in interface ExpressionFactory

endsWith

public Expression endsWith(Value v1,
                           Value v2)
Description copied from interface: ExpressionFactory
Return whether the first string ends with the second.

Specified by:
endsWith in interface ExpressionFactory

matches

public Expression matches(Value v1,
                          Value v2,
                          String single,
                          String multi,
                          String esc)
Description copied from interface: ExpressionFactory
Return whether the string matches the matching pattern.

Specified by:
matches in interface ExpressionFactory
Parameters:
v1 - the value to compare
v2 - the pattern against which to compare
single - the token that signifies a single-character match
multi - the token that signifies a multi-character match
esc - the escape token that escapes the matching tokens

notMatches

public Expression notMatches(Value v1,
                             Value v2,
                             String single,
                             String multi,
                             String esc)
Description copied from interface: ExpressionFactory
Return whether the string does not match the given pattern.

Specified by:
notMatches in interface ExpressionFactory
Parameters:
v1 - the value to compare
v2 - the pattern against which to compare
single - the token that signifies a single-character match
multi - the token that signifies a multi-character match
esc - the escape token that escapes the matching tokens

startsWith

public Expression startsWith(Value v1,
                             Value v2)
Description copied from interface: ExpressionFactory
Return whether the first string starts with the second.

Specified by:
startsWith in interface ExpressionFactory

newSubquery

public Subquery newSubquery(ClassMetaData candidate,
                            boolean subs,
                            String alias)
Description copied from interface: ExpressionFactory
Return a subquery. Paths for the candidates of the subquery are created with ExpressionFactory.newPath(Value), passing in the subquery as the value.

Specified by:
newSubquery in interface ExpressionFactory
Parameters:
candidate - the candidate class of the subquery
subs - whether the query includes subclasses
alias - the alias given to the query candidate class

newPath

public Path newPath()
Description copied from interface: ExpressionFactory
Return a value representing a path which will consist of a chain of 1 or more field names starting in the namespace of the candidate class.
Example: parent.address.city

Specified by:
newPath in interface ExpressionFactory

newPath

public Path newPath(Value val)
Description copied from interface: ExpressionFactory
Return a value representing a path which will consist of a chain of 1 or more field names starting in the namespace of the given value.
Example: var.address.city

Specified by:
newPath in interface ExpressionFactory

newLiteral

public Literal newLiteral(Object val,
                          int parseType)
Description copied from interface: ExpressionFactory
Return a value representing the given constant, which will be a Number, String, or Boolean instance.

Specified by:
newLiteral in interface ExpressionFactory

getThis

public Value getThis()
Description copied from interface: ExpressionFactory
Return a value representing this.

Specified by:
getThis in interface ExpressionFactory

getNull

public Value getNull()
Description copied from interface: ExpressionFactory
Return a value representing null.

Specified by:
getNull in interface ExpressionFactory

getCurrentDate

public Value getCurrentDate()
Description copied from interface: ExpressionFactory
Return a value representing the current date.

Specified by:
getCurrentDate in interface ExpressionFactory

getCurrentTime

public Value getCurrentTime()
Description copied from interface: ExpressionFactory
Return a value representing the current time.

Specified by:
getCurrentTime in interface ExpressionFactory

getCurrentTimestamp

public Value getCurrentTimestamp()
Description copied from interface: ExpressionFactory
Return a value representing the current timestamp.

Specified by:
getCurrentTimestamp in interface ExpressionFactory

newParameter

public Parameter newParameter(String name,
                              Class type)
Description copied from interface: ExpressionFactory
Return a value representing a parameter for the given value. The type may be Object if the parameter is not declared.

Specified by:
newParameter in interface ExpressionFactory

newExtension

public Value newExtension(FilterListener listener,
                          Value target,
                          Value arg)
Description copied from interface: ExpressionFactory
Return the value of the given extension.

Specified by:
newExtension in interface ExpressionFactory

newAggregate

public Value newAggregate(AggregateListener listener,
                          Value arg)
Description copied from interface: ExpressionFactory
Return the value of the given function.

Specified by:
newAggregate in interface ExpressionFactory

newArgumentList

public Arguments newArgumentList(Value val1,
                                 Value val2)
Description copied from interface: ExpressionFactory
Return a function argument list consisting of the given values, either of which may itself be an argument list.

Specified by:
newArgumentList in interface ExpressionFactory

newUnboundVariable

public Value newUnboundVariable(String name,
                                Class type)
Description copied from interface: ExpressionFactory
Return an unbound variable. This method will only be called once for a given named unbound variable. The type may be Object if the variable is not declared.

Specified by:
newUnboundVariable in interface ExpressionFactory

newBoundVariable

public Value newBoundVariable(String name,
                              Class type)
Description copied from interface: ExpressionFactory
This method will be called only once per variable bound in a contains clause, and the returned value will be reused for any further instances of the variable in subexpression of the filter string. The type may be Object if the variable is not declared.

Specified by:
newBoundVariable in interface ExpressionFactory

cast

public Value cast(Value val,
                  Class cls)
Description copied from interface: ExpressionFactory
Cast the value to the given class.

Specified by:
cast in interface ExpressionFactory

add

public Value add(Value val1,
                 Value val2)
Description copied from interface: ExpressionFactory
Return a value representing the two values added together.

Specified by:
add in interface ExpressionFactory

subtract

public Value subtract(Value val1,
                      Value val2)
Description copied from interface: ExpressionFactory
Return a value representing the second value subtracted from the first.

Specified by:
subtract in interface ExpressionFactory

multiply

public Value multiply(Value val1,
                      Value val2)
Description copied from interface: ExpressionFactory
Return a value representing the two values multiplied together.

Specified by:
multiply in interface ExpressionFactory

divide

public Value divide(Value val1,
                    Value val2)
Description copied from interface: ExpressionFactory
Return a value representing the first value divided by the first one.

Specified by:
divide in interface ExpressionFactory

mod

public Value mod(Value val1,
                 Value val2)
Description copied from interface: ExpressionFactory
Return a value representing the first value mod'd by the second one.

Specified by:
mod in interface ExpressionFactory

abs

public Value abs(Value val)
Description copied from interface: ExpressionFactory
Return a value representing the absolute value of the given one.

Specified by:
abs in interface ExpressionFactory

indexOf

public Value indexOf(Value val1,
                     Value val2)
Description copied from interface: ExpressionFactory
Return a value representing the String.indexOf(int) function on the given target with the given args.

Specified by:
indexOf in interface ExpressionFactory

concat

public Value concat(Value val1,
                    Value val2)
Description copied from interface: ExpressionFactory
Return a value representing the concatenation of the given target with the given args.

Specified by:
concat in interface ExpressionFactory

stringLength

public Value stringLength(Value str)
Description copied from interface: ExpressionFactory
Returns the number of characters in the String value.

Specified by:
stringLength in interface ExpressionFactory

trim

public Value trim(Value str,
                  Value trimChar,
                  Boolean where)
Description copied from interface: ExpressionFactory
Trims the specified specified trimChar from the specified value.

Specified by:
trim in interface ExpressionFactory
Parameters:
str - the value from which to trim
trimChar - the characters to trim off
where - which side of the String to trim: null indicates both sides, true indicates leading, and false indicates trailing

sqrt

public Value sqrt(Value val)
Description copied from interface: ExpressionFactory
Return the square root of the given value.

Specified by:
sqrt in interface ExpressionFactory

substring

public Value substring(Value val1,
                       Value val2)
Description copied from interface: ExpressionFactory
Return a value representing the String.substring(int) function on the given target with the given args.

Specified by:
substring in interface ExpressionFactory

toUpperCase

public Value toUpperCase(Value val)
Description copied from interface: ExpressionFactory
Return the upper case of the given value.

Specified by:
toUpperCase in interface ExpressionFactory

toLowerCase

public Value toLowerCase(Value val)
Description copied from interface: ExpressionFactory
Return the upper case of the given value.

Specified by:
toLowerCase in interface ExpressionFactory

avg

public Value avg(Value val)
Description copied from interface: ExpressionFactory
Return the average of the given value for all matches.

Specified by:
avg in interface ExpressionFactory

count

public Value count(Value val)
Description copied from interface: ExpressionFactory
Return the count of the given value for all matches.

Specified by:
count in interface ExpressionFactory

distinct

public Value distinct(Value val)
Description copied from interface: ExpressionFactory
Return distinct values of the given value. This is typically used within aggregates, for example: max(distinct(path))

Specified by:
distinct in interface ExpressionFactory

max

public Value max(Value val)
Description copied from interface: ExpressionFactory
Return the max of the given value for all matches.

Specified by:
max in interface ExpressionFactory

min

public Value min(Value val)
Description copied from interface: ExpressionFactory
Return the max of the given value for all matches.

Specified by:
min in interface ExpressionFactory

sum

public Value sum(Value val)
Description copied from interface: ExpressionFactory
Return the max of the given value for all matches.

Specified by:
sum in interface ExpressionFactory

any

public Value any(Value val)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
any in interface ExpressionFactory

all

public Value all(Value val)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
all in interface ExpressionFactory

size

public Value size(Value val)
Description copied from interface: ExpressionFactory
Return an expression representing the given condition.

Specified by:
size in interface ExpressionFactory

getObjectId

public Value getObjectId(Value val)
Description copied from interface: ExpressionFactory
Return the object id of the given value.

Specified by:
getObjectId in interface ExpressionFactory


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.