uk.ac.starlink.table.jdbc

## Class TypeMappers

- java.lang.Object
- - uk.ac.starlink.table.jdbc.TypeMappers

-     public class TypeMappers
      extends java.lang.Object

  TypeMapper implementation classes.
  Since:
    2 Feb 2010

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static TypeMapper` | `DALI` TypeMapper implementation like `STANDARD`, but which uses a 'T' character as the separator between the date and time parts of timestamp serializations.
    `static TypeMapper` | `IDENTITY` TypeMapper implementation which performs no conversions.
    `static TypeMapper` | `STANDARD` TypeMapper implementation which performs generally useful conversions.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <T> ValueHandler` | `createArrayValueHandler(java.sql.ResultSetMetaData meta, int jcol1, java.lang.Class<T> arrayClazz)` Constructs a new ValueHandler which converts JDBC Array values to java array objects of a specific type.
    `static ValueHandler` | `createIdentityValueHandler(java.sql.ResultSetMetaData meta, int jcol1)` Constructs a new ValueHandler which performs no conversions.
    `static ValueHandler` | `createStringValueHandler(java.sql.ResultSetMetaData meta, int jcol1)` Constructs a new ValueHandler which converts values to Strings.
    `static ValueHandler` | `createTimestampValueHandler(java.sql.ResultSetMetaData meta, int jcol1, char dateTimeSeparator)` Constructs a new ValueHandler which converts JDBC Timestamp values to Strings, with a configurable date/time separator character.
    `static java.lang.Class<?>` | `getArrayClass(java.sql.ResultSetMetaData meta, int jcol1)` Tries to guess a suitable output value type for an array-valued column in a ResultSet.

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

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

- - ### Field Detail

    - #### STANDARD

          public static final TypeMapper STANDARD

      TypeMapper implementation which performs generally useful conversions. In particular, `Date` subclasses (including `java.sql.Date`, `java.sql.Time` and `java.sql.Timestamp` are turned into Strings, using JDBC timestamp escape format (which is ISO-8601 with a space character separating date and time). The intention is that by using this implementation you will get an output table which can be written using non-specialist output formats such as FITS and VOTable.

    - #### DALI

          public static final TypeMapper DALI

      TypeMapper implementation like `STANDARD`, but which uses a 'T' character as the separator between the date and time parts of timestamp serializations. Use of the 'T' separator is mandated by the Data Access Layer Interface standard v1.0, section 3.1.2 (http://www.ivoa.net/documents/DALI/), and so is appropriate for output from VO services such as TAP.

    - #### IDENTITY

          public static final TypeMapper IDENTITY

      TypeMapper implementation which performs no conversions. The output types are just as JDBC provides them.

  - ### Method Detail

    - #### createIdentityValueHandler

          public static ValueHandler createIdentityValueHandler(java.sql.ResultSetMetaData meta,
                                                                int jcol1)
                                                         throws java.sql.SQLException

      Constructs a new ValueHandler which performs no conversions.
      Parameters:
        `meta` - JDBC metadata object
        `jcol1` - JDBC column index (first column is 1)
      Throws:
        `java.sql.SQLException`

    - #### createStringValueHandler

          public static ValueHandler createStringValueHandler(java.sql.ResultSetMetaData meta,
                                                              int jcol1)
                                                       throws java.sql.SQLException

      Constructs a new ValueHandler which converts values to Strings.
      Parameters:
        `meta` - JDBC metadata object
        `jcol1` - JDBC column index (first column is 1)
      Throws:
        `java.sql.SQLException`

    - #### createTimestampValueHandler

          public static ValueHandler createTimestampValueHandler(java.sql.ResultSetMetaData meta,
                                                                 int jcol1,
                                                                 char dateTimeSeparator)
                                                          throws java.sql.SQLException

      Constructs a new ValueHandler which converts JDBC Timestamp values to Strings, with a configurable date/time separator character. The input values are assumed to be of type `Timestamp`.
      Parameters:
        `meta` - JDBC metadata object
        `jcol1` - JDBC column index (first column is 1)
        `dateTimeSeparator` - separator character between date and time parts of ISO-8601 string; usually either ' ' or 'T'
      Throws:
        `java.sql.SQLException`

    - #### createArrayValueHandler

          public static <T> ValueHandler createArrayValueHandler(java.sql.ResultSetMetaData meta,
                                                                 int jcol1,
                                                                 java.lang.Class<T> arrayClazz)
                                                          throws java.sql.SQLException

      Constructs a new ValueHandler which converts JDBC Array values to java array objects of a specific type. This is suitable when `ResultSetMetaData.getColumnClassName(int)` returns "`java.sql.Array`".

      The required output class `arrayClazz` must be specified explicitly. If this class not a good match for the payload of the `Array` values, value conversion won't work very well. The method `getArrayClass` can be used to guess a good value for this parameter.

      Parameters:
        `meta` - JDBC metadata object
        `jcol1` - JDBC column index (first column is 1)
        `arrayClazz` - required output type
      Throws:
        `java.sql.SQLException`

    - #### getArrayClass

          public static java.lang.Class<?> getArrayClass(java.sql.ResultSetMetaData meta,
                                                         int jcol1)

      Tries to guess a suitable output value type for an array-valued column in a ResultSet. The returned type will be STIL-friendly, that is a String[] or primitive type array. If the type is not recognised, null is returned.
      Parameters:
        `meta` - JDBC metadata object
        `jcol1` - JDBC column index (first column is 1)
      Returns:
        best-efforts guess at output array type, or null