Package org.geotools.jdbc
Class VirtualTable
Object
VirtualTable
- All Implemented Interfaces:
Serializable
Describes a virtual table, that is, a feature type created starting from a generic SQL query. This class also carries
information about the primary key (to generate stable feature ids) and the geometry type and native srid (as in most
databases those informations are not available on.
The sql query can contain named parameters. Each parameter has a name, a default value and a way to validate its contents to prevent sql injection.
As well as passing validation, parameters are also passed through a function to escape double quotes, single quotes and strip backslashes to guard against the cases where quotes are desired in the parameters or backslashes have been allowed by an overly lax regular expression.
Escaping is enabled by default and can be controlled by a constructor argument or via the setEscapeSql() method.
- Author:
- Andrea Aime - OpenGeo
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionVirtualTable
(String name, String sql) Builds a new virtual table stating its name and the query to be executed to work on itVirtualTable
(String name, String sql, boolean escapeSql) Builds a new virtual table stating its name, the query to be executed to work on it and a flag to indicate if SQL special characters should be escaped.VirtualTable
(String name, VirtualTable other) Clone a virtual table under a different nameVirtualTable
(VirtualTable other) Clone a virtual table -
Method Summary
Modifier and TypeMethodDescriptionvoid
addGeometryMetadatata
(String geometry, Class<? extends Geometry> binding, int nativeSrid) Adds geometry metadata to the virtual table.void
addGeometryMetadatata
(String geometry, Class<? extends Geometry> binding, int nativeSrid, int dimension) Adds geometry metadata to the virtual table.void
Adds a parameter to the virtual tableboolean
expandParameters
(Hints hints) int
getDimension
(String geometryName) Returns the geometry dimension, or 2 if not knownReturns the name of the geometry colums declared in this virtual tablegetGeometryType
(String geometryName) Returns the geometry's specific type, or null if not knowngetName()
The virtual table nameint
getNativeSrid
(String geometryName) Returns the geometry native srid, or -1 if not knowngetParameter
(String name) Returns the requested parameter, or null if it could not be foundThe current parameter namesReturns the virtual table primary key columns.getSql()
The virtual table sql (raw, without parameter expansion)int
hashCode()
boolean
void
removeParameter
(String paramName) Removes a parameter from the virtual tablevoid
setEscapeSql
(boolean escapeSql) static Hints
If the provided query has a filter of a where clause place holder exists it will be preserved.static Hints
setKeepWhereClausePlaceHolderHint
(Hints hints, boolean keepWhereClausePlaceHolder) Will add an entry to query hints specifying if the the where clause place holder should be keep or not.void
setPrimaryKeyColumns
(List<String> primaryKeyColumns) Sets the virtual table primary keytoString()
-
Field Details
-
WHERE_CLAUSE_PLACE_HOLDER
-
WHERE_CLAUSE_PLACE_HOLDER_LENGTH
public static int WHERE_CLAUSE_PLACE_HOLDER_LENGTH
-
-
Constructor Details
-
VirtualTable
Builds a new virtual table stating its name and the query to be executed to work on it -
VirtualTable
Builds a new virtual table stating its name, the query to be executed to work on it and a flag to indicate if SQL special characters should be escaped. -
VirtualTable
Clone a virtual table under a different name -
VirtualTable
Clone a virtual table
-
-
Method Details
-
setKeepWhereClausePlaceHolderHint
If the provided query has a filter of a where clause place holder exists it will be preserved.- Parameters:
query
- the query to test- Returns:
- a query hints map that will contain an entry specifying if the the where clause place holder should be keep or not
-
setKeepWhereClausePlaceHolderHint
public static Hints setKeepWhereClausePlaceHolderHint(Hints hints, boolean keepWhereClausePlaceHolder) Will add an entry to query hints specifying if the the where clause place holder should be keep or not. If the provided hints is NULL a new one will be instantiated and returned.- Parameters:
hints
- query hints to update, if NULL a new hints map will be createdkeepWhereClausePlaceHolder
- TRUE if the where clause place holder should be keep- Returns:
- a query hints map that will contain an entry specifying if the the where clause place holder should be keep or not
-
getPrimaryKeyColumns
Returns the virtual table primary key columns. It should refer to fields returned by the query, if that is not true the behavior is undefined -
setPrimaryKeyColumns
Sets the virtual table primary key -
getName
The virtual table name -
getSql
The virtual table sql (raw, without parameter expansion) -
expandParameters
- Throws:
SQLException
-
addGeometryMetadatata
public void addGeometryMetadatata(String geometry, Class<? extends Geometry> binding, int nativeSrid) Adds geometry metadata to the virtual table. This is important to get the datastore working, often that is not the case if the right native srid is not in place -
addGeometryMetadatata
public void addGeometryMetadatata(String geometry, Class<? extends Geometry> binding, int nativeSrid, int dimension) Adds geometry metadata to the virtual table. This is important to get the datastore working, often that is not the case if the right native srid is not in place -
addParameter
Adds a parameter to the virtual table -
removeParameter
Removes a parameter from the virtual table -
getParameterNames
The current parameter names -
getParameter
Returns the requested parameter, or null if it could not be found -
getGeometryType
Returns the geometry's specific type, or null if not known -
getGeometries
Returns the name of the geometry colums declared in this virtual table -
getNativeSrid
Returns the geometry native srid, or -1 if not known -
getDimension
Returns the geometry dimension, or 2 if not known -
isEscapeSql
public boolean isEscapeSql() -
setEscapeSql
public void setEscapeSql(boolean escapeSql) -
hashCode
public int hashCode() -
equals
-
toString
-