Class SpatialDatabasesDSMetadata
java.lang.Object
com.vividsolutions.jump.datastore.spatialdatabases.SpatialDatabasesDSMetadata
- All Implemented Interfaces:
DataStoreMetadata
- Direct Known Subclasses:
H2DSMetadata, MariadbDSMetadata, OracleDSMetadata, PostgisDSMetadata, SpatialiteDSMetadata
A base class for Spatial Databases DataStore Metadata: DB accessed through
JDBC driver, implementing if possible OGC SFSQL. Uses postgis default values
=< already implements mechanism for postgis databases
Ex: Postgis, Oracle Spatial, SpatiaLite, SQL Server.
For each spatial db support, a child class should be added based on this class implementing methods as needed. PostGIS was the Spatial DB used for first impl.
TODO: sql injection- Author:
- Nicolas Ribot
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DataStoreConnectionThe dataStoreConnection to get MD fromprotected StringThe SQL query to get the coordinate dimension for a given schema name, table name and geometry columnprotected StringThe SQL query to get all dataset OGC informationprotected Stringquery to get list of spatial tables from the connection.protected ArrayList<DataStoreLayer> The list of dataStoreLayer for this ds metadata.protected Stringthe name of the default schemaprotected StringThe SQL query to get list of geo columns.protected final org.locationtech.jts.io.WKBReaderOGC WKB reader if needed: TODO: keep only in needed classes ?protected StringThe name of this SpatialDatabaseprotected StringThe SQL query to get spatial extent.protected StringThe alternate SQL query to get spatial extent (for instance for postgis)protected Map<String, SpatialReferenceSystemID> The map of SRIDs found for these MDprotected StringThe SQL query to get a SRID for a given schema name, table name and geometry columnprotected final org.locationtech.jts.io.WKTReaderOGC WKB reader if needed: TODO: keep only in needed classes ? -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptioncreateColumnList(FeatureSchema schema, boolean includeSQLDataType, boolean includeGeometry, boolean includeExternalPK, boolean includeReadOnly, boolean normalizeColumnNames) Returns a comma-separated list of attributes included in schema.getAddGeometryColumnStatement(String schemaName, String tableName, String geometryColumn, int srid, String geometryType, int dim) Creates the query String to add a GeometryColumn.getAddSpatialIndexStatement(String schemaName, String tableName, String geometryColumn) Create statement to add a spatial index on the specified geometry column.String[]getColumnNames(String datasetName) gets the list of columns for the given dataset.intgetCoordinateDimension(String datasetName, String colName) getCoordinateDimensionQuery(String schemaName, String tableName, String colName) getCreateTableStatement(FeatureSchema fSchema, String schemaName, String tableName, boolean normalizeColumnNames) Returns the CREATE TABLE statement corresponding to this feature schema.String[]Nico Ribot: 2018-08-07: new method using a query to get all information for datasets in a structure, to avoid querying too much the serverDataSoreConnection used by these metadataprotected StringgetDbTypeName(AttributeType type) Return standard SQL data type for OpenJUMP AttributeType.org.locationtech.jts.geom.EnvelopegetExtents(String datasetName, String attributeName) getGeoColumnsQuery(String datasetName) getGeometryAttributes(String datasetName) Retrieves list of geometric tables from a custom DB Query: Should use OGC metadata geoemtry_columns or equivalent mechanism according to target DB.protected List<GeometryColumn> getGeometryAttributes(String sql, String datasetName) getPrimaryKeyColumns(String datasetName) Returns PRIMARY KEY columns of dataset names.protected StringgetSchemaName(String tableName) Returns the schema name based on the given tableName: string before . if exists, else returns schemaNamegetSpatialExtentQuery1(String schema, String table, String attributeName) getSpatialExtentQuery2(String schema, String table, String attributeName) Get the SRID of a table's (geometry) columngetSridQuery(String schemaName, String tableName, String colName) protected StringgetTableName(String tableName) Returns the table name based on the given tableName: string after "." if exists, else returns tableNamebooleanReturns whether column is used by a spatial index (Gist) or not.protected booleanReturns true if the given Exception concerns a missing geometric metadata tableprotected String
-
Field Details
-
reader
protected final org.locationtech.jts.io.WKBReader readerOGC WKB reader if needed: TODO: keep only in needed classes ? -
txtReader
protected final org.locationtech.jts.io.WKTReader txtReaderOGC WKB reader if needed: TODO: keep only in needed classes ? -
conn
The dataStoreConnection to get MD from -
sridMap
The map of SRIDs found for these MD -
datasetNameQuery
query to get list of spatial tables from the connection. Must return following columns: distinct table_schema, table_name (if several geo columns exist, only one entry should be returned) -
defaultSchemaName
the name of the default schema -
spatialDbName
The name of this SpatialDatabase -
spatialExtentQuery1
The SQL query to get spatial extent. Must return following columns: a geometric column representing the extent -
spatialExtentQuery2
The alternate SQL query to get spatial extent (for instance for postgis) -
geoColumnsQuery
The SQL query to get list of geo columns. Must return column name (String), srid(int) and type (string) (if spatial database does not store type in metadata, can force the base DB geo type in a string: ex: select ... 'SDO_GEOMETRY' as type from all_sdo_geom_metadata -
sridQuery
The SQL query to get a SRID for a given schema name, table name and geometry column -
coordDimQuery
The SQL query to get the coordinate dimension for a given schema name, table name and geometry column -
datasetInfoQuery
The SQL query to get all dataset OGC information -
dataStoreLayers
The list of dataStoreLayer for this ds metadata. Built when list of dataset names is requested: avoids to call getGeometryAttributes for each dataset, which takes too much time on big DB. Instead, all dataStoreLayer are built once and filtered out to get dataset names
-
-
Constructor Details
-
SpatialDatabasesDSMetadata
public SpatialDatabasesDSMetadata() -
SpatialDatabasesDSMetadata
-
-
Method Details
-
getDatasetNameQuery
-
getDefaultSchemaName
-
getSpatialDbName
-
getSpatialExtentQuery1
-
getSpatialExtentQuery2
-
getGeoColumnsQuery
-
getSridQuery
-
getCoordinateDimensionQuery
-
getDatasetInfoQuery
-
getDataStoreLayers
-
getSchemaName
-
getTableName
-
missingGeoException
Returns true if the given Exception concerns a missing geometric metadata table- Parameters:
e- an exception- Returns:
- true if the exception is about missing geometry column
-
getDatasetNames
Nico Ribot: 2018-08-07: new method using a query to get all information for datasets in a structure, to avoid querying too much the server- Specified by:
getDatasetNamesin interfaceDataStoreMetadata- Returns:
- dataset (table) names from this spatial Database
-
getExtents
- Specified by:
getExtentsin interfaceDataStoreMetadata- Parameters:
datasetName- table name (optionally prefixed by a schema name)attributeName- column containing the Geometry- Returns:
- May be null if the extents cannot be determined
-
getGeometryAttributes
Retrieves list of geometric tables from a custom DB Query: Should use OGC metadata geoemtry_columns or equivalent mechanism according to target DB.- Specified by:
getGeometryAttributesin interfaceDataStoreMetadata- Parameters:
datasetName- name of a dataset- Returns:
- list of GeometryColumn's referenced in this dataset
-
getGeometryAttributes
-
getPrimaryKeyColumns
Returns PRIMARY KEY columns of dataset names. Uses JDBC database Metadata to get this information, instead of custom SQL queries- Specified by:
getPrimaryKeyColumnsin interfaceDataStoreMetadata- Parameters:
datasetName- name of the table (optionally prefixed by the schema name)- Returns:
- the list of columns involved in the Primary Key (generally, a single column)
- Throws:
SQLException- if the server throws an Exception while trying to get PrimaryKey columns
-
getColumnNames
gets the list of columns for the given dataset. TODO: factorize MD retrieval in an Util class ?- Specified by:
getColumnNamesin interfaceDataStoreMetadata- Parameters:
datasetName- the dataset (table) name- Returns:
- an array of column names
-
isIndexed
Returns whether column is used by a spatial index (Gist) or not.- Parameters:
dsName- a dataset (table) namecolumn- a column name- Returns:
- true if the column is indexed
- Throws:
SQLException- if an exception occurs during metadata querying
-
getSRID
Description copied from interface:DataStoreMetadataGet the SRID of a table's (geometry) column- Specified by:
getSRIDin interfaceDataStoreMetadata- Parameters:
datasetName- the dataset namecolName- the column name- Returns:
- the SpatialReferenceSystemID for this column
- Throws:
SQLException- if the server throws an Exception during SRID retrieval
-
querySRID
-
getCoordinateDimension
-
getDataStoreConnection
Description copied from interface:DataStoreMetadataDataSoreConnection used by these metadata- Specified by:
getDataStoreConnectionin interfaceDataStoreMetadata- Returns:
- a DataStoreConnection
-
getCreateTableStatement
public String getCreateTableStatement(FeatureSchema fSchema, String schemaName, String tableName, boolean normalizeColumnNames) Returns the CREATE TABLE statement corresponding to this feature schema. The statement includes column names and data types, but neither geometry column nor primary key.- Parameters:
fSchema- client feature schemaschemaName- unquoted schema name or null to use default schematableName- unquoted table namenormalizeColumnNames- whether column names must be normalized (lowercased and without special characters) or not- Returns:
- the sql string to create the table
-
createColumnList
public String createColumnList(FeatureSchema schema, boolean includeSQLDataType, boolean includeGeometry, boolean includeExternalPK, boolean includeReadOnly, boolean normalizeColumnNames) Returns a comma-separated list of attributes included in schema.- Parameters:
schema- the FeatureSchemaincludeSQLDataType- if true, each attribute name is immediately followed by its corresponding sql DataTypeincludeGeometry- if true, the geometry attribute is includedincludeExternalPK- if true, the external primary key is includedincludeReadOnly- if true, readOnly attributes are includednormalizeColumnNames- whether feature attribute names must be normalized (lower case without spacial characters) to specify table column names.- Returns:
- the sql string containing the list of columns for this schema
-
getAddSpatialIndexStatement
public String getAddSpatialIndexStatement(String schemaName, String tableName, String geometryColumn) Create statement to add a spatial index on the specified geometry column. The geometry column name must have its final form. Attribute name normalization is the responsability of the calling method.- Parameters:
schemaName- unquoted schema name or null if default schema is usedtableName- unquoted table namegeometryColumn- unquoted geometry column name- Returns:
- a sql string to add a spatial index
-
getAddGeometryColumnStatement
public String getAddGeometryColumnStatement(String schemaName, String tableName, String geometryColumn, int srid, String geometryType, int dim) Creates the query String to add a GeometryColumn.Note 1 : In PostGIS 2.x, srid=-1 is automatically converted to srid=0 by AddGeometryColumn function.
Note 2 : To stay compatible with PostGIS 1.x, last argument of AddGeometryColumn is omitted. As a consequence, geometry type uses type modifier rather than constraints (new default behaviour in 2.x)
The geometry column name must have its final form. Attribute name normalization is the responsability of the calling method.
- Parameters:
schemaName- the name of the SchematableName- the name of the TablegeometryColumn- the name of the geometry columnsrid- the SRID for the geometry columngeometryType- the (SQL) geometry type as a Stringdim- the coordinate dimension (2 or 3)- Returns:
- a SQL query string to add a geometry column to a table
-
getDbTypeName
Return standard SQL data type for OpenJUMP AttributeType. This method must be overloaded by specific database oj2dbType- Parameters:
type- OpenJUMP attribute type- Returns:
- the database datatype
-