Class InfoStatements
java.lang.Object
org.apache.sis.internal.sql.feature.InfoStatements
- All Implemented Interfaces:
AutoCloseable,Localized
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).
Database.createInfoStatements(Connection).- Since:
- 1.2
- Version:
- 1.1
- Author:
- Alexis Manin (Geomatys), Martin Desruisseaux (Geomatys)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumSpecifies how the geometry type is encoded in the"GEOMETRY_TYPE"column. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PreparedStatementA statement for fetching geometric information for a specific column. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInfoStatements(Database<?> database, Connection connection) Creates an initially emptyCachedStatementswhich will use the given connection for creatingPreparedStatements. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes all prepared statements.voidcompleteIntrospection(TableReference source, Map<String, Column> columns) Gets all geometry and raster columns for the given table and sets information on the corresponding columns.protected final voidconfigureSpatialColumns(PreparedStatement columnQuery, TableReference source, Map<String, Column> columns, InfoStatements.GeometryTypeEncoding typeValueKind) Implementation ofcompleteIntrospection(TableReference, Map)for geometries, as a separated methods for allowing sub-classes to override above-cited method.final org.opengis.referencing.crs.CoordinateReferenceSystemfetchCRS(int srid) Gets a Coordinate Reference System for to given SRID.final intfindSRID(org.opengis.referencing.crs.CoordinateReferenceSystem crs) Finds a SRID code from the spatial reference systems table for the given CRS.final ValueGetter<?> getComponentMapping(Array array) Returns a function for getting values of components in the given array.final LocaleReturns the locale used for warnings and error messages.protected final PreparedStatementprepareIntrospectionStatement(String table, char prefix, String column, String otherColumn) Prepares the statement for fetching information about all geometry or raster columns in a specified table.
-
Field Details
-
geometryColumns
A statement for fetching geometric information for a specific column.
-
-
Constructor Details
-
InfoStatements
Creates an initially emptyCachedStatementswhich will use the given connection for creatingPreparedStatements.- Parameters:
database- information about the spatial database.connection- connection to use for creating the prepared statements.
-
-
Method Details
-
getLocale
Returns the locale used for warnings and error messages. -
getComponentMapping
Returns a function for getting values of components in the given array. If no match is found, then this method returnsnull.- Parameters:
array- the array from which to get the mapping of component values.- Returns:
- converter to the corresponding java type, or
nullif 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 forcompleteIntrospection(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 ornullif 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 ExceptionGets all geometry and raster columns for the given table and sets information on the corresponding columns. Column instances in thecolumnsmap are modified in-place (the map itself is not modified). This method should be invoked before theColumn.valueGetterfield 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 ExceptionImplementation ofcompleteIntrospection(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 thetypeValueKindargument shall benull.- Parameters:
columnQuery- a statement prepared byprepareIntrospectionStatement(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,TEXTUALornullif 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 returnsnull. 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
nullif 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, ornull.- 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
Closes all prepared statements. This method does not close the connection.- Specified by:
closein interfaceAutoCloseable- Throws:
SQLException- if an error occurred while closing a connection.
-