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 DBType
The 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).int
Get 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.int
Get the length associated with this target type.boolean
Indicate whether the output of the CAST function is a geometry or not.boolean
Indicate whether the output of the CAST function is numeric or not.static boolean
isStandardDatatype
(DBType.DBDatatype datatype) Tell whether the given datatype is allowed as target for CAST function.boolean
isString()
Indicate whether the output of the CAST function is a character string or not.static final String
normalizeDatatype
(String str) Normalize the given datatype serialization.static final DBType.DBDatatype
resolveDatatype
(String str) Resolve the given type serialization into aDBType.DBDatatype
.setParameter
(int indParam, ADQLOperand newParam) Replace the indParam-th parameter.void
setPosition
(TextPosition newPosition) Sets the position at which thisTargetType
has 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
normalized
and then resolved into aDBType.DBDatatype
value. If no DBDatatype matches, anIllegalArgumentException
is 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.DBDatatype
returned 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:
true
if allowed by ADQL as CAST' target type,false
otherwise.
-
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:TargetType
Indicate 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:
isNumeric
in interfaceTargetType
- Returns:
true
if the CAST function returns a numeric,false
otherwise.
-
isString
public boolean isString()Description copied from interface:TargetType
Indicate 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:
isString
in interfaceTargetType
- Returns:
true
if the CAST function returns a string,false
otherwise.
-
isGeometry
public boolean isGeometry()Description copied from interface:TargetType
Indicate 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:
isGeometry
in interfaceTargetType
- Returns:
true
if the CAST function returns a geometry,false
otherwise.
-
getName
Description copied from interface:TargetType
Get the type name (as written in ADQL).IMPORTANT: This function MUST never return NULL or an empty string.
- Specified by:
getName
in 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:TargetType
Indicate 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:
getReturnType
in interfaceTargetType
- Returns:
- The expected type returned by the CAST function, or NULL if unknown.
-
getCopy
Description copied from interface:TargetType
Create a deep copy of this target type.- Specified by:
getCopy
in interfaceTargetType
- Returns:
- Type copy.
- Throws:
Exception
- If the copy fails.
-
getPosition
Description copied from interface:TargetType
Position of the type name (start) and all its parameters (end).- Specified by:
getPosition
in 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:TargetType
Sets the position at which thisTargetType
has been found in the original ADQL query string.- Specified by:
setPosition
in interfaceTargetType
-
toString
-
getNbParameters
public int getNbParameters()Description copied from interface:TargetType
Get the actual number of parameters.- Specified by:
getNbParameters
in interfaceTargetType
- Returns:
- Number of parameters.
-
getParameters
Description copied from interface:TargetType
Get the ordered list of all parameters.- Specified by:
getParameters
in interfaceTargetType
- Returns:
- All type parameters, or an empty array if no parameter.
-
getParameter
Description copied from interface:TargetType
Get the indParam-th parameter.- Specified by:
getParameter
in interfaceTargetType
- Parameters:
indParam
- Index (≥ 0) of the parameter to get.- Returns:
- The corresponding parameter.
-
setParameter
Description copied from interface:TargetType
Replace the indParam-th parameter.- Specified by:
setParameter
in 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:TargetType
Serialize this type into ADQL.- Specified by:
toADQL
in interfaceTargetType
- Returns:
- Its ADQL serialization.
-