TypeTablepublic class TypeTable extends Object
Fields Summary |
---|
public static final NullType | nullTypeRepresents the type of null | public static final ErrorType | errorTypeRepresents the internal error type. | public BooleanType | booleanTypeRepresents the type boolean. | public IntegralType | charTypeRepresents the type char. | public IntegralType | byteTypeRepresents the type byte. | public IntegralType | shortTypeRepresents the type short. | public IntegralType | intTypeRepresents the type int. | public IntegralType | longTypeRepresents the type long. | public FloatingPointType | floatTypeRepresents the type float. | public FloatingPointType | doubleTypeRepresents the type double. | public StringType | stringTypeRepresents the type java.lang.String. | public MathType | bigDecimalTypeRepresents the type java.math.BigDecimal | public MathType | bigIntegerTypeRepresents the type java.math.BigInteger | protected com.sun.jdo.api.persistence.model.Model | modelThe model used to access class meta info | protected ClassLoader | classLoaderStore class loader for Class.forName lookup | protected Map | typesThe list of actual known types. | private static Map | typeTablesMap of TypeTable instances. Key is a classLoader. |
Constructors Summary |
---|
private TypeTable(ClassLoader classLoader)
// init model
// JQLC is only used at runtime => use runtime model
this.model = Model.RUNTIME;
this.classLoader = classLoader;
booleanType = new BooleanType();
types.put(booleanType.getName(), booleanType);
charType = new IntegralType("char", char.class, FieldTypeEnumeration.CHARACTER_PRIMITIVE); //NOI18N
types.put(charType.getName(), charType);
byteType = new IntegralType("byte", byte.class, FieldTypeEnumeration.BYTE_PRIMITIVE); //NOI18N
types.put(byteType.getName(), byteType);
shortType = new IntegralType("short", short.class, FieldTypeEnumeration.SHORT_PRIMITIVE); //NOI18N
types.put(shortType.getName(), shortType);
intType = new IntegralType("int", int.class, FieldTypeEnumeration.INTEGER_PRIMITIVE); //NOI18N
types.put(intType.getName(), intType);
longType = new IntegralType("long", long.class, FieldTypeEnumeration.LONG_PRIMITIVE); //NOI18N
types.put(longType.getName(), longType);
floatType = new FloatingPointType("float", float.class, FieldTypeEnumeration.FLOAT_PRIMITIVE); //NOI18N
types.put(floatType.getName(), floatType);
doubleType = new FloatingPointType("double", double.class, FieldTypeEnumeration.DOUBLE_PRIMITIVE); //NOI18N
types.put(doubleType.getName(), doubleType);
stringType = new StringType(this);
types.put(stringType.getName(), stringType);
WrapperClassType booleanClassType =
new WrapperClassType("java.lang.Boolean", Boolean.class, FieldTypeEnumeration.BOOLEAN, booleanType, this); //NOI18N
types.put(booleanClassType.getName(), booleanClassType);
NumericWrapperClassType byteClassType =
new NumericWrapperClassType("java.lang.Byte", Byte.class, FieldTypeEnumeration.BYTE, byteType, this); //NOI18N
types.put(byteClassType.getName(), byteClassType);
NumericWrapperClassType shortClassType =
new NumericWrapperClassType("java.lang.Short", Short.class, FieldTypeEnumeration.SHORT, shortType, this); //NOI18N
types.put(shortClassType.getName(), shortClassType);
NumericWrapperClassType intClassType =
new NumericWrapperClassType("java.lang.Integer", Integer.class, FieldTypeEnumeration.INTEGER, intType, this); //NOI18N
types.put(intClassType.getName(), intClassType);
NumericWrapperClassType longClassType =
new NumericWrapperClassType("java.lang.Long", Long.class, FieldTypeEnumeration.LONG, longType, this); //NOI18N
types.put(longClassType.getName(), longClassType);
NumericWrapperClassType charClassType =
new NumericWrapperClassType("java.lang.Character", Character.class, FieldTypeEnumeration.CHARACTER, charType, this); //NOI18N
types.put(charClassType.getName(), charClassType);
NumericWrapperClassType floatClassType =
new NumericWrapperClassType("java.lang.Float", Float.class, FieldTypeEnumeration.FLOAT, floatType, this); //NOI18N
types.put(floatClassType.getName(), floatClassType);
NumericWrapperClassType doubleClassType =
new NumericWrapperClassType("java.lang.Double", Double.class, FieldTypeEnumeration.DOUBLE, doubleType, this); //NOI18N
types.put(doubleClassType.getName(), doubleClassType);
booleanType.setWrapper(booleanClassType);
byteType.setWrapper(byteClassType);
shortType.setWrapper(shortClassType);
intType.setWrapper(intClassType);
longType.setWrapper(longClassType);
charType.setWrapper(charClassType);
floatType.setWrapper(floatClassType);
doubleType.setWrapper(doubleClassType);
bigDecimalType = new MathType("java.math.BigDecimal", BigDecimal.class, FieldTypeEnumeration.BIGDECIMAL, this); //NOI18N
types.put(bigDecimalType.getName(), bigDecimalType);
bigIntegerType = new MathType("java.math.BigInteger", BigInteger.class, FieldTypeEnumeration.BIGINTEGER, this); //NOI18N
types.put(bigIntegerType.getName(), bigIntegerType);
// Date types
DateType dateType = new DateType("java.util.Date", java.util.Date.class, FieldTypeEnumeration.UTIL_DATE, this);
types.put(dateType.getName(), dateType);
DateType sqldateType = new DateType("java.sql.Date", java.sql.Date.class, FieldTypeEnumeration.SQL_DATE, this);
types.put(sqldateType.getName(), sqldateType);
DateType sqlTimeType = new DateType("java.sql.Time", java.sql.Time.class, FieldTypeEnumeration.SQL_TIME, this);
types.put(sqlTimeType.getName(), sqlTimeType);
DateType sqlTimestampType = new DateType("java.sql.Timestamp", java.sql.Timestamp.class, FieldTypeEnumeration.SQL_TIMESTAMP, this);
types.put(sqlTimestampType.getName(), sqlTimestampType);
|
Methods Summary |
---|
public Type | binaryNumericPromotion(Type left, Type right)Implements binary numeric promotion as defined in the Java Language Specification section 5.6.2
if ((left instanceof NumericType) && (right instanceof NumericType))
{
if (left.equals(doubleType) || right.equals(doubleType))
return doubleType;
else if (left.equals(floatType) || right.equals(floatType))
return floatType;
else if (left.equals(longType) || right.equals(longType))
return longType;
else
return intType;
}
else
{
return errorType;
}
| public Type | checkType(java.lang.String name)Checks for the type with the specified name.
First the internal type table is checked.
If the type is not found it checks Class.forName.
If the type is found the internal type table is updated
(optimization for further access).
If the type is neither in the type table nor found by forName
null is returned and the type table is not changed.
Otherwise the Type representation of the type is returned.
synchronized(types)
{
Type result = (Type)types.get(name);
if (result == null)
{
// type not found => check repository
try
{
Class clazz = Class.forName(name, true, classLoader);
result = new ClassType(name, clazz, this);
types.put(name, result);
}
catch (ClassNotFoundException ex)
{
// unknown class -> error message?
}
}
return result;
}
| public Type | checkType(java.lang.Class clazz)Checks for the type with the specified name.
First the internal type table is checked.
If the type is not found it checks Class.forName.
If the type is found the internal type table is updated
(optimization for further access).
If the type is neither in the type table nor found by forName
null is returned and the type table is not changed.
Otherwise the Type representation of the type is returned.
if (clazz == null)
return null;
String name = clazz.getName();
synchronized (types)
{
Type result = (Type)types.get(name);
if (result == null)
{
// type not found
result = new ClassType(name, clazz, this);
types.put(name, result);
}
return result;
}
| public Type | getAvgReturnType(Type type)Return JDO QL return type for Avg function for a given type.
if (bigDecimalType.equals(type)) {
return bigDecimalType;
} else if (bigIntegerType.equals(type)) {
return bigIntegerType;
} else if (isNumberType(type)) {
return doubleType.getWrapper();
} else {
return type;
}
| public static com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.TypeTable | getInstance(java.lang.ClassLoader classLoader)
synchronized (typeTables) {
TypeTable typeTable = (TypeTable)typeTables.get(classLoader);
if (typeTable == null) {
typeTable = new TypeTable(classLoader);
typeTables.put(classLoader, typeTable);
}
return typeTable;
}
| public Type | getMinMaxReturnType(Type type)Return JDO QL return type for Min/Max function for a given type.
if (isFloatingPointType(type)) {
return doubleType.getWrapper();
} else if (isCharType(type)) {
return charType.getWrapper();
} else if (bigDecimalType.equals(type)) {
return bigDecimalType;
} else if (bigIntegerType.equals(type)) {
return bigIntegerType;
} else if (isNumberType(type)) {
return longType.getWrapper();
} else {
return type;
}
| public Type | getSumReturnType(Type type)Return JDO QL return type for Sum function for a given type.
if (isFloatingPointType(type)) {
return doubleType.getWrapper();
} else if (bigDecimalType.equals(type)) {
return bigDecimalType;
} else if (bigIntegerType.equals(type)) {
return bigIntegerType;
} else if (isNumberType(type)) {
return longType.getWrapper();
} else {
return type;
}
| public boolean | isBooleanType(Type type)Returns true if type is boolean or java.lang.Boolean
return (type.equals(booleanType) || type.equals(booleanType.getWrapper()));
| public boolean | isCharType(Type type)Returns true if type is char or java.lang.Character
return (type.equals(charType) || type.equals(charType.getWrapper()));
| public boolean | isCollectionType(Type type)Returns true if type denotes a collection type.
Note, it returns false for non ClassType values, especially for
NullType and ErrorType.
Type collectionType = checkType("java.util.Collection"); //NOI18N
return (type instanceof ClassType) && type.isCompatibleWith(collectionType);
| public boolean | isDoubleType(Type type)Returns true if type is double or java.lang.Double
return (type.equals(doubleType) || type.equals(doubleType.getWrapper()));
| public boolean | isFloatingPointType(Type type)Returns true if type is a floating point type or a Java wrapper
class type wrapping a floating point integral type.
if (type instanceof FloatingPointType)
return true;
else if (type instanceof NumericWrapperClassType)
return ((NumericWrapperClassType)type).getPrimitiveType() instanceof FloatingPointType;
return false;
| public boolean | isIntType(Type type)Returns true if type is int or java.lang.Integer
return (type.equals(intType) || type.equals(intType.getWrapper()));
| public boolean | isIntegralType(Type type)Returns true if type is an integral type or a Java wrapper class
type wrapping an integral type.
if (type instanceof IntegralType)
return true;
else if (type instanceof NumericWrapperClassType)
return ((NumericWrapperClassType)type).getPrimitiveType() instanceof IntegralType;
return false;
| public boolean | isJavaLangMathType(Type type)Returns true if type denotes a collection type.
Note, it returns false for non ClassType values, especially for
NullType and ErrorType.
Type mathType = checkType("java.lang.Math"); //NOI18N
return (type instanceof ClassType) && type.isCompatibleWith(mathType);
| public boolean | isNumberType(Type type)Returns true if type is a NumericType or compatible to java.lang.Number
Type numberType = checkType("java.lang.Number"); //NOI18N
Type characterType = checkType("java.lang.Character"); //NOI18N
return (type instanceof NumericType) ||
(type.isCompatibleWith(numberType)) ||
(type.isCompatibleWith(characterType));
| public boolean | isPersistenceCapableType(Type type)Returns true if type denotes a pertsistence capable class
Note, it returns false for non ClassType values, especially for
NullType and ErrorType.
return ((type instanceof ClassType) &&
((ClassType)type).isPersistenceCapable());
| public static void | removeInstance(java.lang.ClassLoader classLoader)
synchronized (typeTables) {
typeTables.remove(classLoader);
}
| public Type | unaryNumericPromotion(Type type)Implements unray numeric promotion as defined in the Java Language Specification section 5.6.1
if (type instanceof NumericType)
{
if (type.equals(byteType) || type.equals(shortType) || type.equals(charType))
{
return intType;
}
else
{
return type;
}
}
else
{
return errorType;
}
|
|