Package org.apache.openjpa.kernel.exps
Class AbstractExpressionBuilder
java.lang.Object
org.apache.openjpa.kernel.exps.AbstractExpressionBuilder
- Direct Known Subclasses:
JPQLExpressionBuilder
Abstract base class to help build expressions. Provides
generic language-independent support for variable resolution,
path traversal, and error messages.
- Author:
- Marc Prud'hommeaux
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
protected static final int
protected static final int
protected static final int
protected ExpressionFactory
protected final Resolver
static final Class<Collection>
-
Constructor Summary
ConstructorDescriptionAbstractExpressionBuilder
(ExpressionFactory factory, Resolver resolver) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected ClassMetaData
addAccessPath
(ClassMetaData meta) Register the specified metadata as being in the query's access path.protected abstract void
addSchemaToContext
(String alias, ClassMetaData meta) Register the schema alias to the current JPQL query context.protected abstract void
addVariableToContext
(String id, Value var) Register the variable associated with the schema alias (id) to the current JPQL query context.protected void
Validate that all unbound variables are of a PC type.protected void
Record that the given variable is bound.static void
convertTypes
(Value val1, Value val2) Perform conversions to make values compatible.static void
convertTypesQuotedNumbers
(Value val1, Value val2) Perform conversions to make values compatible.protected Value
createVariable
(String id, boolean bind) protected abstract String
Returns the current string being parsed; used for error messages.protected ClassMetaData[]
Return the recorded query access path.protected abstract ClassLoader
Returns the class loader that should be used for resolving class names (in addition to the resolver in the query).protected abstract Class<?>
Returns the type of the named variable if it has been declared.protected abstract Localizer
Used for obtaining theLocalizer
to use for translating error messages.protected ClassMetaData
getMetaData
(Class<?> c, boolean required) Convenience method to get metadata for the given type.protected ClassMetaData
getMetaData
(Class<?> c, boolean required, ClassLoader loader) Convenience method to get metadata for the given type.protected abstract Value
getVariable
(String id) Returns the variable associated with the schema alias (id).protected Value
getVariable
(String id, boolean bind) Returns a value for the given id.protected boolean
Return true if the given variable has been bound.protected abstract boolean
Returns whether the specified variable name has been explicitly declared.static boolean
Return true if given class can be used as a number.protected boolean
isSeenVariable
(String id) Return whether the given id has been used as a variable.protected OpenJPAException
parseException
(int e, String token, Object[] args, Exception nest) Create a proper parse exception for the given reason.protected void
setImplicitContainsTypes
(Value val1, Value val2, int op) Set the implicit types of the given values based on the fact that the first is supposed to contain the second.protected static void
setImplicitType
(Value val, Class<?> expected) Set the implicit type of the given value to the given class.protected void
setImplicitTypes
(Value val1, Value val2, Class<?> expected) Set the implicit types of the given values based on the fact that they're used together, and based on the operator type.protected static void
setImplicitTypes
(Value val1, Value val2, Class<?> expected, Resolver resolver) protected Value
traversePath
(Path path, String field) Traverse the given field in the given path.protected Value
traversePath
(Path path, String field, boolean pcOnly, boolean allowNull) Traverse the given field in the given path.protected Object
traverseStaticField
(Class<?> cls, String field) Return a constant containing the value of the given static field.protected Value
traverseXPath
(Path path, String field)
-
Field Details
-
EX_USER
protected static final int EX_USER- See Also:
-
EX_FATAL
protected static final int EX_FATAL- See Also:
-
EX_UNSUPPORTED
protected static final int EX_UNSUPPORTED- See Also:
-
TYPE_OBJECT
-
TYPE_STRING
-
TYPE_CHAR_OBJ
-
TYPE_NUMBER
-
TYPE_COLLECTION
-
TYPE_MAP
-
CONTAINS_TYPE_ELEMENT
public static final int CONTAINS_TYPE_ELEMENT- See Also:
-
CONTAINS_TYPE_KEY
public static final int CONTAINS_TYPE_KEY- See Also:
-
CONTAINS_TYPE_VALUE
public static final int CONTAINS_TYPE_VALUE- See Also:
-
resolver
-
factory
-
-
Constructor Details
-
AbstractExpressionBuilder
Constructor.- Parameters:
factory
- the expression factory to useresolver
- used to resolve variables, parameters, and class names used in the query
-
-
Method Details
-
getClassLoader
Returns the class loader that should be used for resolving class names (in addition to the resolver in the query). -
parseException
Create a proper parse exception for the given reason. -
addAccessPath
Register the specified metadata as being in the query's access path. -
getAccessPath
Return the recorded query access path. -
isBound
Return true if the given variable has been bound. -
bind
Record that the given variable is bound. -
getVariable
Returns a value for the given id. -
createVariable
-
assertUnboundVariablesValid
protected void assertUnboundVariablesValid()Validate that all unbound variables are of a PC type. If not, assume that the user actually made a typo that we took for an implicit unbound variable. -
isDeclaredVariable
Returns whether the specified variable name has been explicitly declared. Note all query languages necessarily support declaring variables.- Parameters:
id
- the variable to check- Returns:
- true if the variabe has been explicitely declared
-
isSeenVariable
Return whether the given id has been used as a variable. -
getMetaData
Convenience method to get metadata for the given type. -
getMetaData
Convenience method to get metadata for the given type. -
traversePath
Traverse the given field in the given path. -
traverseXPath
-
traversePath
Traverse the given field in the given path. -
traverseStaticField
Return a constant containing the value of the given static field. -
getDeclaredVariableType
Returns the type of the named variable if it has been declared. -
setImplicitTypes
Set the implicit types of the given values based on the fact that they're used together, and based on the operator type. -
setImplicitTypes
-
convertTypes
Perform conversions to make values compatible. -
convertTypesQuotedNumbers
Perform conversions to make values compatible. -
isNumeric
Return true if given class can be used as a number. -
setImplicitContainsTypes
Set the implicit types of the given values based on the fact that the first is supposed to contain the second. -
setImplicitType
Set the implicit type of the given value to the given class. -
getLocalizer
Used for obtaining theLocalizer
to use for translating error messages. -
currentQuery
Returns the current string being parsed; used for error messages. -
addSchemaToContext
Register the schema alias to the current JPQL query context. -
addVariableToContext
Register the variable associated with the schema alias (id) to the current JPQL query context. -
getVariable
Returns the variable associated with the schema alias (id).
-