org.datanucleus.query
Class QueryUtils

java.lang.Object
  extended by org.datanucleus.query.QueryUtils

public class QueryUtils
extends java.lang.Object

Utilities for use in queries.


Field Summary
protected static java.lang.Class[] classArrayObjectObject
          Convenience Class[] for parameter types in getMethod call.
protected static Localiser LOCALISER
          Localiser for messages.
 
Constructor Summary
QueryUtils()
           
 
Method Summary
static java.lang.Object createResultObjectUsingArgumentedConstructor(java.lang.Class resultClass, java.lang.Object[] fieldValues)
          Convenience method to create an instance of the result class with the provided field values, using a constructor taking the arguments.
static java.lang.Object createResultObjectUsingDefaultConstructorAndSetters(java.lang.Class resultClass, java.lang.String[] resultFieldNames, java.lang.reflect.Field[] resultFields, java.lang.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 java.lang.Object createResultObjectUsingDefaultConstructorAndSetters(java.lang.Class resultClass, java.lang.String[] resultFieldNames, java.util.Map resultClassFieldNames, java.lang.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 java.lang.String[] getExpressionsFromString(java.lang.String str)
          Convenience method to split an expression string into its constituent parts where separated by commas.
static java.lang.reflect.Method getPublicPutMethodForResultClass(java.lang.Class resultClass)
          Convenience method to return the put(Object, Object method for the result class.
static java.lang.reflect.Method getPublicSetMethodForFieldOfResultClass(java.lang.Class resultClass, java.lang.String fieldName, java.lang.Class fieldType)
          Convenience method to return the setXXX method for a field of the result class.
static java.lang.String getStringValue(java.lang.Object obj)
          Convenience method to get the String value for an Object.
static java.lang.String getStringValueForExpression(Expression expr, SymbolTable symbolTable)
          Convenience method to get the String value for an Expression.
static java.lang.Object getValueForParameterExpression(java.util.Map parameterValues, ParameterExpression paramExpr)
          Convenience method to get the value for a ParameterExpression.
static java.lang.Object getValueForParameterExpression(SymbolTable symtbl, ParameterExpression paramExpr)
          Convenience method to get the value for a ParameterExpression.
static boolean resultClassIsSimple(java.lang.String className)
          Utility to return if the passed result class is a simple type with a single value.
static boolean resultClassIsUserType(java.lang.String className)
          Utility to return if the passed result class is a user-type, and so requires fields matching up.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final Localiser LOCALISER
Localiser for messages.


classArrayObjectObject

protected static java.lang.Class[] classArrayObjectObject
Convenience Class[] for parameter types in getMethod call.

Constructor Detail

QueryUtils

public QueryUtils()
Method Detail

resultClassIsUserType

public static boolean resultClassIsUserType(java.lang.String className)
Utility to return if the passed result class is a user-type, and so requires fields matching up.

Parameters:
className - the class name looked for
Returns:
Whether it is a user class

resultClassIsSimple

public static boolean resultClassIsSimple(java.lang.String className)
Utility to return if the passed result class is a simple type with a single value. Checks the class name against the supported "simple" JDOQL result-class types.

Parameters:
className - the class name looked for
Returns:
Whether the result class is "simple".

createResultObjectUsingArgumentedConstructor

public static java.lang.Object createResultObjectUsingArgumentedConstructor(java.lang.Class resultClass,
                                                                            java.lang.Object[] fieldValues)
Convenience method to create an instance of the result class with the provided field values, using a constructor taking the arguments. If the returned object is null there is no constructor with the correct signature.

Parameters:
resultClass - The class of results that need creating
fieldValues - The field values
Returns:
The result class object

createResultObjectUsingDefaultConstructorAndSetters

public static java.lang.Object createResultObjectUsingDefaultConstructorAndSetters(java.lang.Class resultClass,
                                                                                   java.lang.String[] resultFieldNames,
                                                                                   java.util.Map resultClassFieldNames,
                                                                                   java.lang.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. If one of these parts is not found in the result class the returned object is null.

Parameters:
resultClass - Result class that we need to create an object of
resultFieldNames - Names of the fields in the results
resultClassFieldNames - Map of the result class fields, keyed by the field name
fieldValues - The field values
Returns:
The result class object

createResultObjectUsingDefaultConstructorAndSetters

public static java.lang.Object createResultObjectUsingDefaultConstructorAndSetters(java.lang.Class resultClass,
                                                                                   java.lang.String[] resultFieldNames,
                                                                                   java.lang.reflect.Field[] resultFields,
                                                                                   java.lang.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. If one of these parts is not found in the result class the returned object is null.

Parameters:
resultClass - Result class that we need to create an object of
resultFieldNames - Names of the fields in the results
resultFields - (java.lang.reflect.)Field objects for the fields in the results
fieldValues - The field values
Returns:
The result class object

getPublicSetMethodForFieldOfResultClass

public static java.lang.reflect.Method getPublicSetMethodForFieldOfResultClass(java.lang.Class resultClass,
                                                                               java.lang.String fieldName,
                                                                               java.lang.Class fieldType)
Convenience method to return the setXXX method for a field of the result class.

Parameters:
resultClass - The result class
fieldName - Name of the field
fieldType - The type of the field being set
Returns:
The setter method

getPublicPutMethodForResultClass

public static java.lang.reflect.Method getPublicPutMethodForResultClass(java.lang.Class resultClass)
Convenience method to return the put(Object, Object method for the result class.

Parameters:
resultClass - The result class
Returns:
The put(Object, Object) method

getExpressionsFromString

public static java.lang.String[] getExpressionsFromString(java.lang.String str)
Convenience method to split an expression string into its constituent parts where separated by commas. This is used in the case of, for example, a result specification, to get the column definitions.

Parameters:
str - The expression string
Returns:
The expression parts

getValueForParameterExpression

public static java.lang.Object getValueForParameterExpression(SymbolTable symtbl,
                                                              ParameterExpression paramExpr)
Convenience method to get the value for a ParameterExpression.

Parameters:
symtbl - Symbol table containing the parameter symbol
paramExpr - Expression
Returns:
The value in the object for this expression

getValueForParameterExpression

public static java.lang.Object getValueForParameterExpression(java.util.Map parameterValues,
                                                              ParameterExpression paramExpr)
Convenience method to get the value for a ParameterExpression.

Parameters:
parameterValues - Input parameter values keyed by the parameter name/position
paramExpr - Expression
Returns:
The value in the object for this expression

getStringValue

public static java.lang.String getStringValue(java.lang.Object obj)
Convenience method to get the String value for an Object. Currently String, Character and Number are supported.

Parameters:
obj - Object
Returns:
The String value for the Object

getStringValueForExpression

public static java.lang.String getStringValueForExpression(Expression expr,
                                                           SymbolTable symbolTable)
Convenience method to get the String value for an Expression. Currently only ParameterExpression and Literal are supported.

Parameters:
primExpr - Expression
Returns:
The String value in the object for this expression


Copyright © 2009. All Rights Reserved.