Class InfoStatements

java.lang.Object
org.apache.sis.internal.sql.feature.InfoStatements
All Implemented Interfaces:
AutoCloseable, Localized

public class InfoStatements extends Object implements Localized, AutoCloseable
A set of prepared statements to create when first needed and to reuse as long as the connection is in scope. The prepared statement tasks include:
  • Searching for geometric information using SQL queries specialized for Simple Feature table.
  • Fetching a Coordinate Reference System (CRS) from a SRID.
  • Finding a SRID from a Coordinate Reference System (CRS).
This class is not thread-safe. Each instance should be used in a single thread. Instances are created by Database.createInfoStatements(Connection).
Since:
1.2
Version:
1.1
Author:
Alexis Manin (Geomatys), Martin Desruisseaux (Geomatys)
See Also:
  • Field Details

    • geometryColumns

      protected PreparedStatement geometryColumns
      A statement for fetching geometric information for a specific column.
  • Constructor Details

    • InfoStatements

      protected InfoStatements(Database<?> database, Connection connection)
      Creates an initially empty CachedStatements which will use the given connection for creating PreparedStatements.
      Parameters:
      database - information about the spatial database.
      connection - connection to use for creating the prepared statements.
  • Method Details

    • getLocale

      public final Locale getLocale()
      Returns the locale used for warnings and error messages.
      Specified by:
      getLocale in interface Localized
      Returns:
      the locale, or null if not explicitly defined.
    • getComponentMapping

      public final ValueGetter<?> getComponentMapping(Array array) throws SQLException
      Returns a function for getting values of components in the given array. If no match is found, then this method returns null.
      Parameters:
      array - the array from which to get the mapping of component values.
      Returns:
      converter to the corresponding java type, or null if this class cannot find a mapping.
      Throws:
      SQLException - if the mapping cannot be obtained.
    • prepareIntrospectionStatement

      protected final PreparedStatement prepareIntrospectionStatement(String table, char prefix, String column, String otherColumn) throws SQLException
      Prepares the statement for fetching information about all geometry or raster columns in a specified table. This method is for completeIntrospection(TableReference, Map) implementations.
      Parameters:
      table - name of the geometry table. Standard value is "GEOMETRY_COLUMNS".
      prefix - column name prefix: 'F' for features or 'R' for rasters.
      column - name of the geometry column without prefix. Standard value is "GEOMETRY_COLUMN".
      otherColumn - additional columns or null if none. Standard value is "GEOMETRY_TYPE".
      Returns:
      the prepared statement for querying the geometry table.
      Throws:
      SQLException - if the statement cannot be created.
    • completeIntrospection

      public void completeIntrospection(TableReference source, Map<String,Column> columns) throws Exception
      Gets all geometry and raster columns for the given table and sets information on the corresponding columns. Column instances in the columns map are modified in-place (the map itself is not modified). This method should be invoked before the Column.valueGetter field is set.
      Parameters:
      source - the table for which to get all geometry columns.
      columns - all columns for the specified table. Keys are column names.
      Throws:
      DataStoreContentException - if a logical error occurred in processing data.
      ParseException - if the WKT cannot be parsed.
      SQLException - if a SQL error occurred.
      Exception
    • configureSpatialColumns

      protected final void configureSpatialColumns(PreparedStatement columnQuery, TableReference source, Map<String,Column> columns, InfoStatements.GeometryTypeEncoding typeValueKind) throws Exception
      Implementation of completeIntrospection(TableReference, Map) for geometries, as a separated methods for allowing sub-classes to override above-cited method. May also be used for non-geometric columns such as rasters, in which case the typeValueKind argument shall be null.
      Parameters:
      columnQuery - a statement prepared by prepareIntrospectionStatement(String, char, String, String).
      source - the table for which to get all geometry columns.
      columns - all columns for the specified table. Keys are column names.
      typeValueKind - NUMERIC, TEXTUAL or null if none.
      Throws:
      DataStoreContentException - if a logical error occurred in processing data.
      ParseException - if the WKT cannot be parsed.
      SQLException - if a SQL error occurred.
      Exception
    • fetchCRS

      public final org.opengis.referencing.crs.CoordinateReferenceSystem fetchCRS(int srid) throws Exception
      Gets a Coordinate Reference System for to given SRID. If the given SRID is zero or negative, then this method returns null. Otherwise the CRS is decoded from the database "SPATIAL_REF_SYS" table.
      Parameters:
      srid - the Spatial Reference Identifier (SRID) to resolve as a CRS object.
      Returns:
      the CRS associated to the given SRID, or null if the SRID is zero.
      Throws:
      DataStoreContentException - if the CRS cannot be fetched. Possible reasons are: no entry found in the "SPATIAL_REF_SYS" table, or more than one entry is found, or a single entry exists but has no WKT definition and its authority code is unsupported by SIS.
      ParseException - if the WKT cannot be parsed.
      SQLException - if a SQL error occurred.
      Exception
    • findSRID

      public final int findSRID(org.opengis.referencing.crs.CoordinateReferenceSystem crs) throws Exception
      Finds a SRID code from the spatial reference systems table for the given CRS.
      Parameters:
      crs - the CRS for which to find a SRID, or null.
      Returns:
      SRID for the given CRS, or 0 if the given CRS was null.
      Throws:
      Exception - if an SQL error, parsing error or other error occurred.
    • close

      public void close() throws SQLException
      Closes all prepared statements. This method does not close the connection.
      Specified by:
      close in interface AutoCloseable
      Throws:
      SQLException - if an error occurred while closing a connection.