Package org.apache.openjpa.kernel.jpql
Class JPQLExpressionBuilder
- java.lang.Object
-
- org.apache.openjpa.kernel.exps.AbstractExpressionBuilder
-
- org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder
-
- All Implemented Interfaces:
JPQLTreeConstants
public class JPQLExpressionBuilder extends AbstractExpressionBuilder implements JPQLTreeConstants
Builder for JPQL expressions. This class takes the query parsed inJPQLand converts it to an expression tree using anExpressionFactory. Public for unit testing purposes.- Author:
- Marc Prud'hommeaux, Patrick Linskey
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classJPQLExpressionBuilder.JPQLNodeBase node that will be generated by the JPQLExpressionBuilder; base class of theSimpleNodethat is used byJPQL.static classJPQLExpressionBuilder.ParsedJPQLPublic for unit testing purposes.
-
Field Summary
-
Fields inherited from class org.apache.openjpa.kernel.exps.AbstractExpressionBuilder
CONTAINS_TYPE_ELEMENT, CONTAINS_TYPE_KEY, CONTAINS_TYPE_VALUE, EX_FATAL, EX_UNSUPPORTED, EX_USER, factory, resolver, TYPE_CHAR_OBJ, TYPE_COLLECTION, TYPE_MAP, TYPE_NUMBER, TYPE_OBJECT, TYPE_STRING
-
Fields inherited from interface org.apache.openjpa.kernel.jpql.JPQLTreeConstants
JJTABS, JJTABSTRACTSCHEMANAME, JJTADD, JJTAGGREGATE, JJTALL, JJTAND, JJTANY, JJTASCENDING, JJTAVERAGE, JJTBETWEEN, JJTBOOLEANLITERAL, JJTCASE, JJTCLASSNAME, JJTCOALESCE, JJTCOLLECTIONPARAMETER, JJTCONCAT, JJTCONSTRUCTOR, JJTCONSTRUCTORPARAM, JJTCONSTRUCTORPARAMS, JJTCOUNT, JJTCURRENTDATE, JJTCURRENTTIME, JJTCURRENTTIMESTAMP, JJTDATELITERAL, JJTDECIMALLITERAL, JJTDELETE, JJTDESCENDING, JJTDISTINCT, JJTDISTINCTPATH, JJTDIVIDE, JJTENTRY, JJTEQUALS, JJTESCAPECHARACTER, JJTEXISTS, JJTFROM, JJTFROMITEM, JJTGENERALCASE, JJTGENERALIDENTIFIER, JJTGREATEROREQUAL, JJTGREATERTHAN, JJTGROUPBY, JJTGROUPBYEXTENSION, JJTHAVING, JJTIDENTIFICATIONVARIABLE, JJTIDENTIFIER, JJTIN, JJTINDEX, JJTINNERFETCHJOIN, JJTINNERJOIN, JJTINTEGERLITERAL, JJTISEMPTY, JJTISNULL, JJTKEY, JJTLENGTH, JJTLESSOREQUAL, JJTLESSTHAN, JJTLIKE, JJTLOCATE, JJTLOWER, JJTMAX, JJTMEMBEROF, JJTMIN, JJTMOD, JJTMULTIPLY, JJTNAMEDINPUTPARAMETER, JJTNEGATIVE, jjtNodeName, JJTNOT, JJTNOTEQUALS, JJTNULLIF, JJTOR, JJTORDERBY, JJTORDERBYEXTENSION, JJTORDERBYITEM, JJTOUTERFETCHJOIN, JJTOUTERJOIN, JJTPATH, JJTPATTERNVALUE, JJTPOSITIONALINPUTPARAMETER, JJTQUALIFIEDIDENTIFIER, JJTQUALIFIEDPATH, JJTSCALAREXPRESSION, JJTSELECT, JJTSELECTCLAUSE, JJTSELECTEXPRESSION, JJTSELECTEXPRESSIONS, JJTSELECTEXTENSION, JJTSIMPLECASE, JJTSIZE, JJTSQRT, JJTSTRINGLITERAL, JJTSTRINGLITERAL2, JJTSUBSELECT, JJTSUBSTRING, JJTSUBTRACT, JJTSUM, JJTTIMELITERAL, JJTTIMESTAMPLITERAL, JJTTOK, JJTTRIM, JJTTRIMBOTH, JJTTRIMCHARACTER, JJTTRIMLEADING, JJTTRIMTRAILING, JJTTYPE, JJTTYPELITERAL, JJTUPDATE, JJTUPDATEITEM, JJTUPDATEVALUE, JJTUPPER, JJTVALUE, JJTVOID, JJTWHEN, JJTWHENSCALAR, JJTWHERE
-
-
Constructor Summary
Constructors Constructor Description JPQLExpressionBuilder(ExpressionFactory factory, ExpressionStoreQuery query, java.lang.Object parsedQuery)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddSchemaToContext(java.lang.String id, ClassMetaData meta)Register the schema alias to the current JPQL query context.protected voidaddVariableToContext(java.lang.String id, Value var)Register the variable associated with the schema alias (id) to the current JPQL query context.static voidcheckEmbeddable(Value val, java.lang.String currentQuery)static ValueconvertSubstringArguments(ExpressionFactory factory, Value val1, Value val2, Value val3)Converts JPQL substring() function to OpenJPA ExpressionFactory substring() arguments.protected java.lang.StringcurrentQuery()Returns the current string being parsed; used for error messages.protected ExpressionevalFetchJoins(QueryExpressions exps)protected voidevalSetClause(QueryExpressions exps)protected ClassMetaDatagetCandidateMetaData(JPQLExpressionBuilder.JPQLNode node)protected java.lang.ClassLoadergetClassLoader()Returns the class loader that should be used for resolving class names (in addition to the resolver in the query).protected java.lang.Class<?>getDeclaredVariableType(java.lang.String name)Returns the type of the named variable if it has been declared.protected ValuegetDefinedVariable(java.lang.String id)protected LocalizergetLocalizer()Used for obtaining theLocalizerto use for translating error messages.protected JPQLExpressionBuilder.ParsedJPQLgetParsedQuery()protected JPQLExpressionBuilder.ParsedJPQLgetParsedQuery(java.lang.String jpql)protected ValuegetVariable(java.lang.String var)Returns the variable associated with the schema alias (id).protected ValuegetVariable(java.lang.String id, boolean bind)Identification variables in JPQL are case insensitive, so lower-case all variables we are going to bind.protected booleanisDeclaredVariable(java.lang.String name)Returns whether the specified variable name has been explicitly declared.protected booleanisSeenVariable(java.lang.String var)Return whether the given id has been used as a variable.protected ClassMetaDataresolveClassMetaData(JPQLExpressionBuilder.JPQLNode node)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.static voidsetImplicitTypes(Value val1, Value val2, java.lang.Class<?> expected, Resolver resolver, OrderedMap<java.lang.Object,java.lang.Class<?>> parameterTypes, java.lang.String currentQuery)-
Methods inherited from class org.apache.openjpa.kernel.exps.AbstractExpressionBuilder
addAccessPath, assertUnboundVariablesValid, bind, convertTypes, convertTypesQuotedNumbers, createVariable, getAccessPath, getMetaData, getMetaData, isBound, isNumeric, parseException, setImplicitContainsTypes, setImplicitType, setImplicitTypes, traversePath, traversePath, traverseStaticField, traverseXPath
-
-
-
-
Constructor Detail
-
JPQLExpressionBuilder
public JPQLExpressionBuilder(ExpressionFactory factory, ExpressionStoreQuery query, java.lang.Object parsedQuery)
Constructor.- Parameters:
factory- the expression factory to usequery- used to resolve variables, parameters, and class names used in the queryparsedQuery- the parsed query
-
-
Method Detail
-
getLocalizer
protected Localizer getLocalizer()
Description copied from class:AbstractExpressionBuilderUsed for obtaining theLocalizerto use for translating error messages.- Specified by:
getLocalizerin classAbstractExpressionBuilder
-
getClassLoader
protected java.lang.ClassLoader getClassLoader()
Description copied from class:AbstractExpressionBuilderReturns the class loader that should be used for resolving class names (in addition to the resolver in the query).- Specified by:
getClassLoaderin classAbstractExpressionBuilder
-
getParsedQuery
protected JPQLExpressionBuilder.ParsedJPQL getParsedQuery()
-
getParsedQuery
protected JPQLExpressionBuilder.ParsedJPQL getParsedQuery(java.lang.String jpql)
-
resolveClassMetaData
protected ClassMetaData resolveClassMetaData(JPQLExpressionBuilder.JPQLNode node)
-
getCandidateMetaData
protected ClassMetaData getCandidateMetaData(JPQLExpressionBuilder.JPQLNode node)
-
currentQuery
protected java.lang.String currentQuery()
Description copied from class:AbstractExpressionBuilderReturns the current string being parsed; used for error messages.- Specified by:
currentQueryin classAbstractExpressionBuilder
-
evalFetchJoins
protected Expression evalFetchJoins(QueryExpressions exps)
-
evalSetClause
protected void evalSetClause(QueryExpressions exps)
-
isDeclaredVariable
protected boolean isDeclaredVariable(java.lang.String name)
Description copied from class:AbstractExpressionBuilderReturns whether the specified variable name has been explicitly declared. Note all query languages necessarily support declaring variables.- Specified by:
isDeclaredVariablein classAbstractExpressionBuilder- Parameters:
name- the variable to check- Returns:
- true if the variabe has been explicitely declared
-
getVariable
protected Value getVariable(java.lang.String id, boolean bind)
Identification variables in JPQL are case insensitive, so lower-case all variables we are going to bind.- Overrides:
getVariablein classAbstractExpressionBuilder
-
getDefinedVariable
protected Value getDefinedVariable(java.lang.String id)
-
isSeenVariable
protected boolean isSeenVariable(java.lang.String var)
Description copied from class:AbstractExpressionBuilderReturn whether the given id has been used as a variable.- Overrides:
isSeenVariablein classAbstractExpressionBuilder
-
checkEmbeddable
public static void checkEmbeddable(Value val, java.lang.String currentQuery)
-
convertSubstringArguments
public static Value convertSubstringArguments(ExpressionFactory factory, Value val1, Value val2, Value val3)
Converts JPQL substring() function to OpenJPA ExpressionFactory substring() arguments.- Parameters:
val1- the original Stringval2- the 1-based start index as per JPQL substring() semanticsval3- the length of the returned string as per JPQL semantics
-
setImplicitTypes
public void setImplicitTypes(Value val1, Value val2, java.lang.Class<?> expected)
Description copied from class:AbstractExpressionBuilderSet the implicit types of the given values based on the fact that they're used together, and based on the operator type.- Overrides:
setImplicitTypesin classAbstractExpressionBuilder
-
setImplicitTypes
public static void setImplicitTypes(Value val1, Value val2, java.lang.Class<?> expected, Resolver resolver, OrderedMap<java.lang.Object,java.lang.Class<?>> parameterTypes, java.lang.String currentQuery)
-
getDeclaredVariableType
protected java.lang.Class<?> getDeclaredVariableType(java.lang.String name)
Description copied from class:AbstractExpressionBuilderReturns the type of the named variable if it has been declared.- Specified by:
getDeclaredVariableTypein classAbstractExpressionBuilder
-
addSchemaToContext
protected void addSchemaToContext(java.lang.String id, ClassMetaData meta)Description copied from class:AbstractExpressionBuilderRegister the schema alias to the current JPQL query context.- Specified by:
addSchemaToContextin classAbstractExpressionBuilder
-
addVariableToContext
protected void addVariableToContext(java.lang.String id, Value var)Description copied from class:AbstractExpressionBuilderRegister the variable associated with the schema alias (id) to the current JPQL query context.- Specified by:
addVariableToContextin classAbstractExpressionBuilder
-
getVariable
protected Value getVariable(java.lang.String var)
Description copied from class:AbstractExpressionBuilderReturns the variable associated with the schema alias (id).- Specified by:
getVariablein classAbstractExpressionBuilder
-
-