public final class DataTypeHelper extends java.lang.Object implements HQLParserTokenTypes
upper()
The FqlType
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.Integer,java.lang.Class<? extends BaseDataType>> |
bdts
Map of SQL types to BDT classes
|
private static java.util.Map<java.lang.Class<?>,FqlType> |
classes
Map of Java class types to HQL types
|
private static java.util.Map<FunctionKey,FqlType> |
functions
Map of functions to HQL types
|
private static java.util.Map<java.lang.Integer,FqlType> |
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, JOIN, 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, SQL_TYPE, 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 FqlType |
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 java.lang.Class<? extends BaseDataType> |
getBdtClass(int sqlType) |
static java.lang.Class<?> |
getJavaTypeQualifiedProperty(Aast aliasAst,
java.util.Map<java.lang.String,RecordBuffer> bufferMap)
Get the Java type associated with a particular, qualified DMO property, as represented by the given AST.
|
static java.lang.Class<?> |
getJavaTypeUnqualifiedProperty(Aast propAst,
java.util.Map<java.lang.String,RecordBuffer> bufferMap)
Get the Java type associated with a particular, unqualified DMO property, as represented by the given AST.
|
static FqlType |
getTypeClass(java.lang.Class<?> javaType)
Get the HQL type associated with a particular Java class.
|
private static FqlType |
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 FqlType |
getTypeFunction(FunctionKey key)
Get the HQL type associated with a particular
FunctionKey . |
static FqlType |
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 FqlType |
getTypeToken(int tokenType)
Get the HQL type associated with a particular token type.
|
static FqlType |
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
FqlType . |
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 FqlType for that function. |
private static void |
initFunction(java.lang.String name,
FqlType returns,
FqlType... paramTypes)
Given the name and signature of a user-defined function accessible from
HQL, create a mapping of
FunctionKey to FqlType for that function. |
private static void |
initFunctions()
Initialize the mappings of
FunctionKey to FqlType 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
FqlType for those
classes which are known to be used in HQL where clauses. |
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,FqlType> tokens
private static final java.util.Map<FunctionKey,FqlType> functions
private static final java.util.Map<java.lang.Class<?>,FqlType> classes
private static final java.util.Map<java.lang.Integer,java.lang.Class<? extends BaseDataType>> bdts
private DataTypeHelper()
public static void initialize()
public static FqlType getTypeClass(java.lang.Class<?> javaType)
javaType
- A Java class.FqlType.UNKNOWN
if no mapping is available.public static java.lang.Class<? extends BaseDataType> getBdtClass(int sqlType)
public static FqlType getTypeToken(int tokenType)
tokenType
- A token type from HQLParserTokenTypes
.FqlType.UNKNOWN
if no mapping is available.public static FqlType getTypeFunction(FunctionKey key)
FunctionKey
.key
- A FunctionKey
which describes a standard function
or a built-in function.FqlType.UNKNOWN
if no mapping is available.public static FqlType 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).FqlType.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 FqlType 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).FqlType.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 java.lang.Class<?> getJavaTypeQualifiedProperty(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).PersistenceException
- if the property does not exist, or if there is some error
determining its data type.public static java.lang.Class<?> getJavaTypeUnqualifiedProperty(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).PersistenceException
- if the property does not exist, or if there is some error
determining its data type.public static FqlType 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 FqlType 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).FqlType.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()
FqlType
for those
classes which are known to be used in HQL where clauses.private static void initBasicTokens()
FqlType
. Only
those token types whose data types will not change (i.e., constants and
certain operators) are mapped here.private static void initFunctions()
FunctionKey
to FqlType
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 FqlType
for that function.method
- Java method to be mapped.private static void initFunction(java.lang.String name, FqlType returns, FqlType... paramTypes)
FunctionKey
to FqlType
for that function.name
- Function namereturns
- Data type that the function returns.paramTypes
- Data types of function parameters, if any.