Class InfoStatements
java.lang.Object
org.apache.sis.internal.sql.feature.InfoStatements
- All Implemented Interfaces:
AutoCloseable
,Localized
- Direct Known Subclasses:
ExtendedInfo
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
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enum
Specifies how the geometry type is encoded in the"GEOMETRY_TYPE"
column. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Connection
Connection to use for creating the prepared statements.private final Database<?>
The database that created this set of cached statements.(package private) static final String
The table containing the list of geometry columns, as specified by ISO 19125 / OGC Simple feature access part 2.protected PreparedStatement
A statement for fetching geometric information for a specific column.(package private) static final String
The table containing CRS definitions, as specified by ISO 19125 / OGC Simple feature access part 2.private PreparedStatement
The statement for fetching a SRID from a CRS and its set of authority codes.private PreparedStatement
The statement for fetching CRS Well-Known Text (WKT) from a SRID code.private WKTFormat
The object to use for parsing Well-Known Text (WKT), created when first needed. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
InfoStatements
(Database<?> database, Connection connection) Creates an initially emptyCachedStatements
which will use the given connection for creatingPreparedStatement
s. -
Method Summary
Modifier and TypeMethodDescriptionprivate static SQLBuilder
appendCondition
(SQLBuilder sql, char prefix, String column) Appends a statement after"WHERE"
such as""F_TABLE_NAME = ?"
.private void
appendFrom
(SQLBuilder sql, String table) Appends a" FROM <table> WHERE "
text to the given builder.void
close()
Closes all prepared statements.void
completeIntrospection
(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 void
configureSpatialColumns
(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.CoordinateReferenceSystem
fetchCRS
(int srid) Gets a Coordinate Reference System for to given SRID.final int
findSRID
(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 Locale
Returns the locale used for warnings and error messages.private DataStoreContentException
invalidSRID
(short message, Object complement, int srid, org.opengis.referencing.NoSuchAuthorityCodeException suppressed) Creates the exception to throw for an invalid SRID.private org.opengis.referencing.crs.CoordinateReferenceSystem
parseCRS
(int srid) Invoked when the requested CRS is not in the cache.protected final PreparedStatement
prepareIntrospectionStatement
(String table, char prefix, String column, String otherColumn) Prepares the statement for fetching information about all geometry or raster columns in a specified table.private WKTFormat
Returns the object to use for parsing Well Known Text (CRS).
-
Field Details
-
SPATIAL_REF_SYS
The table containing CRS definitions, as specified by ISO 19125 / OGC Simple feature access part 2. Note that the standard specifies table names in upper-case letters, which is also the default case specified by the SQL standard. However, some databases use lower cases instead. This table name can be used unquoted for letting the database engine converts the case.- See Also:
-
GEOMETRY_COLUMNS
The table containing the list of geometry columns, as specified by ISO 19125 / OGC Simple feature access part 2.- See Also:
-
database
The database that created this set of cached statements. This object includes the cache of CRS created from SRID codes and the listeners where to send warnings. ADatabase
object does not contain live JDBCConnection
. -
connection
Connection to use for creating the prepared statements. This connection will not be closed by this class. -
geometryColumns
A statement for fetching geometric information for a specific column. -
wktFromSrid
The statement for fetching CRS Well-Known Text (WKT) from a SRID code.- See Also:
-
sridFromCRS
The statement for fetching a SRID from a CRS and its set of authority codes. -
wktReader
The object to use for parsing Well-Known Text (WKT), created when first needed.
-
-
Constructor Details
-
InfoStatements
Creates an initially emptyCachedStatements
which will use the given connection for creatingPreparedStatement
s.- 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
null
if this class cannot find a mapping. - Throws:
SQLException
- if the mapping cannot be obtained.
-
appendFrom
Appends a" FROM <table> WHERE "
text to the given builder. The table name will be prefixed by catalog and schema name if applicable. -
appendCondition
Appends a statement after"WHERE"
such as""F_TABLE_NAME = ?"
.- Parameters:
sql
- the builder where to add the SQL statement.prefix
- the column name prefix:'F'
for features or'R'
for rasters.column
- the column name (e.g."TABLE_NAME"
.- Returns:
- the given SQL builder.
-
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 ornull
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 ExceptionGets all geometry and raster columns for the given table and sets information on the corresponding columns. Column instances in thecolumns
map are modified in-place (the map itself is not modified). This method should be invoked before theColumn.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 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 thetypeValueKind
argument 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
,TEXTUAL
ornull
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 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
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
-
parseCRS
Invoked when the requested CRS is not in the cache. This method gets the entry from the "SPATIAL_REF_SYS" table then gets the CRS from its authority code if possible, or fallback on the WKT otherwise.- Parameters:
srid
- the Spatial Reference Identifier (SRID) of the CRS to create from the database content.- Returns:
- the CRS created from database content.
- Throws:
Exception
- if an SQL error, parsing error or other error occurred.
-
invalidSRID
private DataStoreContentException invalidSRID(short message, Object complement, int srid, org.opengis.referencing.NoSuchAuthorityCodeException suppressed) Creates the exception to throw for an invalid SRID. The message is expected to have two arguments,complement
andsrid
if that order, where the "complement" can be a table name or a class name depending on the message.- Parameters:
message
- key of the message to create.complement
- first argument in message formatting.srid
- second argument in message formatting.suppressed
- exception to add as a suppressed exception.- Returns:
- the exception to throw.
-
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.
-
wktReader
Returns the object to use for parsing Well Known Text (CRS). The parser is created when first needed. -
close
Closes all prepared statements. This method does not close the connection.- Specified by:
close
in interfaceAutoCloseable
- Throws:
SQLException
- if an error occurred while closing a connection.
-