Class Postgres<G>
java.lang.Object
org.apache.sis.internal.metadata.sql.Syntax
org.apache.sis.internal.sql.feature.Database<G>
org.apache.sis.internal.sql.postgis.Postgres<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)
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionPostgres(DataSource source, Connection connection, DatabaseMetaData metadata, Geometries<G> geomLibrary, StoreListeners listeners) Creates a new session for a PostGIS database. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddIgnoredTables(Map<String, Boolean> ignoredTables) Adds to the given set a list of tables to ignore when searching for feature tables.protected InfoStatementscreateInfoStatements(Connection connection) Prepares a cache of statements about spatial information using the given connection.protected intgetArrayComponentType(Column columnDefinition) Returns the type of components in SQL arrays stored in a column.protected BinaryEncodinggetBinaryEncoding(Column columnDefinition) Returns an identifier of the way binary data are encoded by the JDBC driver.protected ValueGetter<Object> Returns the mapping forObjector unrecognized types.protected org.opengis.geometry.EnvelopegetEstimatedExtent(TableReference table, Column[] columns, boolean recall) Computes an estimation of the envelope of all geometry columns using PostgreSQL statistics if available.protected SelectionClauseWriterReturns the converter from filters/expressions to theWHEREpart of SQL statement.ValueGetter<?> getMapping(Column columnDefinition) Returns a function for getting values from a column having the given definition.Methods inherited from class org.apache.sis.internal.sql.feature.Database
appendFunctionCall, create, findTable, forGeometry, hasGeometry, hasRaster, isSpatial, listTables, log, tables, toString
-
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
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 returnsnull.- Overrides:
getMappingin classDatabase<G>- Parameters:
columnDefinition- information about the column to extract values from and expose through Java API.- Returns:
- converter to the corresponding java type, or
nullif this class cannot find a mapping.
-
getArrayComponentType
Returns the type of components in SQL arrays stored in a column. This method is invoked when=invalid reference
#typeTypes.ARRAY.- Overrides:
getArrayComponentTypein classDatabase<G>- Parameters:
columnDefinition- information about the column to extract array component type.- Returns:
- one of
Typesconstants. - See Also:
-
getDefaultMapping
Returns the mapping forObjector unrecognized types.- Overrides:
getDefaultMappingin classDatabase<G>- Returns:
- the default mapping for unknown or unrecognized types.
-
getBinaryEncoding
Returns an identifier of the way binary data are encoded by the JDBC driver. Data stored as PostgreSQLBYTEAtype are encoded in hexadecimal.- Overrides:
getBinaryEncodingin classDatabase<G>- Parameters:
columnDefinition- information about the column to extract binary values from.- Returns:
- how the binary data are returned by the JDBC driver.
-
createInfoStatements
Prepares a cache of statements about spatial information using the given connection. Statements will be created only when first needed.- Overrides:
createInfoStatementsin classDatabase<G>- Parameters:
connection- the connection to use for creating statements.- Returns:
- a cache of prepared statements about spatial information.
-
addIgnoredTables
Adds to the given set a list of tables to ignore when searching for feature tables.- Overrides:
addIgnoredTablesin classDatabase<G>- Parameters:
ignoredTables- where to add names of tables to ignore.
-
getFilterToSQL
Returns the converter from filters/expressions to theWHEREpart of SQL statement.- Overrides:
getFilterToSQLin classDatabase<G>- Returns:
- the converter from filters/expressions to the
WHEREpart 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 PostGISST_EstimatedExtent(…)function to get a rough estimation of column extent. This method is invoked only if thecolumnsarray contains at least one geometry column.- Overrides:
getEstimatedExtentin classDatabase<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
nullif none. - Throws:
SQLException- if an error occurred while fetching the envelope.- See Also:
-