Class Column

java.lang.Object
org.apache.sis.internal.sql.feature.Column

public final class Column extends Object
Information (name, data type…) about a table column. It contains information extracted from database metadata, possibly completed with information about a geometry column. The aim is to describe all information about a column that is needed for mapping to feature model.

Multi-threading

Column instances shall be kept unmodified after all fields have been initialized. The same instances may be read concurrently by many threads.
Since:
1.1
Version:
1.2
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private org.opengis.referencing.crs.CoordinateReferenceSystem
    If this column is a geometry or raster column, the Coordinate Reference System (CRS).
    private GeometryType
    If this column is a geometry column, the type of the geometry objects.
    final boolean
    Whether the column can have null values.
    final String
    Title to use for displays.
    final String
    Name of the column.
    private final int
    The column size, or 0 if not applicable.
    (package private) String
    Name to use for feature property.
    final int
    Type of values as one of the constants enumerated in Types class.
    final String
    A name for the value type, free-text from the database engine.
    (package private) ValueGetter<?>
    Converter from ResultSet column value to value stored in the feature instance.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Column(int type, String typeName)
    Creates a synthetic column (a column not inferred from database analysis) for describing the type of elements in an array.
    Column(ResultSetMetaData metadata, int column, String quote)
    Creates a new column from the result of a query.
    Column(Analyzer analyzer, ResultSet metadata, String quote)
    Creates a new column from database metadata.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) final AttributeTypeBuilder<?>
    Creates a feature attribute for this column.
    final Optional<org.opengis.referencing.crs.CoordinateReferenceSystem>
    If this column is a geometry or raster column, returns the default coordinate reference system.
    If this column is a geometry column, returns the type of the geometry objects.
    private static String
    localPart(String type, String quote)
    PostgreSQL JDBC drivers sometimes gives the fully qualified type name.
    (package private) final void
    makeSpatial(Localized caller, GeometryType type, org.opengis.referencing.crs.CoordinateReferenceSystem crs)
    Modifies this column for declaring it as a geometry or raster column.
    Returns a string representation for debugging purposes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • name

      public final String name
      Name of the column.
      See Also:
    • label

      public final String label
      Title to use for displays. This is the name specified by the AS keyword in a SELECT clause. This is never null but may be identical to name if no label was specified.
    • propertyName

      String propertyName
      Name to use for feature property. This is the same as label unless there is a name collision. In that case the property name is modified for avoiding the collision.
    • type

      public final int type
      Type of values as one of the constants enumerated in Types class.
      See Also:
    • typeName

      public final String typeName
      A name for the value type, free-text from the database engine. For more information about this, see DatabaseMetaData.getColumns(String, String, String, String) and Reflection.TYPE_NAME. This value shall not be null.
      See Also:
    • precision

      private final int precision
      The column size, or 0 if not applicable. For texts, this is the maximum number of characters allowed. For numbers, this is the maximum number of digits. For blobs, this is a limit in number of bytes.
      See Also:
    • isNullable

      public final boolean isNullable
      Whether the column can have null values.
      See Also:
    • geometryType

      private GeometryType geometryType
      If this column is a geometry column, the type of the geometry objects. Otherwise null.
      See Also:
    • defaultCRS

      private org.opengis.referencing.crs.CoordinateReferenceSystem defaultCRS
      If this column is a geometry or raster column, the Coordinate Reference System (CRS). Otherwise null. This is determined from the geometry Spatial Reference Identifier (SRID).
      See Also:
    • valueGetter

      ValueGetter<?> valueGetter
      Converter from ResultSet column value to value stored in the feature instance. It will typically delegate to the ResultSet getter method for the column type, but may also perform some conversions such as parsing geometry Well-Known Binary (WKB).
  • Constructor Details

    • Column

      Column(int type, String typeName)
      Creates a synthetic column (a column not inferred from database analysis) for describing the type of elements in an array.
      Parameters:
      type - SQL type of the column.
      typeName - SQL name of the type.
    • Column

      Column(Analyzer analyzer, ResultSet metadata, String quote) throws SQLException
      Creates a new column from database metadata. Information are fetched from current ResultSet row. This method does not change cursor position.
      Parameters:
      analyzer - the analyzer which is creating this column.
      metadata - the result of DatabaseMetaData.getColumns(…).
      quote - value of DatabaseMetaData.getIdentifierQuoteString().
      Throws:
      SQLException - if an error occurred while fetching metadata.
      See Also:
    • Column

      Column(ResultSetMetaData metadata, int column, String quote) throws SQLException
      Creates a new column from the result of a query.
      Parameters:
      metadata - value of ResultSet.getMetaData().
      column - index of the column for which to get metadata.
      quote - value of DatabaseMetaData.getIdentifierQuoteString().
      Throws:
      SQLException - if an error occurred while fetching metadata.
      See Also:
  • Method Details

    • localPart

      private static String localPart(String type, String quote) throws SQLDataException
      PostgreSQL JDBC drivers sometimes gives the fully qualified type name. For example, we sometimes get "public"."geometry" (including the quotes) instead of a plain geometry. If this is the case, keep only the local part.
      Parameters:
      type - value found in the @value Reflection#TYPE_NAME} column.
      quote - value of DatabaseMetaData.getIdentifierQuoteString().
      Returns:
      local part of the type name.
      Throws:
      SQLDataException
    • makeSpatial

      final void makeSpatial(Localized caller, GeometryType type, org.opengis.referencing.crs.CoordinateReferenceSystem crs) throws DataStoreContentException
      Modifies this column for declaring it as a geometry or raster column. This method is invoked during inspection of the "GEOMETRY_COLUMNS" table of a spatial database. It can also be invoked during the inspection of "GEOGRAPHY_COLUMNS" or "RASTER_COLUMNS" tables, which are PostGIS extensions. In the raster case, the geometry type argument shall be null.
      Parameters:
      caller - provider of the locale for error message, if any.
      type - the type of values in the column, or null if not geometric.
      crs - the Coordinate Reference System (CRS), or null if unknown.
      Throws:
      DataStoreContentException
    • getGeometryType

      public final Optional<GeometryType> getGeometryType()
      If this column is a geometry column, returns the type of the geometry objects. Otherwise returns empty (including the case where this is a raster column). Note that if this column is a geometry column but the geometry type was not defined, then GeometryType.GEOMETRY is returned as a fallback.
      Returns:
      type of geometry objects, or empty if this column is not a geometry column.
    • getDefaultCRS

      public final Optional<org.opengis.referencing.crs.CoordinateReferenceSystem> getDefaultCRS()
      If this column is a geometry or raster column, returns the default coordinate reference system. Otherwise returns empty. The CRS may also be empty even for a geometry column if it is unspecified.
      Returns:
      CRS of geometries or rasters in this column, or empty if unknown or not applicable.
    • createAttribute

      final AttributeTypeBuilder<?> createAttribute(FeatureTypeBuilder feature)
      Creates a feature attribute for this column. The attribute is appended to the given feature builder. The attribute builder is returned for allowing additional configuration.
      Parameters:
      feature - the feature where to append an attribute for this column.
      Returns:
      builder for the added feature attribute.
    • toString

      public String toString()
      Returns a string representation for debugging purposes.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this column.