Package org.geotools.jdbc
Class VirtualTable
- Object
-
- VirtualTable
-
- All Implemented Interfaces:
Serializable
public class VirtualTable extends Object implements 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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
WHERE_CLAUSE_PLACE_HOLDER
static int
WHERE_CLAUSE_PLACE_HOLDER_LENGTH
-
Constructor Summary
Constructors Constructor Description VirtualTable(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
addParameter(VirtualTableParameter param)
Adds a parameter to the virtual tableboolean
equals(Object obj)
String
expandParameters(Hints hints)
int
getDimension(String geometryName)
Returns the geometry dimension, or 2 if not knownSet<String>
getGeometries()
Returns the name of the geometry colums declared in this virtual tableClass<? extends Geometry>
getGeometryType(String geometryName)
Returns the geometry's specific type, or null if not knownString
getName()
The virtual table nameint
getNativeSrid(String geometryName)
Returns the geometry native srid, or -1 if not knownVirtualTableParameter
getParameter(String name)
Returns the requested parameter, or null if it could not be foundCollection<String>
getParameterNames()
The current parameter namesList<String>
getPrimaryKeyColumns()
Returns the virtual table primary key columns.String
getSql()
The virtual table sql (raw, without parameter expansion)int
hashCode()
boolean
isEscapeSql()
void
removeParameter(String paramName)
Removes a parameter from the virtual tablevoid
setEscapeSql(boolean escapeSql)
static Hints
setKeepWhereClausePlaceHolderHint(Query query)
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 keyString
toString()
-
-
-
Field Detail
-
WHERE_CLAUSE_PLACE_HOLDER
public static String WHERE_CLAUSE_PLACE_HOLDER
-
WHERE_CLAUSE_PLACE_HOLDER_LENGTH
public static int WHERE_CLAUSE_PLACE_HOLDER_LENGTH
-
-
Constructor Detail
-
VirtualTable
public VirtualTable(String name, String sql)
Builds a new virtual table stating its name and the query to be executed to work on it
-
VirtualTable
public VirtualTable(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
public VirtualTable(String name, VirtualTable other)
Clone a virtual table under a different name
-
VirtualTable
public VirtualTable(VirtualTable other)
Clone a virtual table
-
-
Method Detail
-
setKeepWhereClausePlaceHolderHint
public static Hints setKeepWhereClausePlaceHolderHint(Query query)
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
public List<String> 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
public void setPrimaryKeyColumns(List<String> primaryKeyColumns)
Sets the virtual table primary key
-
getName
public String getName()
The virtual table name
-
getSql
public String getSql()
The virtual table sql (raw, without parameter expansion)
-
expandParameters
public String expandParameters(Hints hints) throws SQLException
- 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
public void addParameter(VirtualTableParameter param)
Adds a parameter to the virtual table
-
removeParameter
public void removeParameter(String paramName)
Removes a parameter from the virtual table
-
getParameterNames
public Collection<String> getParameterNames()
The current parameter names
-
getParameter
public VirtualTableParameter getParameter(String name)
Returns the requested parameter, or null if it could not be found
-
getGeometryType
public Class<? extends Geometry> getGeometryType(String geometryName)
Returns the geometry's specific type, or null if not known
-
getGeometries
public Set<String> getGeometries()
Returns the name of the geometry colums declared in this virtual table
-
getNativeSrid
public int getNativeSrid(String geometryName)
Returns the geometry native srid, or -1 if not known
-
getDimension
public int getDimension(String geometryName)
Returns the geometry dimension, or 2 if not known
-
isEscapeSql
public boolean isEscapeSql()
-
setEscapeSql
public void setEscapeSql(boolean escapeSql)
-
-