public final class DataTypeHelper extends java.lang.Object implements HQLParserTokenTypes
upper()
The HQLTypes
enum is used to rationalize all the various type
constructs (token types, Java class types, Hibernate types) into a common
construct. Any request for type information will be in terms of an
HQLTypes
enum value.
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.Class<?>,HQLTypes> |
classes
Map of Java class types to HQL types
|
private static java.util.Map<FunctionKey,HQLTypes> |
functions
Map of functions to HQL types
|
private static java.util.Map<org.hibernate.type.Type,HQLTypes> |
parameters
Map of query substitution parameter Hibernate types to HQL types
|
private static java.util.Map<java.lang.Integer,HQLTypes> |
tokens
Map of token types to HQL types
|
ALIAS, AND, AS, BOOL_FALSE, BOOL_TRUE, CASE, CAST, COMMA, CONCAT, DEC_LITERAL, DIGIT, DIVIDE, DMO, DOT, ELSE, END, EOF, EQUALS, ESCAPE, FROM, FUNCTION, GT, GTE, IN, INDEX, IS, IS_NULL, LBRACKET, LETTER, LIKE, LONG_LITERAL, LPARENS, LT, LTE, MINUS, MULTIPLY, NOT, NOT_EQ, NOT_NULL, NULL, NULL_TREE_LOOKAHEAD, NUM_LITERAL, OR, PLUS, PROPERTY, RBRACKET, RPARENS, SELECT, STRING, SUBSCRIPT, SUBSELECT, SUBST, SYM_CHAR, SYMBOL, TERNARY, THEN, UN_MINUS, VALID_1ST_IDENT, VALID_SYM_CHAR, WHEN, WHERE, WS
Modifier | Constructor and Description |
---|---|
private |
DataTypeHelper()
Private constructor; access is via static methods.
|
Modifier and Type | Method and Description |
---|---|
static HQLTypes |
expressionType(Aast node,
java.util.Map<java.lang.String,RecordBuffer> bufferMap)
Determine the HQL type of the expression represented by the given AST node, which may be
a single leaf node, or the head of a more complex expression.
|
static HQLTypes |
getTypeClass(java.lang.Class<?> javaType)
Get the HQL type associated with a particular Java class.
|
private static HQLTypes |
getTypeFunction(Aast function,
java.util.Map<java.lang.String,RecordBuffer> bufferMap)
Get the HQL type which will be returned when the given function is executed.
|
static HQLTypes |
getTypeFunction(FunctionKey key)
Get the HQL type associated with a particular
FunctionKey . |
static HQLTypes |
getTypeParameter(org.hibernate.type.Type paramType)
Get the HQL type associated with a particular Hibernate
Type , used to identify the data type of a query
substitution parameter. |
static HQLTypes |
getTypeQualifiedProperty(Aast aliasAst,
java.util.Map<java.lang.String,RecordBuffer> bufferMap)
Get the HQL type associated with a particular, qualified DMO property,
as represented by the given AST.
|
static HQLTypes |
getTypeToken(int tokenType)
Get the HQL type associated with a particular token type.
|
static HQLTypes |
getTypeUnqualifiedProperty(Aast propAst,
java.util.Map<java.lang.String,RecordBuffer> bufferMap)
Get the HQL type associated with a particular, unqualified DMO property,
as represented by the given AST.
|
private static void |
initBasicTokens()
Initialize the mapping of basic token types to
HQLTypes . |
private static void |
initFunction(java.lang.reflect.Method method)
Given a Java method which represents a user-defined function accessible
from HQL, create a mapping of
FunctionKey to HQLTypes for that function. |
private static void |
initFunction(java.lang.String name,
HQLTypes returns,
HQLTypes... paramTypes)
Given the name and signature of a user-defined function accessible from
HQL, create a mapping of
FunctionKey to HQLTypes for that function. |
private static void |
initFunctions()
Initialize the mappings of
FunctionKey to HQLTypes for
all standard functions used in HQL (including built-in functions which
emulate Progress functionality). |
static void |
initialize()
Initialize the data structures needed to enable this helper.
|
private static void |
initJavaClasses()
Initialize the mapping of Java classes to
HQLTypes for those
classes which are known to be used in HQL where clauses. |
private static void |
initQueryParamTypes()
Initialize the mapping of Hibernate
Type s to HQLTypes for those Hibernate Type s (including custom P2J
wrapper types) which are known to be used in HQL where clauses as query
substitution parameters. |
static RecordBuffer |
lookupBuffer(Aast alias,
java.util.Map<java.lang.String,RecordBuffer> bufferMap,
HQLExpression hql)
Attempt to look up a record buffer by alias from the given map.
|
private static final java.util.Map<java.lang.Integer,HQLTypes> tokens
private static final java.util.Map<FunctionKey,HQLTypes> functions
private static final java.util.Map<org.hibernate.type.Type,HQLTypes> parameters
private static final java.util.Map<java.lang.Class<?>,HQLTypes> classes
private DataTypeHelper()
public static void initialize()
public static HQLTypes getTypeClass(java.lang.Class<?> javaType)
javaType
- A Java class.HQLTypes.UNKNOWN
if no mapping is available.public static HQLTypes getTypeToken(int tokenType)
tokenType
- A token type from HQLParserTokenTypes
.HQLTypes.UNKNOWN
if no mapping is available.public static HQLTypes getTypeParameter(org.hibernate.type.Type paramType)
Type
, used to identify the data type of a query
substitution parameter.paramType
- A Hibernate Type
.HQLTypes.UNKNOWN
if no mapping is available.public static HQLTypes getTypeFunction(FunctionKey key)
FunctionKey
.key
- A FunctionKey
which describes a standard function
or a built-in function.HQLTypes.UNKNOWN
if no mapping is available.public static HQLTypes getTypeQualifiedProperty(Aast aliasAst, java.util.Map<java.lang.String,RecordBuffer> bufferMap) throws PersistenceException
aliasAst
- An AST which represents a DMO alias, whose first (and only)
child represents a property of that DMO.bufferMap
- A map of DMO aliases to their corresponding record buffers, where null
is mapped to the buffer whose property references in the HQL expression are
unqualified (if any).HQLTypes.UNKNOWN
if no mapping is available.PersistenceException
- if the property does not exist, or if there is some error
determining its data type.public static HQLTypes getTypeUnqualifiedProperty(Aast propAst, java.util.Map<java.lang.String,RecordBuffer> bufferMap) throws PersistenceException
propAst
- An AST which represents a property of a DMO.bufferMap
- A map of DMO aliases to their corresponding record buffers, where null
is mapped to the buffer whose property references in the HQL expression are
unqualified (if any).HQLTypes.UNKNOWN
if no mapping is available.PersistenceException
- if the property does not exist, or if there is some error
determining its data type.public static HQLTypes expressionType(Aast node, java.util.Map<java.lang.String,RecordBuffer> bufferMap) throws PersistenceException
node
- AST node whose HQL type is to be determined.bufferMap
- A map of DMO aliases to their corresponding record buffers, where null
is mapped to the buffer whose property references in the HQL expression are
unqualified (if any).PersistenceException
- if a DMO property referenced within the expression does not
exist, or if there is some error determining its data type.public static RecordBuffer lookupBuffer(Aast alias, java.util.Map<java.lang.String,RecordBuffer> bufferMap, HQLExpression hql)
alias
AST. If there is no matching entry in the buffer map, an exception
is thrown.
The returned buffer is initialized by side effect.
alias
- DMO alias AST. If null
, a null
lookup key is used.bufferMap
- A map of DMO aliases to record buffers. If no alias is provided (e.g., for an
unqualified property reference, the appropriate buffer is expected to be mapped
to the null
key.hql
- Optional HQL expression from which the alias is parsed.private static HQLTypes getTypeFunction(Aast function, java.util.Map<java.lang.String,RecordBuffer> bufferMap) throws PersistenceException
function
- AST node representing a standard or built-in function expression.bufferMap
- A map of DMO aliases to their corresponding record buffers, where null
is mapped to the buffer whose property references in the HQL expression are
unqualified (if any).HQLTypes.UNKNOWN
if
no mapping is available.PersistenceException
- if a DMO property referenced within the expression does not exist, or if there
is some error determining its data type.private static void initJavaClasses()
HQLTypes
for those
classes which are known to be used in HQL where clauses.private static void initBasicTokens()
HQLTypes
. Only
those token types whose data types will not change (i.e., constants and
certain operators) are mapped here.private static void initQueryParamTypes()
Type
s to HQLTypes
for those Hibernate Type
s (including custom P2J
wrapper types) which are known to be used in HQL where clauses as query
substitution parameters.private static void initFunctions()
FunctionKey
to HQLTypes
for
all standard functions used in HQL (including built-in functions which
emulate Progress functionality).private static void initFunction(java.lang.reflect.Method method)
FunctionKey
to HQLTypes
for that function.method
- Java method to be mapped.private static void initFunction(java.lang.String name, HQLTypes returns, HQLTypes... paramTypes)
FunctionKey
to HQLTypes
for that function.name
- Function namereturns
- Data type that the function returns.paramTypes
- Data types of function parameters, if any.