Class SQLServerTranslator
- All Implemented Interfaces:
ADQLTranslator
Important:
This translator works correctly ONLY IF SQLServer_ADQLQueryFactory
has been used to create any ADQL query this translator is asked to
translate.
translateGeometryFromDB(Object)
, translateGeometryToDB(Region)
and all this other
translate(...) functions for the ADQL's geometrical functions.
TODO Check MS SQL Server datatypes (see convertTypeFromDB(int, String, String, String[])
,
convertTypeToDB(DBType)
).
Important note 1: Geometrical functions and IN_UNIT are not translated ; the translation returned for them is their ADQL expression.
Important note 2:
If new optional features are supported in an extension of this translator,
they should be visible in getSupportedFeatures()
. To customize this
list, you must overwrite initSupportedFeatures()
and update in
there the attribute supportedFeatures
.
- Since:
- 1.4
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte
Indicate the case sensitivity to apply to each SQL identifier (only SCHEMA, TABLE and COLUMN).protected final FeatureSet
List of all optional features supported by this translator. -
Constructor Summary
ConstructorsConstructorDescriptionBuilds an SQLServerTranslator which always translates in SQL all identifiers (schema, table and column) in a case sensitive manner ; in other words, schema, table and column names will be surrounded by double quotes in the SQL translation.SQLServerTranslator
(boolean allCaseSensitive) Builds an SQLServerTranslator which always translates in SQL all identifiers (schema, table and column) in the specified case sensitivity ; in other words, schema, table and column names will all be surrounded or not by double quotes in the SQL translation.SQLServerTranslator
(boolean catalog, boolean schema, boolean table, boolean column) Builds an SQLServerTranslator which will always translate in SQL identifiers with the defined case sensitivity. -
Method Summary
Modifier and TypeMethodDescriptionconvertTypeFromDB
(int dbmsType, String rawDbmsTypeName, String dbmsTypeName, String[] params) Convert any type provided by a JDBC driver into a type understandable by the ADQL/TAP library.convertTypeToDB
(DBType type) Convert any type provided by the ADQL/TAP library into a type understandable by a JDBC driver.protected ADQLColumn
generateJoinColumn
(FromContent table, DBColumn colMeta, ADQLColumn joinedColumn) Generate an ADQL column of the given table and with the given metadata.final FeatureSet
Get all features that are fully supported by this translator.protected void
Initialize the list of optional features supported by this translator.boolean
isCaseSensitive
(IdentifierField field) Tell whether the specified identifier MUST be translated so that being interpreted case sensitively or not.For SQL Server,translate(ClauseSelect)
must be overridden for LIMIT and OFFSET handling.translate
(ClauseSelect clause) Translate the given SELECT clause into an SQL compatible with MS-SQLServer.protected String
translate
(ClauseSelect clause, boolean topAllowed) This version oftranslate(ClauseSelect)
lets translate the given SELECT clause with or without the TOP instruction in case a limit is specified in ADQL.translate
(Comparison comp) translate
(Concatenation concat) translate
(AreaFunction areaFunction) translate
(BoxFunction box) translate
(CentroidFunction centroidFunction) translate
(CircleFunction circle) translate
(ExtractCoord extractCoord) translate
(ExtractCoordSys extractCoordSys) translate
(PointFunction point) translate
(PolygonFunction polygon) translate
(InUnitFunction fct) translate
(MathFunction fct) translate
(SetOperation set) translateGeometryFromDB
(Object jdbcColValue) Parse the given JDBC column value as a geometry object and convert it into aRegion
.translateGeometryToDB
(Region region) Convert the given STC region into a DB column value.Methods inherited from class adql.translator.JDBCTranslator
appendIdentifier, appendIdentifier, getColumnName, getDefaultADQLFunction, getDefaultADQLList, getDefaultADQLList, getDefaultCastFunction, getDefaultColumnReference, getQualifiedSchemaName, getQualifiedTableName, getTableName, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate, translate
-
Field Details
-
caseSensitivity
protected byte caseSensitivityIndicate the case sensitivity to apply to each SQL identifier (only SCHEMA, TABLE and COLUMN).
Note: In this implementation, this field is set by the constructor and never modified elsewhere. It would be better to never modify it after the construction in order to keep a certain consistency.
-
supportedFeatures
List of all optional features supported by this translator.Note: This list can be customized by extending this translator and then overwriting
initSupportedFeatures()
.- Since:
- 2.0
-
-
Constructor Details
-
SQLServerTranslator
public SQLServerTranslator()Builds an SQLServerTranslator which always translates in SQL all identifiers (schema, table and column) in a case sensitive manner ; in other words, schema, table and column names will be surrounded by double quotes in the SQL translation. -
SQLServerTranslator
public SQLServerTranslator(boolean allCaseSensitive) Builds an SQLServerTranslator which always translates in SQL all identifiers (schema, table and column) in the specified case sensitivity ; in other words, schema, table and column names will all be surrounded or not by double quotes in the SQL translation.- Parameters:
allCaseSensitive
-true
to translate all identifiers in a case sensitive manner (surrounded by double quotes),false
for case insensitivity.
-
SQLServerTranslator
public SQLServerTranslator(boolean catalog, boolean schema, boolean table, boolean column) Builds an SQLServerTranslator which will always translate in SQL identifiers with the defined case sensitivity.- Parameters:
catalog
-true
to translate catalog names with double quotes (case sensitive in the DBMS),false
otherwise.schema
-true
to translate schema names with double quotes (case sensitive in the DBMS),false
otherwise.table
-true
to translate table names with double quotes (case sensitive in the DBMS),false
otherwise.column
-true
to translate column names with double quotes (case sensitive in the DBMS),false
otherwise.
-
-
Method Details
-
initSupportedFeatures
protected void initSupportedFeatures()Initialize the list of optional features supported by this translator.By default, all optional features are supported except the following:
- All geometric functions,
- ILIKE,
- and IN_UNIT
- Since:
- 2.0
-
getSupportedFeatures
Description copied from interface:ADQLTranslator
Get all features that are fully supported by this translator.Note: If NULL is returned, the default list of supported features should be used instead. This default list depends on the ADQL version and is set in an
ADQLParser
instance when no feature set is specified.- Returns:
- All features supported by this translator.
-
isCaseSensitive
Description copied from class:JDBCTranslator
Tell whether the specified identifier MUST be translated so that being interpreted case sensitively or not. By default, an identifier that must be translated with case sensitivity will be surrounded by double quotes. But, if this function returns FALSE, the SQL name will be written just as given in the metadata, without double quotes.
WARNING: An
IdentifierField
object can be a SCHEMA, TABLE, COLUMN and ALIAS. However, in this translator, aliases are translated like in ADQL (so, with the same case sensitivity specification as in ADQL). So, this function will never be used to know the case sensitivity to apply to an alias. It is then useless to write a special behavior for the ALIAS value.- Specified by:
isCaseSensitive
in classJDBCTranslator
- Parameters:
field
- The identifier whose the case sensitive to apply is asked.- Returns:
- true if the specified identifier must be translated case sensitivity, false otherwise (included if ALIAS or NULL).
-
translate
For SQL Server,translate(ClauseSelect)
must be overridden for LIMIT and OFFSET handling.Implementation note: If an OFFSET is specified, TOP can no longer be used to specify a limit in SQL. In such case, TOP is replaced by FETCH NEXT right after the OFFSET instruction. Besides, SQLServer requires an ORDER BY clause in order to use OFFSET. If none is given in the ADQL query, the default
ORDER BY 1 ASC
(i.e. sort on the first column) is applied.- Specified by:
translate
in interfaceADQLTranslator
- Overrides:
translate
in classJDBCTranslator
- Throws:
TranslationException
-
translate
- Specified by:
translate
in interfaceADQLTranslator
- Overrides:
translate
in classJDBCTranslator
- Throws:
TranslationException
-
translate
This version oftranslate(ClauseSelect)
lets translate the given SELECT clause with or without the TOP instruction in case a limit is specified in ADQL.- Parameters:
clause
- The SELECT clause to translate.topAllowed
- Iftrue
and a TOP limit is specified, it will be translated as a TOP in SQL (exactly as in ADQL). Iffalse
and a TOP limit is specified, it will never appear in the SQL translation. (in such case,translate(ADQLQuery)
will take care of this limit)- Throws:
TranslationException
- Since:
- 2.0
-
translate
Translate the given SELECT clause into an SQL compatible with MS-SQLServer.Note: The TOP limit, if any, will always be present in the SQL translation.
- Specified by:
translate
in interfaceADQLTranslator
- Overrides:
translate
in classJDBCTranslator
- Throws:
TranslationException
- See Also:
-
translate
- Specified by:
translate
in interfaceADQLTranslator
- Overrides:
translate
in classJDBCTranslator
- Throws:
TranslationException
-
translate
- Throws:
TranslationException
-
translate
- Specified by:
translate
in interfaceADQLTranslator
- Overrides:
translate
in classJDBCTranslator
- Throws:
TranslationException
-
translate
- Specified by:
translate
in interfaceADQLTranslator
- Overrides:
translate
in classJDBCTranslator
- Throws:
TranslationException
-
generateJoinColumn
protected ADQLColumn generateJoinColumn(FromContent table, DBColumn colMeta, ADQLColumn joinedColumn) Generate an ADQL column of the given table and with the given metadata.- Parameters:
table
- Parent table of the column to generate.colMeta
- DB metadata of the column to generate.joinedColumn
- The joined column (i.e. the ADQL column listed in a USING) from which the generated column should derive. If NULL, anADQLColumn
instance will be created from scratch using the ADQL name of the given DB metadata.- Returns:
- The generated column.
-
translate
- Throws:
TranslationException
-
translate
- Throws:
TranslationException
-
translate
- Throws:
TranslationException
-
translate
- Throws:
TranslationException
-
translate
- Throws:
TranslationException
-
translate
- Throws:
TranslationException
-
translate
- Throws:
TranslationException
-
translate
- Throws:
TranslationException
-
translate
- Throws:
TranslationException
-
translate
- Throws:
TranslationException
-
translate
- Throws:
TranslationException
-
translate
- Specified by:
translate
in interfaceADQLTranslator
- Overrides:
translate
in classJDBCTranslator
- Throws:
TranslationException
-
convertTypeFromDB
public DBType convertTypeFromDB(int dbmsType, String rawDbmsTypeName, String dbmsTypeName, String[] params) Description copied from class:JDBCTranslator
Convert any type provided by a JDBC driver into a type understandable by the ADQL/TAP library.- Specified by:
convertTypeFromDB
in classJDBCTranslator
- Parameters:
dbmsType
- Type returned by a JDBC driver. Note: this value is returned by ResultSetMetadata.getColumnType(int) and correspond to a type of java.sql.TypesrawDbmsTypeName
- Full name of the type returned by a JDBC driver. Note: this name is returned by ResultSetMetadata.getColumnTypeName(int) ; this name may contain parametersdbmsTypeName
- Name of type, without the eventual parameters. Note: this name is extracted from rawDbmsTypeName.params
- The eventual type parameters (e.g. char string length). Note: these parameters are extracted from rawDbmsTypeName.- Returns:
- The corresponding ADQL/TAP type or NULL if the specified type is unknown.
-
convertTypeToDB
Description copied from class:JDBCTranslator
Convert any type provided by the ADQL/TAP library into a type understandable by a JDBC driver.
Note: The returned DBMS type may contain some parameters between brackets.
- Specified by:
convertTypeToDB
in classJDBCTranslator
- Parameters:
type
- The ADQL/TAP library's type to convert.- Returns:
- The corresponding DBMS type or NULL if the specified type is unknown.
-
translateGeometryFromDB
Description copied from class:JDBCTranslator
Parse the given JDBC column value as a geometry object and convert it into a
Region
.Note: Generally the returned object will be used to get its STC-S expression.
Note: If the given column value is NULL, NULL will be returned.
Important note: This function is called ONLY for value of columns flagged as geometries by
JDBCTranslator.convertTypeFromDB(int, String, String, String[])
. So the value should always be of the expected type and format. However, if it turns out that the type is wrong and that the conversion is finally impossible, this function SHOULD throw aParseException
.- Specified by:
translateGeometryFromDB
in classJDBCTranslator
- Parameters:
jdbcColValue
- A JDBC column value (returned by ResultSet.getObject(int)).- Returns:
- The corresponding
Region
if the given value is a geometry. - Throws:
ParseException
- If the given object is not a geometrical object or can not be transformed into aRegion
object.
-
translateGeometryToDB
Description copied from class:JDBCTranslator
Convert the given STC region into a DB column value.
Note: This function is used only by the UPLOAD feature, to import geometries provided as STC-S expression in a VOTable document inside a DB column.
Note: If the given region is NULL, NULL will be returned.
- Specified by:
translateGeometryToDB
in classJDBCTranslator
- Parameters:
region
- The region to store in the DB.- Returns:
- The corresponding DB column object.
- Throws:
ParseException
- If the given STC Region can not be converted into a DB object.
-