Package org.apache.openjpa.kernel.exps
Class AbstractExpressionBuilder
- java.lang.Object
-
- org.apache.openjpa.kernel.exps.AbstractExpressionBuilder
-
- Direct Known Subclasses:
JPQLExpressionBuilder
public abstract class AbstractExpressionBuilder extends java.lang.ObjectAbstract 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
Fields Modifier and Type Field Description static intCONTAINS_TYPE_ELEMENTstatic intCONTAINS_TYPE_KEYstatic intCONTAINS_TYPE_VALUEprotected static intEX_FATALprotected static intEX_UNSUPPORTEDprotected static intEX_USERprotected ExpressionFactoryfactoryprotected Resolverresolverstatic java.lang.Class<java.lang.Character>TYPE_CHAR_OBJstatic java.lang.Class<java.util.Collection>TYPE_COLLECTIONstatic java.lang.Class<java.util.Map>TYPE_MAPstatic java.lang.Class<java.lang.Number>TYPE_NUMBERstatic java.lang.Class<java.lang.Object>TYPE_OBJECTstatic java.lang.Class<java.lang.String>TYPE_STRING
-
Constructor Summary
Constructors Constructor Description AbstractExpressionBuilder(ExpressionFactory factory, Resolver resolver)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected ClassMetaDataaddAccessPath(ClassMetaData meta)Register the specified metadata as being in the query's access path.protected abstract voidaddSchemaToContext(java.lang.String alias, ClassMetaData meta)Register the schema alias to the current JPQL query context.protected abstract voidaddVariableToContext(java.lang.String id, Value var)Register the variable associated with the schema alias (id) to the current JPQL query context.protected voidassertUnboundVariablesValid()Validate that all unbound variables are of a PC type.protected voidbind(Value var)Record that the given variable is bound.static voidconvertTypes(Value val1, Value val2)Perform conversions to make values compatible.static voidconvertTypesQuotedNumbers(Value val1, Value val2)Perform conversions to make values compatible.protected ValuecreateVariable(java.lang.String id, boolean bind)protected abstract java.lang.StringcurrentQuery()Returns the current string being parsed; used for error messages.protected ClassMetaData[]getAccessPath()Return the recorded query access path.protected abstract java.lang.ClassLoadergetClassLoader()Returns the class loader that should be used for resolving class names (in addition to the resolver in the query).protected abstract java.lang.Class<?>getDeclaredVariableType(java.lang.String name)Returns the type of the named variable if it has been declared.protected abstract LocalizergetLocalizer()Used for obtaining theLocalizerto use for translating error messages.protected ClassMetaDatagetMetaData(java.lang.Class<?> c, boolean required)Convenience method to get metadata for the given type.protected ClassMetaDatagetMetaData(java.lang.Class<?> c, boolean required, java.lang.ClassLoader loader)Convenience method to get metadata for the given type.protected abstract ValuegetVariable(java.lang.String id)Returns the variable associated with the schema alias (id).protected ValuegetVariable(java.lang.String id, boolean bind)Returns a value for the given id.protected booleanisBound(Value var)Return true if the given variable has been bound.protected abstract booleanisDeclaredVariable(java.lang.String id)Returns whether the specified variable name has been explicitly declared.static booleanisNumeric(java.lang.Class<?> type)Return true if given class can be used as a number.protected booleanisSeenVariable(java.lang.String id)Return whether the given id has been used as a variable.protected OpenJPAExceptionparseException(int e, java.lang.String token, java.lang.Object[] args, java.lang.Exception nest)Create a proper parse exception for the given reason.protected voidsetImplicitContainsTypes(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 voidsetImplicitType(Value val, java.lang.Class<?> expected)Set the implicit type of the given value to the given class.protected voidsetImplicitTypes(Value val1, Value val2, java.lang.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 voidsetImplicitTypes(Value val1, Value val2, java.lang.Class<?> expected, Resolver resolver)protected ValuetraversePath(Path path, java.lang.String field)Traverse the given field in the given path.protected ValuetraversePath(Path path, java.lang.String field, boolean pcOnly, boolean allowNull)Traverse the given field in the given path.protected java.lang.ObjecttraverseStaticField(java.lang.Class<?> cls, java.lang.String field)Return a constant containing the value of the given static field.protected ValuetraverseXPath(Path path, java.lang.String field)
-
-
-
Field Detail
-
EX_USER
protected static final int EX_USER
- See Also:
- Constant Field Values
-
EX_FATAL
protected static final int EX_FATAL
- See Also:
- Constant Field Values
-
EX_UNSUPPORTED
protected static final int EX_UNSUPPORTED
- See Also:
- Constant Field Values
-
TYPE_OBJECT
public static final java.lang.Class<java.lang.Object> TYPE_OBJECT
-
TYPE_STRING
public static final java.lang.Class<java.lang.String> TYPE_STRING
-
TYPE_CHAR_OBJ
public static final java.lang.Class<java.lang.Character> TYPE_CHAR_OBJ
-
TYPE_NUMBER
public static final java.lang.Class<java.lang.Number> TYPE_NUMBER
-
TYPE_COLLECTION
public static final java.lang.Class<java.util.Collection> TYPE_COLLECTION
-
TYPE_MAP
public static final java.lang.Class<java.util.Map> TYPE_MAP
-
CONTAINS_TYPE_ELEMENT
public static final int CONTAINS_TYPE_ELEMENT
- See Also:
- Constant Field Values
-
CONTAINS_TYPE_KEY
public static final int CONTAINS_TYPE_KEY
- See Also:
- Constant Field Values
-
CONTAINS_TYPE_VALUE
public static final int CONTAINS_TYPE_VALUE
- See Also:
- Constant Field Values
-
resolver
protected final Resolver resolver
-
factory
protected ExpressionFactory factory
-
-
Constructor Detail
-
AbstractExpressionBuilder
public AbstractExpressionBuilder(ExpressionFactory factory, Resolver resolver)
Constructor.- Parameters:
factory- the expression factory to useresolver- used to resolve variables, parameters, and class names used in the query
-
-
Method Detail
-
getClassLoader
protected abstract java.lang.ClassLoader getClassLoader()
Returns the class loader that should be used for resolving class names (in addition to the resolver in the query).
-
parseException
protected OpenJPAException parseException(int e, java.lang.String token, java.lang.Object[] args, java.lang.Exception nest)
Create a proper parse exception for the given reason.
-
addAccessPath
protected ClassMetaData addAccessPath(ClassMetaData meta)
Register the specified metadata as being in the query's access path.
-
getAccessPath
protected ClassMetaData[] getAccessPath()
Return the recorded query access path.
-
isBound
protected boolean isBound(Value var)
Return true if the given variable has been bound.
-
bind
protected void bind(Value var)
Record that the given variable is bound.
-
getVariable
protected Value getVariable(java.lang.String id, boolean bind)
Returns a value for the given id.
-
createVariable
protected Value createVariable(java.lang.String id, boolean bind)
-
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
protected abstract boolean isDeclaredVariable(java.lang.String id)
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
protected boolean isSeenVariable(java.lang.String id)
Return whether the given id has been used as a variable.
-
getMetaData
protected ClassMetaData getMetaData(java.lang.Class<?> c, boolean required)
Convenience method to get metadata for the given type.
-
getMetaData
protected ClassMetaData getMetaData(java.lang.Class<?> c, boolean required, java.lang.ClassLoader loader)
Convenience method to get metadata for the given type.
-
traversePath
protected Value traversePath(Path path, java.lang.String field)
Traverse the given field in the given path.
-
traversePath
protected Value traversePath(Path path, java.lang.String field, boolean pcOnly, boolean allowNull)
Traverse the given field in the given path.
-
traverseStaticField
protected java.lang.Object traverseStaticField(java.lang.Class<?> cls, java.lang.String field)Return a constant containing the value of the given static field.
-
getDeclaredVariableType
protected abstract java.lang.Class<?> getDeclaredVariableType(java.lang.String name)
Returns the type of the named variable if it has been declared.
-
setImplicitTypes
protected void setImplicitTypes(Value val1, Value val2, java.lang.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.
-
setImplicitTypes
protected static void setImplicitTypes(Value val1, Value val2, java.lang.Class<?> expected, Resolver resolver)
-
convertTypes
public static void convertTypes(Value val1, Value val2)
Perform conversions to make values compatible.
-
convertTypesQuotedNumbers
public static void convertTypesQuotedNumbers(Value val1, Value val2)
Perform conversions to make values compatible.
-
isNumeric
public static boolean isNumeric(java.lang.Class<?> type)
Return true if given class can be used as a number.
-
setImplicitContainsTypes
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.
-
setImplicitType
protected static void setImplicitType(Value val, java.lang.Class<?> expected)
Set the implicit type of the given value to the given class.
-
getLocalizer
protected abstract Localizer getLocalizer()
Used for obtaining theLocalizerto use for translating error messages.
-
currentQuery
protected abstract java.lang.String currentQuery()
Returns the current string being parsed; used for error messages.
-
addSchemaToContext
protected abstract void addSchemaToContext(java.lang.String alias, ClassMetaData meta)Register the schema alias to the current JPQL query context.
-
addVariableToContext
protected abstract void addVariableToContext(java.lang.String id, Value var)Register the variable associated with the schema alias (id) to the current JPQL query context.
-
getVariable
protected abstract Value getVariable(java.lang.String id)
Returns the variable associated with the schema alias (id).
-
-