Package adql.translator

## Class SQLServerTranslator

- java.lang.Object
- - adql.translator.JDBCTranslator
  - - adql.translator.SQLServerTranslator

- All Implemented Interfaces:
    `ADQLTranslator`

      public class SQLServerTranslator
      extends JDBCTranslator

  MS SQL Server translator.

  Important: This translator works correctly ONLY IF `SQLServer_ADQLQueryFactory` has been used to create any ADQL query this translator is asked to translate.

  TODO See how case sensitivity is supported by MS SQL Server and modify this translator accordingly. TODO Extend this class for each MS SQL Server extension supporting geometry and particularly `translateGeometryFromDB(Object)`, `translateGeometryToDB(adql.db.STCS.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: Geometrical functions are not translated ; the translation returned for them is their ADQL expression.

  Since:
    1.4
  Version:
    1.5 (03/2019)
  Author:
    Grégory Mantelet (ARI;CDS)
  See Also:
    `SQLServer_ADQLQueryFactory`

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected byte` | `caseSensitivity` | Indicate the case sensitivity to apply to each SQL identifier (only SCHEMA, TABLE and COLUMN).

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `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​(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

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `DBType` | `convertTypeFromDB​(int dbmsType, java.lang.String rawDbmsTypeName, java.lang.String dbmsTypeName, java.lang.String[] params)` | Convert any type provided by a JDBC driver into a type understandable by the ADQL/TAP library.
    `java.lang.String` | `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.
    `boolean` | `isCaseSensitive​(IdentifierField field)` | Tell whether the specified identifier MUST be translated so that being interpreted case sensitively or not.
    `java.lang.String` | `translate​(ADQLQuery query)` | For SQL Server, `translate(ClauseSelect)` must be overridden for TOP/LIMIT handling.
    `java.lang.String` | `translate​(ClauseSelect clause)` |
    `java.lang.String` | `translate​(ADQLJoin join)` |
    `java.lang.String` | `translate​(Concatenation concat)` |
    `java.lang.String` | `translate​(AreaFunction areaFunction)` |
    `java.lang.String` | `translate​(BoxFunction box)` |
    `java.lang.String` | `translate​(CentroidFunction centroidFunction)` |
    `java.lang.String` | `translate​(CircleFunction circle)` |
    `java.lang.String` | `translate​(ContainsFunction fct)` |
    `java.lang.String` | `translate​(DistanceFunction fct)` |
    `java.lang.String` | `translate​(ExtractCoord extractCoord)` |
    `java.lang.String` | `translate​(ExtractCoordSys extractCoordSys)` |
    `java.lang.String` | `translate​(IntersectsFunction fct)` |
    `java.lang.String` | `translate​(PointFunction point)` |
    `java.lang.String` | `translate​(PolygonFunction polygon)` |
    `java.lang.String` | `translate​(RegionFunction region)` |
    `java.lang.String` | `translate​(MathFunction fct)` |
    `STCS.Region` | `translateGeometryFromDB​(java.lang.Object jdbcColValue)` | Parse the given JDBC column value as a geometry object and convert it into a `STCS.Region`.
    `java.lang.Object` | `translateGeometryToDB​(STCS.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, 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`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### caseSensitivity

          protected byte caseSensitivity

      Indicate 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.

  - ### Constructor Detail

    - #### 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 Detail

    - #### isCaseSensitive

          public boolean isCaseSensitive​(IdentifierField field)

      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 class `JDBCTranslator`
      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

          public java.lang.String translate​(ADQLQuery query)
                                     throws TranslationException

      For SQL Server, `translate(ClauseSelect)` must be overridden for TOP/LIMIT handling. We must not add the LIMIT at the end of the query, it must go in the SELECT.
      Specified by:
        `translate` in interface `ADQLTranslator`
      Overrides:
        `translate` in class `JDBCTranslator`
      Throws:
        `TranslationException`
      See Also:
        `translate(ClauseSelect)`

    - #### translate

          public java.lang.String translate​(ClauseSelect clause)
                                     throws TranslationException

      Specified by:
        `translate` in interface `ADQLTranslator`
      Overrides:
        `translate` in class `JDBCTranslator`
      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(Concatenation concat)
                                     throws TranslationException

      Specified by:
        `translate` in interface `ADQLTranslator`
      Overrides:
        `translate` in class `JDBCTranslator`
      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(ADQLJoin join)
                                     throws TranslationException

      Specified by:
        `translate` in interface `ADQLTranslator`
      Overrides:
        `translate` in class `JDBCTranslator`
      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, an `ADQLColumn` instance will be created from scratch using the ADQL name of the given DB metadata.
      Returns:
        The generated column.

    - #### translate

          public java.lang.String translate​(ExtractCoord extractCoord)
                                     throws TranslationException

      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(ExtractCoordSys extractCoordSys)
                                     throws TranslationException

      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(AreaFunction areaFunction)
                                     throws TranslationException

      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(CentroidFunction centroidFunction)
                                     throws TranslationException

      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(DistanceFunction fct)
                                     throws TranslationException

      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(ContainsFunction fct)
                                     throws TranslationException

      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(IntersectsFunction fct)
                                     throws TranslationException

      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(PointFunction point)
                                     throws TranslationException

      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(CircleFunction circle)
                                     throws TranslationException

      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(BoxFunction box)
                                     throws TranslationException

      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(PolygonFunction polygon)
                                     throws TranslationException

      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(RegionFunction region)
                                     throws TranslationException

      Throws:
        `TranslationException`

    - #### translate

          public java.lang.String translate​(MathFunction fct)
                                     throws TranslationException

      Specified by:
        `translate` in interface `ADQLTranslator`
      Overrides:
        `translate` in class `JDBCTranslator`
      Throws:
        `TranslationException`

    - #### convertTypeFromDB

          public DBType convertTypeFromDB​(int dbmsType,
                                          java.lang.String rawDbmsTypeName,
                                          java.lang.String dbmsTypeName,
                                          java.lang.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 class `JDBCTranslator`
      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.Types
        `rawDbmsTypeName` - Full name of the type returned by a JDBC driver. Note: this name is returned by ResultSetMetadata.getColumnTypeName(int) ; this name may contain parameters
        `dbmsTypeName` - 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

          public java.lang.String convertTypeToDB​(DBType type)

      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 class `JDBCTranslator`
      Parameters:
        `type` - The ADQL/TAP library's type to convert.
      Returns:
        The corresponding DBMS type or NULL if the specified type is unknown.

    - #### translateGeometryFromDB

          public STCS.Region translateGeometryFromDB​(java.lang.Object jdbcColValue)
                                              throws ParseException

      Description copied from class: `JDBCTranslator`

      Parse the given JDBC column value as a geometry object and convert it into a `STCS.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 a `ParseException`.

      Specified by:
        `translateGeometryFromDB` in class `JDBCTranslator`
      Parameters:
        `jdbcColValue` - A JDBC column value (returned by ResultSet.getObject(int)).
      Returns:
        The corresponding `STCS.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 a `STCS.Region` object.

    - #### translateGeometryToDB

          public java.lang.Object translateGeometryToDB​(STCS.Region region)
                                                 throws ParseException

      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 class `JDBCTranslator`
      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.