Class CustomTargetType
- All Implemented Interfaces:
TargetType
Parameters
On the contrary to a standard target type, a custom type does not have any restriction on parameters: it may have as many parameters as desired. There is no constraint as well on their type: no strict signature to follow.
Return type
Because the target type is custom, there is no way to automatically
determine the (approximate or precise) type of the value returned by the
CAST function. The constructor of CustomTargetType
tries anyway to
resolve the given custom type name, in case it is a datatype known by the
ADQL library (see DBType.DBDatatype
). If successfully resolved, a
DBType
is automatically created (with no length parameter) and will
be returned by getReturnType()
. If still unknown (or erroneous),
one has to explicitly use setReturnType(DBType)
.
The functions isNumeric()
, isString()
and
isGeometry()
are used to give hint to the ADQL query parser about
where the CAST function can be used. By default, they return what the
same functions of the getReturnType()
returns. If this latter
returns NULL, all these functions return true
so that the CAST
function can be used anywhere in an ADQL query. However, this may lead to
errors when running the query against a database.
- Since:
- 2.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ADQLOperand[]
Ordered list of all type parameters.protected DBType
Type of the value returned by the CAST function.protected String
Datatype's name. -
Constructor Summary
ConstructorsConstructorDescriptionCustomTargetType
(String typeName) Create a custom CAST's target type with no parameter.CustomTargetType
(String typeName, ADQLOperand[] parameters) Create a custom CAST's target type. -
Method Summary
Modifier and TypeMethodDescriptiongetCopy()
Create a deep copy of this target type.final String
getName()
Get the type name (as written in ADQL).int
Get the actual number of parameters.getParameter
(int indParam) Get the indParam-th parameter.Get the ordered list of all parameters.final TextPosition
Position of the type name (start) and all its parameters (end).final DBType
Indicate the precise type of the value expected to be returned by the CAST function.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.boolean
isString()
Indicate whether the output of the CAST function is a character string or not.setParameter
(int indParam, ADQLOperand newParam) Replace the indParam-th parameter.final void
setPosition
(TextPosition newPosition) Sets the position at which thisTargetType
has been found in the original ADQL query string.void
setReturnType
(DBType newType) Set the expected type returned by the CAST function.toADQL()
Serialize this type into ADQL.toString()
-
Field Details
-
typeName
Datatype's name. Never NULL or empty. -
parameters
Ordered list of all type parameters. >NULL (preferably ; by default) or empty if no parameter. -
returnType
Type of the value returned by the CAST function. NULL if unknown (default).
-
-
Constructor Details
-
CustomTargetType
Create a custom CAST's target type with no parameter.Implementation note: This constructor is equivalent to
CustomTargetType(String, ADQLOperand[])
with(typeName, null)
.- Parameters:
typeName
- Name of the custom type.- Throws:
NullPointerException
- If the given name is NULL or empty.
-
CustomTargetType
Create a custom CAST's target type.- Parameters:
typeName
- Name of the custom type.parameters
- Type parameters (e.g. a length). NULL or empty if no parameter.- Throws:
NullPointerException
- If the given name is NULL or empty, or if one parameter is NULL.
-
-
Method Details
-
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.
-
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
-
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.
-
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.
-
setReturnType
Set the expected type returned by the CAST function.- Parameters:
newType
- The presumed returned type, or NULL if unknown.
-
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.
-
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.
-
toString
-