Class Postgres<G>


public final class Postgres<G> extends Database<G>
Information about a connection to a PostgreSQL + PostGIS database. This class specializes some of the functions for converting PostGIS objects to Java objects. The PostGIS database is optional; it is possible to use PostgreSQL alone as a store of features without geometries.
Since:
1.1
Version:
1.2
Author:
Alexis Manin (Geomatys), Martin Desruisseaux (Geomatys)
  • Constructor Details

    • Postgres

      public Postgres(DataSource source, Connection connection, DatabaseMetaData metadata, Geometries<G> geomLibrary, StoreListeners listeners) throws SQLException
      Creates a new session for a PostGIS database.
      Parameters:
      source - provider of (pooled) connections to the database.
      connection - the connection to the database. Should be considered as read-only.
      metadata - metadata about the database for which a session is created.
      geomLibrary - the factory to use for creating geometric objects.
      listeners - where to send warnings.
      Throws:
      SQLException - if an error occurred while reading database metadata.
  • Method Details

    • getMapping

      public ValueGetter<?> getMapping(Column columnDefinition)
      Returns a function for getting values from a column having the given definition. The given definition should include data SQL type and type name. If no match is found, then this method returns null.
      Overrides:
      getMapping in class Database<G>
      Parameters:
      columnDefinition - information about the column to extract values from and expose through Java API.
      Returns:
      converter to the corresponding java type, or null if this class cannot find a mapping.
    • getArrayComponentType

      protected int getArrayComponentType(Column columnDefinition)
      Returns the type of components in SQL arrays stored in a column. This method is invoked when
      invalid reference
      #type
      = Types.ARRAY.
      Overrides:
      getArrayComponentType in class Database<G>
      Parameters:
      columnDefinition - information about the column to extract array component type.
      Returns:
      one of Types constants.
      See Also:
    • getDefaultMapping

      protected ValueGetter<Object> getDefaultMapping()
      Returns the mapping for Object or unrecognized types.
      Overrides:
      getDefaultMapping in class Database<G>
      Returns:
      the default mapping for unknown or unrecognized types.
    • getBinaryEncoding

      protected BinaryEncoding getBinaryEncoding(Column columnDefinition)
      Returns an identifier of the way binary data are encoded by the JDBC driver. Data stored as PostgreSQL BYTEA type are encoded in hexadecimal.
      Overrides:
      getBinaryEncoding in class Database<G>
      Parameters:
      columnDefinition - information about the column to extract binary values from.
      Returns:
      how the binary data are returned by the JDBC driver.
    • createInfoStatements

      protected InfoStatements createInfoStatements(Connection connection)
      Prepares a cache of statements about spatial information using the given connection. Statements will be created only when first needed.
      Overrides:
      createInfoStatements in class Database<G>
      Parameters:
      connection - the connection to use for creating statements.
      Returns:
      a cache of prepared statements about spatial information.
    • addIgnoredTables

      protected void addIgnoredTables(Map<String,Boolean> ignoredTables)
      Adds to the given set a list of tables to ignore when searching for feature tables.
      Overrides:
      addIgnoredTables in class Database<G>
      Parameters:
      ignoredTables - where to add names of tables to ignore.
    • getFilterToSQL

      protected SelectionClauseWriter getFilterToSQL()
      Returns the converter from filters/expressions to the WHERE part of SQL statement.
      Overrides:
      getFilterToSQL in class Database<G>
      Returns:
      the converter from filters/expressions to the WHERE part of SQL statement.
    • getEstimatedExtent

      protected org.opengis.geometry.Envelope getEstimatedExtent(TableReference table, Column[] columns, boolean recall) throws SQLException
      Computes an estimation of the envelope of all geometry columns using PostgreSQL statistics if available. Uses the PostGIS ST_EstimatedExtent(…) function to get a rough estimation of column extent. This method is invoked only if the columns array contains at least one geometry column.
      Overrides:
      getEstimatedExtent in class Database<G>
      Parameters:
      table - the table for which to compute an estimation of the envelope.
      columns - all columns in the table (including non-geometry columns). This is a reference to an internal array; do not modify.
      recall - if it is at least the second time that this method is invoked for the specified table.
      Returns:
      an estimation of the spatiotemporal resource extent, or null if none.
      Throws:
      SQLException - if an error occurred while fetching the envelope.
      See Also: