org.geotools.jdbc
Class VirtualTable

Object
  extended by 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

Constructor Summary
VirtualTable(String name, String sql)
          Builds a new virtual table stating its name and the query to be executed to work on it
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(String name, VirtualTable other)
          Clone a virtual table under a different name
VirtualTable(VirtualTable other)
          Clone a virtual table
 
Method Summary
 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 table
 boolean equals(Object obj)
           
 String expandParameters(Hints hints)
           
 int getDimension(String geometryName)
          Returns the geometry dimension, or 2 if not known
 Set<String> getGeometries()
          Returns the name of the geometry colums declared in this virtual table
 Class<? extends Geometry> getGeometryType(String geometryName)
          Returns the geometry's specific type, or null if not known
 String getName()
          The virtual table name
 int getNativeSrid(String geometryName)
          Returns the geometry native srid, or -1 if not known
 VirtualTableParameter getParameter(String name)
          Returns the requested parameter, or null if it could not be found
 Collection<String> getParameterNames()
          The current parameter names
 List<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 table
 void setEscapeSql(boolean escapeSql)
           
 void setPrimaryKeyColumns(List<String> primaryKeyColumns)
          Sets the virtual table primary key
 String toString()
           
 
Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

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

Parameters:
name -
sql -

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.

Parameters:
name -
sql -
escapeSql -

VirtualTable

public VirtualTable(String name,
                    VirtualTable other)
Clone a virtual table under a different name

Parameters:
name -
other -

VirtualTable

public VirtualTable(VirtualTable other)
Clone a virtual table

Parameters:
name -
other -
Method Detail

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

Parameters:
primaryKeyColumns -

getName

public String getName()
The virtual table name

Returns:

getSql

public String getSql()
The virtual table sql (raw, without parameter expansion)

Returns:

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

Parameters:
geometry -
binding -
nativeSrid -

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

Parameters:
geometry -
binding -
nativeSrid -

addParameter

public void addParameter(VirtualTableParameter param)
Adds a parameter to the virtual table

Parameters:
param -

removeParameter

public void removeParameter(String paramName)
Removes a parameter from the virtual table

Parameters:
paramName -

getParameterNames

public Collection<String> getParameterNames()
The current parameter names

Returns:

getParameter

public VirtualTableParameter getParameter(String name)
Returns the requested parameter, or null if it could not be found

Returns:

getGeometryType

public Class<? extends Geometry> getGeometryType(String geometryName)
Returns the geometry's specific type, or null if not known

Parameters:
geometryName -
Returns:

getGeometries

public Set<String> getGeometries()
Returns the name of the geometry colums declared in this virtual table

Returns:

getNativeSrid

public int getNativeSrid(String geometryName)
Returns the geometry native srid, or -1 if not known

Parameters:
geometryName -
Returns:

getDimension

public int getDimension(String geometryName)
Returns the geometry dimension, or 2 if not known

Parameters:
geometryName -
Returns:

isEscapeSql

public boolean isEscapeSql()

setEscapeSql

public void setEscapeSql(boolean escapeSql)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 1996-2014 Geotools. All Rights Reserved.