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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Version
Version of PostGIS extension, ornull
if PostGIS has not been found. -
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 void
addIgnoredTables
(Map<String, Boolean> ignoredTables) Adds to the given set a list of tables to ignore when searching for feature tables.protected InfoStatements
createInfoStatements
(Connection connection) Prepares a cache of statements about spatial information using the given connection.protected int
getArrayComponentType
(Column columnDefinition) Returns the type of components in SQL arrays stored in a column.protected BinaryEncoding
getBinaryEncoding
(Column columnDefinition) Returns an identifier of the way binary data are encoded by the JDBC driver.protected ValueGetter
<Object> Returns the mapping forObject
or unrecognized types.protected org.opengis.geometry.Envelope
getEstimatedExtent
(TableReference table, Column[] columns, boolean recall) Computes an estimation of the envelope of all geometry columns using PostgreSQL statistics if available.protected SelectionClauseWriter
Returns the converter from filters/expressions to theWHERE
part of SQL statement.ValueGetter
<?> getMapping
(Column columnDefinition) Returns a function for getting values from a column having the given definition.(package private) static Version
parseVersion
(String version) Returns the version number of PostGIS extension.Methods inherited from class org.apache.sis.internal.sql.feature.Database
appendFunctionCall, create, findTable, forGeometry, hasGeometry, hasRaster, isSpatial, listTables, log, tables, toString
-
Field Details
-
postgisVersion
Version of PostGIS extension, ornull
if PostGIS has not been found. Not to be confused with the version of PostgreSQL server, which is given by another class provided in the PostgreSQL JDBC driver.- See Also:
-
-
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
-
parseVersion
Returns the version number of PostGIS extension. PostGIS version query returns a detailed text starting with its numerical version. Example of a PostGIS version string:3.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
. The version is assumed at the beginning of the string and terminated by a space. In the future, we could also parse other information in the version text.- Parameters:
version
- the text starting with a semantic version, ornull
.- Returns:
- major version number, or
null
if cannot be parsed.
-
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:
getMapping
in 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
null
if this class cannot find a mapping.
-
getArrayComponentType
Returns the type of components in SQL arrays stored in a column. This method is invoked wheninvalid reference
#type
Types.ARRAY
.- Overrides:
getArrayComponentType
in classDatabase<G>
- Parameters:
columnDefinition
- information about the column to extract array component type.- Returns:
- one of
Types
constants. - See Also:
-
getDefaultMapping
Returns the mapping forObject
or unrecognized types.- Overrides:
getDefaultMapping
in 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 PostgreSQLBYTEA
type are encoded in hexadecimal.- Overrides:
getBinaryEncoding
in 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:
createInfoStatements
in 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:
addIgnoredTables
in classDatabase<G>
- Parameters:
ignoredTables
- where to add names of tables to ignore.
-
getFilterToSQL
Returns the converter from filters/expressions to theWHERE
part of SQL statement.- Overrides:
getFilterToSQL
in classDatabase<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 PostGISST_EstimatedExtent(…)
function to get a rough estimation of column extent. This method is invoked only if thecolumns
array contains at least one geometry column.- Overrides:
getEstimatedExtent
in 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
null
if none. - Throws:
SQLException
- if an error occurred while fetching the envelope.- See Also:
-