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 DBTypeType of the value returned by the CAST function.protected StringDatatype'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 StringgetName()Get the type name (as written in ADQL).intGet the actual number of parameters.getParameter(int indParam) Get the indParam-th parameter.Get the ordered list of all parameters.final TextPositionPosition of the type name (start) and all its parameters (end).final DBTypeIndicate the precise type of the value expected to be returned by the CAST function.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.booleanisString()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 voidsetPosition(TextPosition newPosition) Sets the position at which thisTargetTypehas been found in the original ADQL query string.voidsetReturnType(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: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.
-
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
-
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.
-
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.
-
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: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.
-
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.
-
toString
-