public class QueryUtils extends Object
Constructor and Description |
---|
QueryUtils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
compareExpressionValues(Object left,
Object right,
Expression.Operator op)
Convenience method to compare two expression values against the specified operator.
|
static Object |
createResultObjectUsingArgumentedConstructor(Class resultClass,
Object[] fieldValues,
Class[] fieldTypes)
Convenience method to create an instance of the result class with the provided field
values, using a constructor taking the arguments.
|
static Object |
createResultObjectUsingDefaultConstructorAndSetters(Class resultClass,
String[] resultFieldNames,
Field[] resultFields,
Object[] fieldValues)
Convenience method to create an instance of the result class with the provided field
values, using the default constructor and setting the fields using either public fields,
or setters, or a put method.
|
static Object |
createResultObjectUsingDefaultConstructorAndSetters(Class resultClass,
String[] resultFieldNames,
Map resultClassFieldNames,
Object[] fieldValues)
Convenience method to create an instance of the result class with the provided field
values, using the default constructor and setting the fields using either public fields,
or setters, or a put method.
|
static boolean |
expressionHasNotOperator(Expression expr)
Convenience method to return if there is a NOT operator in the expression.
|
static boolean |
expressionHasOrOperator(Expression expr)
Convenience method to return if there is an OR operator in the expression.
|
static String[] |
getExpressionsFromString(String str)
Convenience method to split an expression string into its constituent parts where separated by commas.
|
static String |
getKeyForQueryResultsCache(Query query,
Map params)
Convenience method to generate the "key" for storing the query results of a query with parameters.
|
static ParameterExpression |
getParameterExpressionForPosition(Expression rootExpr,
int pos)
Convenience method to return the ParameterExpression for the specified position
if found in the expression tree starting at
|
static Method |
getPublicPutMethodForResultClass(Class resultClass)
Convenience method to return the put(Object, Object method for the result class.
|
static Method |
getPublicSetMethodForFieldOfResultClass(Class resultClass,
String fieldName,
Class fieldType)
Convenience method to return the setXXX method for a field of the result class.
|
static String |
getStringValue(Object obj)
Convenience method to get the String value for an Object.
|
static String |
getStringValueForExpression(Expression expr,
Map parameters)
Convenience method to get the String value for an Expression.
|
static Object |
getValueForParameterExpression(Map parameterValues,
ParameterExpression paramExpr)
Convenience method to get the value for a ParameterExpression.
|
static List |
orderCandidates(List candidates,
Class type,
String ordering,
ExecutionContext ec,
ClassLoaderResolver clr)
Convenience method to in-memory order the candidates, using the ordering supplied.
|
static List |
orderCandidates(List candidates,
Class type,
String ordering,
ExecutionContext ec,
ClassLoaderResolver clr,
String queryLanguage)
Convenience method to in-memory order the candidates, using the ordering supplied.
|
static List |
orderCandidates(List candidates,
Expression[] ordering,
Map state,
String candidateAlias,
ExecutionContext ec,
ClassLoaderResolver clr,
Map parameterValues,
Imports imports,
String queryLanguage)
Convenience method to order the input List of objects to the ordering defined by the compilation.
|
static boolean |
queryParameterTypesAreCompatible(Class cls1,
Class cls2) |
static boolean |
queryReturnsSingleRow(Query query)
Convenience method to return whether the query should return a single row.
|
static boolean |
resultClassIsSimple(String className)
Utility to return if the passed result class is a simple type with a single value.
|
static boolean |
resultClassIsUserType(String className)
Utility to return if the passed result class is a user-type, and so requires fields matching up.
|
static boolean |
resultHasOnlyAggregates(String result)
Convenience method to return if the "result" clause from a java string-based query language
includes only aggregates.
|
public static boolean resultClassIsUserType(String className)
className
- the class name looked forpublic static boolean resultClassIsSimple(String className)
className
- the class name looked forpublic static boolean resultHasOnlyAggregates(String result)
result
- The result requiredpublic static boolean queryReturnsSingleRow(Query query)
query
- The querypublic static Object createResultObjectUsingArgumentedConstructor(Class resultClass, Object[] fieldValues, Class[] fieldTypes)
resultClass
- The class of results that need creatingfieldValues
- The field valuesfieldTypes
- The field types (optional). If specified needs same number as fieldValuespublic static Object createResultObjectUsingDefaultConstructorAndSetters(Class resultClass, String[] resultFieldNames, Map resultClassFieldNames, Object[] fieldValues)
resultClass
- Result class that we need to create an object ofresultFieldNames
- Names of the fields in the resultsresultClassFieldNames
- Map of the result class fields, keyed by the field namefieldValues
- The field valuespublic static Object createResultObjectUsingDefaultConstructorAndSetters(Class resultClass, String[] resultFieldNames, Field[] resultFields, Object[] fieldValues)
resultClass
- Result class that we need to create an object ofresultFieldNames
- Names of the fields in the resultsresultFields
- (java.lang.reflect.)Field objects for the fields in the resultsfieldValues
- The field valuespublic static Method getPublicSetMethodForFieldOfResultClass(Class resultClass, String fieldName, Class fieldType)
resultClass
- The result classfieldName
- Name of the fieldfieldType
- The type of the field being setpublic static Method getPublicPutMethodForResultClass(Class resultClass)
resultClass
- The result classpublic static String[] getExpressionsFromString(String str)
str
- The expression stringpublic static Object getValueForParameterExpression(Map parameterValues, ParameterExpression paramExpr)
parameterValues
- Input parameter values keyed by the parameter name/positionparamExpr
- Expressionpublic static String getStringValue(Object obj)
obj
- Objectpublic static String getStringValueForExpression(Expression expr, Map parameters)
expr
- Expressionparameters
- Input parameterspublic static boolean compareExpressionValues(Object left, Object right, Expression.Operator op)
left
- Left objectright
- Right objectop
- OperatorNucleusException
- if the comparison is impossiblepublic static boolean expressionHasOrOperator(Expression expr)
expr
- The expressionpublic static boolean expressionHasNotOperator(Expression expr)
expr
- The expressionpublic static ParameterExpression getParameterExpressionForPosition(Expression rootExpr, int pos)
rootExpr
rootExpr
- The expressionpos
- The positionpublic static boolean queryParameterTypesAreCompatible(Class cls1, Class cls2)
public static String getKeyForQueryResultsCache(Query query, Map params)
JDOQL:SELECT FROM myClass WHERE myFilter:123456where "123456" is the hashCode of the parameters for the query
query
- The queryparams
- The paramspublic static List orderCandidates(List candidates, Class type, String ordering, ExecutionContext ec, ClassLoaderResolver clr)
candidates
- The candidatestype
- Candidate typeordering
- The ordering clauseec
- Execution Contextclr
- ClassLoader resolverpublic static List orderCandidates(List candidates, Class type, String ordering, ExecutionContext ec, ClassLoaderResolver clr, String queryLanguage)
candidates
- The candidatestype
- Candidate typeordering
- The ordering clauseec
- Execution Contextclr
- ClassLoader resolverqueryLanguage
- The query language in usepublic static List orderCandidates(List candidates, Expression[] ordering, Map state, String candidateAlias, ExecutionContext ec, ClassLoaderResolver clr, Map parameterValues, Imports imports, String queryLanguage)
candidates
- Candidatesordering
- Ordering expression(s)state
- Map of state information (see JavaQueryEvaluator)candidateAlias
- Candidate aliasec
- ExecutionContextclr
- ClassLoader resolverparameterValues
- Any parameter values (maybe used by the ordering clause)imports
- Imports for the queryqueryLanguage
- The language of this query (JDOQL, JPQL etc)Copyright © 2019. All rights reserved.