Class StandardTargetType
- All Implemented Interfaces:
TargetType
Parameters
All target types represented by this class can not be parameterized, except
variable datatypes (such as DBType.DBDatatype.CHAR and
DBType.DBDatatype.VARCHAR) which may have only one - the length.
Standard datatypes
Datatypes considered as standard by this class can be retrieved thanks to
getStandardDatatypes(). It is also possible to get them by category
with getNumericDatatypes(), getStringDatatypes() and
getGeometricDatatypes(). A given DBType.DBDatatype can be tested
to know whether it is considered as standard or not with
isStandardDatatype(DBDatatype).
Note:
DBType.DBDatatype.DOUBLE is represented in ADQL with the string
DOUBLE PRECISION. This specificity is already taken into
account by toADQL() and when creating a StandardTargetType
with a string (see below).
Datatype normalization
The constructors StandardTargetType(String) and
StandardTargetType(String, int) accepts the string version of
a standard datatype. To resolve it, they rely on the static function
resolveDatatype(String). This latter always normalize the input
string so that consecutive whitespace characters are replaced by only one
and all other characters are upper-case. The normalization is performed by
the static function normalizeDatatype(String).
- Since:
- 2.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final DBType.DBDatatype[]All datatypes allowed by ADQL as CAST's target type.protected DBTypeThe represented target type. -
Constructor Summary
ConstructorsConstructorDescriptionStandardTargetType(DBType type) Create a standard target type.StandardTargetType(String typeName) Create a standard target type with just a datatype (no length parameter).StandardTargetType(String typeName, int length) Create a standard target type, possibly a variable-length one. -
Method Summary
Modifier and TypeMethodDescriptiongetCopy()Create a deep copy of this target type.static final DBType.DBDatatype[]Get all geometric datatypes among all the standard CAST's target types.getName()Get the type name (as written in ADQL).intGet the actual number of parameters.static final DBType.DBDatatype[]Get all numeric datatypes among all the standard CAST's target types.getParameter(int indParam) Get the indParam-th parameter.Get the ordered list of all parameters.Position of the type name (start) and all its parameters (end).Indicate the precise type of the value expected to be returned by the CAST function.static final DBType.DBDatatype[]Get all datatypes considered as standard CAST's target types.static final DBType.DBDatatype[]Get all string datatypes among all the standard CAST's target types.intGet the length associated with this target type.booleanIndicate whether the output of the CAST function is a geometry or not.booleanIndicate whether the output of the CAST function is numeric or not.static booleanisStandardDatatype(DBType.DBDatatype datatype) Tell whether the given datatype is allowed as target for CAST function.booleanisString()Indicate whether the output of the CAST function is a character string or not.static final StringnormalizeDatatype(String str) Normalize the given datatype serialization.static final DBType.DBDatatyperesolveDatatype(String str) Resolve the given type serialization into aDBType.DBDatatype.setParameter(int indParam, ADQLOperand newParam) Replace the indParam-th parameter.voidsetPosition(TextPosition newPosition) Sets the position at which thisTargetTypehas been found in the original ADQL query string.toADQL()Serialize this type into ADQL.toString()
-
Field Details
-
STANDARD_DATATYPES
All datatypes allowed by ADQL as CAST's target type. -
type
The represented target type.
-
-
Constructor Details
-
StandardTargetType
Create a standard target type with just a datatype (no length parameter).Implementation note: This constructor is similar to
StandardTargetType(String, int)with(typeName,.DBType.NO_LENGTH)- Parameters:
typeName- Target type's name.- Throws:
NullPointerException- If the type name is NULL or empty.IllegalArgumentException- If the given type name is unknown or not standard.
-
StandardTargetType
public StandardTargetType(String typeName, int length) throws NullPointerException, IllegalArgumentException Create a standard target type, possibly a variable-length one.Warning: A length can be provided only for a variable-length datatype (e.g. CHAR, VARCHAR).
- Parameters:
typeName- Name of the type.length- Length of the type (or ≤0 if undefined).- Throws:
NullPointerException- If the type name is NULL or empty.IllegalArgumentException- If the given type name is unknown or not standard, or if a positive non-zero length is provided for a non variable-length datatype.
-
StandardTargetType
Create a standard target type.- Parameters:
type- Target type.- Throws:
NullPointerException- If the target type is missing.IllegalArgumentException- If the given type is not standard, or if a length is provided for non variable-length datatype.
-
-
Method Details
-
normalizeDatatype
Normalize the given datatype serialization.The normalization performed here...
- ...remove leading and trailing space characters,
- ...replace all consecutive space characters by a single space,
- ...and put all characters in upper-case.
- Parameters:
str- The string to normalize.- Returns:
- Its normalized version.
- Throws:
NullPointerException- If the given string is NULL or empty.
-
resolveDatatype
public static final DBType.DBDatatype resolveDatatype(String str) throws NullPointerException, IllegalArgumentException Resolve the given type serialization into aDBType.DBDatatype.The given string is
normalizedand then resolved into aDBType.DBDatatypevalue. If no DBDatatype matches, anIllegalArgumentExceptionis thrown.Note: The returned datatype is not guaranteed to be a standard CAST's target datatype: this is not checked in this function. To check the datatype use
isStandardDatatype(DBDatatype)with theDBType.DBDatatypereturned by this function.- Parameters:
str- The type's string serialization.- Returns:
- The resolved datatype.
- Throws:
NullPointerException- If the given string is NULL or empty.IllegalArgumentException- If the serialized datatype is unknown.
-
isStandardDatatype
Tell whether the given datatype is allowed as target for CAST function.- Parameters:
datatype- The datatype to test.- Returns:
trueif allowed by ADQL as CAST' target type,falseotherwise.
-
getStandardDatatypes
Get all datatypes considered as standard CAST's target types.- Returns:
- All standard CAST's target types.
-
getNumericDatatypes
Get all numeric datatypes among all the standard CAST's target types.- Returns:
- All standard numeric CAST's target types.
-
getStringDatatypes
Get all string datatypes among all the standard CAST's target types.- Returns:
- All standard string CAST's target types.
-
getGeometricDatatypes
Get all geometric datatypes among all the standard CAST's target types.- Returns:
- All standard geometric CAST's target types.
-
isNumeric
public boolean isNumeric()Description copied from interface:TargetTypeIndicate whether the output of the CAST function is numeric or not.Implementation note: If the return type is unknown, it is a good practice to make
TargetType.isNumeric(),TargetType.isGeometry()andTargetType.isString()to returntrue. This information is used only by the parser when checking whether the CAST function can be used in some context. So, when the type of an ADQL operand is unknown, it is assumed it could be placed anywhere until its type can be precisely determined or until the query reaches the database.- Specified by:
isNumericin interfaceTargetType- Returns:
trueif the CAST function returns a numeric,falseotherwise.
-
isString
public boolean isString()Description copied from interface:TargetTypeIndicate whether the output of the CAST function is a character string or not.Implementation note: If the return type is unknown, it is a good practice to make
TargetType.isNumeric(),TargetType.isGeometry()andTargetType.isString()to returntrue. This information is used only by the parser when checking whether the CAST function can be used in some context. So, when the type of an ADQL operand is unknown, it is assumed it could be placed anywhere until its type can be precisely determined or until the query reaches the database.- Specified by:
isStringin interfaceTargetType- Returns:
trueif the CAST function returns a string,falseotherwise.
-
isGeometry
public boolean isGeometry()Description copied from interface:TargetTypeIndicate whether the output of the CAST function is a geometry or not.Implementation note: If the return type is unknown, it is a good practice to make
TargetType.isNumeric(),TargetType.isGeometry()andTargetType.isString()to returntrue. This information is used only by the parser when checking whether the CAST function can be used in some context. So, when the type of an ADQL operand is unknown, it is assumed it could be placed anywhere until its type can be precisely determined or until the query reaches the database.- Specified by:
isGeometryin interfaceTargetType- Returns:
trueif the CAST function returns a geometry,falseotherwise.
-
getName
Description copied from interface:TargetTypeGet the type name (as written in ADQL).IMPORTANT: This function MUST never return NULL or an empty string.
- Specified by:
getNamein interfaceTargetType- Returns:
- The type name.
-
getTypeLength
public int getTypeLength()Get the length associated with this target type.Note: The returned length can be positive and not null ONLY IF the target type is a variable length type (e.g. CHAR, VARCHAR).
- Returns:
- Type length.
-
getReturnType
Description copied from interface:TargetTypeIndicate the precise type of the value expected to be returned by the CAST function.This information is used only when the CAST function is used as output column (so, in the SELECT clause). It is a hint when formatting the query result to make the most appropriate conversion.
- Specified by:
getReturnTypein interfaceTargetType- Returns:
- The expected type returned by the CAST function, or NULL if unknown.
-
getCopy
Description copied from interface:TargetTypeCreate a deep copy of this target type.- Specified by:
getCopyin interfaceTargetType- Returns:
- Type copy.
- Throws:
Exception- If the copy fails.
-
getPosition
Description copied from interface:TargetTypePosition of the type name (start) and all its parameters (end).- Specified by:
getPositionin interfaceTargetType- Returns:
- Position of this target type in the input ADQL query, or NULL if this piece of information is not available.
-
setPosition
Description copied from interface:TargetTypeSets the position at which thisTargetTypehas been found in the original ADQL query string.- Specified by:
setPositionin interfaceTargetType
-
toString
-
getNbParameters
public int getNbParameters()Description copied from interface:TargetTypeGet the actual number of parameters.- Specified by:
getNbParametersin interfaceTargetType- Returns:
- Number of parameters.
-
getParameters
Description copied from interface:TargetTypeGet the ordered list of all parameters.- Specified by:
getParametersin interfaceTargetType- Returns:
- All type parameters, or an empty array if no parameter.
-
getParameter
Description copied from interface:TargetTypeGet the indParam-th parameter.- Specified by:
getParameterin interfaceTargetType- Parameters:
indParam- Index (≥ 0) of the parameter to get.- Returns:
- The corresponding parameter.
-
setParameter
Description copied from interface:TargetTypeReplace the indParam-th parameter.- Specified by:
setParameterin interfaceTargetType- Parameters:
indParam- Index (≥ 0) of the parameter to replace.newParam- The operand to set instead of the current indParam-th parameter.- Returns:
- The former indParam-th parameter.
-
toADQL
Description copied from interface:TargetTypeSerialize this type into ADQL.- Specified by:
toADQLin interfaceTargetType- Returns:
- Its ADQL serialization.
-