org.geotools.jdbc
Class JDBCDataStore

Object
  extended by ContentDataStore
      extended by JDBCDataStore
All Implemented Interfaces:
DataAccess<SimpleFeatureType,SimpleFeature>, DataStore, GmlObjectStore

public final class JDBCDataStore
extends ContentDataStore
implements GmlObjectStore

Datastore implementation for jdbc based relational databases.

This class is not intended to be subclassed on a per database basis. Instead the notion of a "dialect" is used.

Dialects

A dialect (SQLDialect) encapsulates all the operations that are database specific. Therefore to implement a jdbc based datastore one must extend SQLDialect. The specific dialect to use is set using setSQLDialect(SQLDialect).

Database Connections

Connections to the underlying database are obtained through a DataSource. A datastore must be specified using setDataSource(DataSource).

Schemas

This datastore supports the notion of database schemas, which is more or less just a grouping of tables. When a schema is specified, only those tables which are part of the schema are provided by the datastore. The schema is specified using setDatabaseSchema(String).

Spatial Functions

The set of spatial operations or functions that are supported by the specific database are reported with a FilterCapabilities instance. This is specified using #setFilterCapabilities(FilterCapabilities).

Author:
Justin Deoliveira, The Open Planning Project
Module:
modules/library/jdbc (gt-jdbc.jar)

Field Summary
protected  HashMap<Class<? extends FeatureVisitor>,String> aggregateFunctions
          Feature visitor to aggregate function name
protected  boolean associations
          flag controlling if the datastore is supporting feature and geometry relationships with associations
protected  HashMap<Class<?>,Integer> classToSqlTypeMappings
          java class to sql type mappings;
protected  String databaseSchema
          The database schema.
protected  DataSource dataSource
          data source
protected static PrimaryKeyFinder DEFAULT_PRIMARY_KEY_FINDER
          The default primary key finder, looks in the default metadata table first, uses heuristics later
protected  SQLDialect dialect
          the dialect of sql
protected static ReferencedEnvelope EMPTY_ENVELOPE
          The envelope returned when bounds is called against a geometryless feature type
protected  boolean exposePrimaryKeyColumns
          flag controlling whether primary key columns of a table are exposed via the feature type.
protected static String FEATURE_ASSOCIATION_TABLE
          name of table to use to store feature associations when associations is set.
protected static String FEATURE_RELATIONSHIP_TABLE
          name of table to use to store feature relationships (information about associations) when associations is set.
protected  int fetchSize
          The fetch size for this datastore, defaulting to 1000.
protected static String GEOMETRY_ASSOCIATION_TABLE
          name of table to use to store geometry associations when associations is set.
protected static String GEOMETRY_TABLE
          name of table to use to store geometries when associations is set.
static String JDBC_NATIVE_SRID
          The native SRID associated to a certain descriptor TODO: qualify this key with 'org.geotools.jdbc'
static String JDBC_NATIVE_TYPENAME
          The key for attribute descriptor user data which specifies the original database column data type.
static String JDBC_READ_ONLY
          Boolean marker stating whether the feature type is to be considered read only
protected static String MULTI_GEOMETRY_TABLE
          name of table to use to store multi geometries made up of non-multi geometries when associations is set.
protected  PrimaryKeyFinder primaryKeyFinder
          Finds the primary key definitions
protected  HashMap<String,Class<?>> sqlTypeNameToClassMappings
          sql type name to java class mappings
protected  HashMap<Integer,Class<?>> sqlTypeToClassMappings
          sql type to java class mappings
protected  HashMap<Integer,String> sqlTypeToSqlTypeNameOverrides
          sql type to sql type name overrides
 
Fields inherited from class ContentDataStore
dataStoreFactory, entries, featureFactory, filterFactory, geometryFactory, lockingManager, LOGGER, namespaceURI, typeFactory, WRITER_ADD, WRITER_UPDATE
 
Constructor Summary
JDBCDataStore()
           
 
Method Summary
 Transaction buildTransaction(Connection cx)
          Builds a transaction object around a user provided connection.
 void closeSafe(Connection cx)
          Utility method for closing a connection.
 void closeSafe(ResultSet rs)
          Utility method for closing a result set.
 void closeSafe(Statement st)
          Utility method for closing a statement.
protected  String createAssociationTableSQL(Connection cx)
          Creates the sql for the association table.
protected  Connection createConnection()
          Creates a new connection.
protected  ContentState createContentState(ContentEntry entry)
          Creates an instanceof JDBCState.
protected  ContentFeatureSource createFeatureSource(ContentEntry entry)
          Creates a new instance of JDBCFeatureStore.
protected  FilterToSQL createFilterToSQL(SimpleFeatureType featureType)
          Creates a new instance of a filter to sql encoder.
protected  String createGeometryAssociationTableSQL(Connection cx)
          Creates the sql for the geometry association table.
protected  String createGeometryTableSQL(Connection cx)
          Creates the sql for the geometry table.
protected  String createMultiGeometryTableSQL(Connection cx)
          Creates the sql for the multi_geometry table.
protected  PreparedFilterToSQL createPreparedFilterToSQL(SimpleFeatureType featureType)
          Creates a new instance of a filter to sql encoder to be used in a prepared statement.
protected  String createRelationshipTableSQL(Connection cx)
          Creates the sql for the relationship table.
 void createSchema(SimpleFeatureType featureType)
          Creates a table in the underlying database from the specified table.
protected  String createTableSQL(SimpleFeatureType featureType, Connection cx)
          Generates a 'CREATE TABLE' sql statement.
protected  List createTypeNames()
          Generates the list of type names provided by the database.
protected  List<Object> decodeFID(PrimaryKey key, String FID, boolean strict)
          Decodes a fid into its components based on a primary key.
protected  void delete(SimpleFeatureType featureType, Filter filter, Connection cx)
          Deletes an existing feature(s) in the database for a particular feature type / table.
protected  void delete(SimpleFeatureType featureType, String fid, Connection cx)
          Deletes an existing feature in the database for a particular feature type / fid.
protected  String deleteSQL(SimpleFeatureType featureType, Filter filter)
          Generates a 'DELETE FROM' sql statement.
protected  PreparedStatement deleteSQLPS(SimpleFeatureType featureType, Filter filter, Connection cx)
          Generates a 'DELETE FROM' prepared statement.
 void dispose()
          Disposes of this data store and releases any resource that it is using.
protected  String encodeFID(List<Object> keyValues)
           
protected  String encodeFID(PrimaryKey pkey, ResultSet rs)
          Encodes a feature id from a primary key and result set values.
protected  void encodeFunction(String function, AttributeDescriptor att, Query query, StringBuffer sql)
           
protected  void encodeGeometryColumn(GeometryDescriptor gatt, StringBuffer sql, Hints hints)
          Encoding a geometry column with respect to hints Supported Hints are provided by SQLDialect.addSupportedHints(Set)
protected  void encodeTableName(String tableName, StringBuffer sql)
          Helper method to encode table name which checks if a schema is set and prefixes the table name with it.
protected  void ensureAssociationTablesExist(Connection cx)
          Helper method for creating geometry association table if it does not exist.
protected  void ensureAuthorization(SimpleFeatureType featureType, Filter filter, Transaction tx, Connection cx)
          Ensures that that the specified transaction has access to features specified by a filter.
protected  void finalize()
           
 Map<Class<? extends FeatureVisitor>,String> getAggregateFunctions()
          Returns the supported aggregate functions and the visitors they map to.
protected  Object getAggregateValue(FeatureVisitor visitor, SimpleFeatureType featureType, Query query, Connection cx)
          Results the value of an aggregate function over a query.
protected  ReferencedEnvelope getBounds(SimpleFeatureType featureType, Query query, Connection cx)
          Returns the bounds of the features for a particular feature type / table.
 Map<Class<?>,Integer> getClassToSqlTypeMappings()
          The java type to sql type mappings that the datastore uses when reading and writing objects to and from the database.
protected  LinkedHashSet<String> getColumnNames(PrimaryKey key)
          Returns the set of the primary key column names.
protected  Class getColumnType(DatabaseMetaData metaData, String databaseSchema2, String tableName, String columnName)
          Returns the type of the column by inspecting the metadata, with the collaboration of the dialect
protected  Connection getConnection(JDBCState state)
          Gets a database connection for the specified feature store.
 Connection getConnection(Transaction t)
          Returns a JDCB Connection to the underlying database for the specified GeoTools Transaction.
protected  int getCount(SimpleFeatureType featureType, Query query, Connection cx)
          Returns the count of the features for a particular feature type / table.
 String getDatabaseSchema()
          The schema from which this datastore is serving tables from.
 DataSource getDataSource()
          The data source the datastore uses to obtain connections to the underlying database.
protected  int getDescriptorSRID(AttributeDescriptor descriptor)
          Extracts the eventual native SRID user property from the descriptor, returns -1 if not found
 int getFetchSize()
          The current fetch size.
 FilterCapabilities getFilterCapabilities()
          The filter capabilities which reports which spatial operations the underlying database can handle natively.
protected  int getGeometrySRID(Geometry g, AttributeDescriptor descriptor)
          Looks up the geometry srs by trying a number of heuristics.
 Object getGmlObject(GmlObjectId id, Hints hints)
          Looks up an object by its gml id.
protected  Object getLastValue(PrimaryKeyColumn col, PrimaryKey pkey, Connection cx)
          Gets the last value of a generated primary key column.
protected  List<Object> getLastValues(PrimaryKey pkey, Connection cx)
          Gets the last value of a generated primary key.
 Integer getMapping(Class<?> clazz)
          Returns the sql type mapped to the specified java type.
 Class<?> getMapping(int sqlType)
          Returns the java type mapped to the specified sql type.
 Class<?> getMapping(String sqlTypeName)
          Returns the java type mapped to the specified sql type name.
protected  Object getNextValue(PrimaryKeyColumn col, PrimaryKey pkey, Connection cx)
          Gets the next value for the column of a primary key.
protected  List<Object> getNextValues(PrimaryKey pkey, Connection cx)
          Gets the next value of a primary key.
protected  PrimaryKey getPrimaryKey(ContentEntry entry)
          Returns the primary key object for a particular entry, deriving it from the underlying database metadata.
protected  PrimaryKey getPrimaryKey(SimpleFeatureType featureType)
          Returns the primary key object for a particular feature type / table, deriving it from the underlying database metadata.
 PrimaryKeyFinder getPrimaryKeyFinder()
          Returns the finder used to build PrimaryKey representations
protected  String getPropertyName(SimpleFeatureType featureType, PropertyName propertyName)
          Helper method for executing a property name against a feature type.
 SQLDialect getSQLDialect()
          The dialect the datastore uses to generate sql statements in order to communicate with the underlying database.
 Map<String,Class<?>> getSqlTypeNameToClassMappings()
          The sql type name to java type mappings that the dialect uses when reading and writing objects to and from the database.
 Map<Integer,Class<?>> getSqlTypeToClassMappings()
          The sql type to java type mappings that the datastore uses when reading and writing objects to and from the database.
 Map<Integer,String> getSqlTypeToSqlTypeNameOverrides()
          Returns any ovverides which map integer constants for database types (from Types) to database type names.
protected
<F extends FilterToSQL>
F
initializeFilterToSQL(F toSQL, SimpleFeatureType featureType)
          Helper method to initialize a filter encoder instance.
protected  void insert(Collection features, SimpleFeatureType featureType, Connection cx)
          Inserts a collection of new features into the database for a particular feature type / table.
protected  void insert(SimpleFeature feature, SimpleFeatureType featureType, Connection cx)
          Inserts a new feature into the database for a particular feature type / table.
protected  String insertSQL(SimpleFeatureType featureType, SimpleFeature feature, List keyValues, Connection cx)
          Generates a 'INSERT INFO' sql statement.
protected  PreparedStatement insertSQLPS(SimpleFeatureType featureType, SimpleFeature feature, List keyValues, Connection cx)
          Generates a 'INSERT INFO' prepared statement.
 boolean isAssociations()
          Flag controlling if the datastore is supporting feature and geometry relationships with associations
 boolean isExposePrimaryKeyColumns()
          Determines if the datastore creates feature types which include those columns / attributes which compose the primary key.
protected  boolean isExposePrimaryKeyColumns(SimpleFeatureType featureType)
          Returns the expose primary key columns flag for the specified feature type
protected  boolean isGeneralizationRequired(Hints hints, GeometryDescriptor gatt)
          Checks if geometry generalization required and makes sense
protected  boolean isGenerated(PrimaryKey pkey)
          Determines if a primary key is made up entirely of column which are generated via an auto-generating column or a sequence.
protected  boolean isGeometryReduceRequired(Hints hints, GeometryDescriptor gatt, Hints.Key param)
          Checks if reduction required and makes sense
protected  boolean isSimplificationRequired(Hints hints, GeometryDescriptor gatt)
          Checks if geometry simplification required and makes sense
protected  void releaseConnection(Connection cx, JDBCState state)
          Releases an existing connection.
protected  String selectAggregateSQL(String function, AttributeDescriptor att, SimpleFeatureType featureType, Query query)
          Generates a 'SELECT () FROM' statement.
protected  PreparedStatement selectAggregateSQLPS(String function, AttributeDescriptor att, SimpleFeatureType featureType, Query query, Connection cx)
          Generates a 'SELECT () FROM' prepared statement.
protected  String selectAssociationSQL(String fid)
          Creates the sql for the association table.
protected  PreparedStatement selectAssociationSQLPS(String fid, Connection cx)
          Creates the prepared statement for the association table.
protected  String selectBoundsSQL(SimpleFeatureType featureType, Query query)
          Generates a 'SELECT' sql statement which selects bounds.
protected  PreparedStatement selectBoundsSQLPS(SimpleFeatureType featureType, Query query, Connection cx)
          Generates a 'SELECT' prepared statement which selects bounds.
protected  String selectCountSQL(SimpleFeatureType featureType, Query query)
          Generates a 'SELECT count(*) FROM' sql statement.
protected  PreparedStatement selectCountSQLPS(SimpleFeatureType featureType, Query query, Connection cx)
          Generates a 'SELECT count(*) FROM' prepared statement.
protected  String selectGeometryAssociationSQL(String fid, String gid, String gname)
          Creates the sql for a select from the geometry association table.
protected  PreparedStatement selectGeometryAssociationSQLPS(String fid, String gid, String gname, Connection cx)
          Creates the prepared statement for a select from the geometry association table.
protected  String selectGeometrySQL(String gid)
          Creates the sql for a select from the geometry table.
protected  PreparedStatement selectGeometrySQLPS(String gid, Connection cx)
          Creates the prepared for a select from the geometry table.
protected  String selectMultiGeometrySQL(String gid)
          Creates the sql for a select from the multi geometry table.
protected  PreparedStatement selectMultiGeometrySQLPS(String gid, Connection cx)
          Creates the prepared statement for a select from the multi geometry table.
protected  String selectRelationshipSQL(String table, String column)
          Creates the sql for the relationship table.
protected  PreparedStatement selectRelationshipSQLPS(String table, String column, Connection cx)
          Creates the prepared statement for a query against the relationship table.
protected  String selectSQL(SimpleFeatureType featureType, Query query)
          Generates a 'SELECT p1, p2, ...
protected  PreparedStatement selectSQLPS(SimpleFeatureType featureType, Query query, Connection cx)
          Generates a 'SELECT p1, p2, ...
 void setAssociations(boolean foreignKeyGeometries)
          Sets the flag controlling if the datastore is supporting feature and geometry relationships with associations
 void setDatabaseSchema(String databaseSchema)
          Set the database schema for the datastore.
 void setDataSource(DataSource dataSource)
          Sets the data source the datastore uses to obtain connections to the underlying database.
 void setExposePrimaryKeyColumns(boolean exposePrimaryKeyColumns)
          Sets the flag controlling if the datastore creates feature types which include those columns / attributes which compose the primary key.
 void setFetchSize(int fetchSize)
          Changes the fetch size.
protected  void setGmlProperties(Geometry g, String gid, String name, String description)
          Helper method for setting the gml:id of a geometry as user data.
protected  void setPreparedFilterValues(PreparedStatement ps, PreparedFilterToSQL toSQL, int offset, Connection cx)
          Helper method for setting the values of the WHERE class of a prepared statement.
 void setPrimaryKeyFinder(PrimaryKeyFinder primaryKeyFinder)
          Sets the finder used to build PrimaryKey representations
 void setSQLDialect(SQLDialect dialect)
          Sets the dialect the datastore uses to generate sql statements in order to communicate with the underlying database.
protected  void update(SimpleFeatureType featureType, AttributeDescriptor[] attributes, Object[] values, Filter filter, Connection cx)
          Updates an existing feature(s) in the database for a particular feature type / table.
protected  void update(SimpleFeatureType featureType, List<AttributeDescriptor> attributes, List<Object> values, Filter filter, Connection cx)
          Updates an existing feature(s) in the database for a particular feature type / table.
protected  String updateSQL(SimpleFeatureType featureType, AttributeDescriptor[] attributes, Object[] values, Filter filter)
          Generates an 'UPDATE' sql statement.
protected  PreparedStatement updateSQLPS(SimpleFeatureType featureType, AttributeDescriptor[] attributes, Object[] values, Filter filter, Connection cx)
          Generates an 'UPDATE' prepared statement.
 
Methods inherited from class ContentDataStore
ensureEntry, ensureFeatureStore, entry, getDataStoreFactory, getEntry, getFeatureFactory, getFeatureReader, getFeatureSource, getFeatureSource, getFeatureSource, getFeatureSource, getFeatureTypeFactory, getFeatureWriter, getFeatureWriter, getFeatureWriterAppend, getFilterFactory, getGeometryFactory, getInfo, getLockingManager, getLogger, getNames, getNamespaceURI, getSchema, getSchema, getTypeNames, getView, name, setDataStoreFactory, setFeatureFactory, setFeatureTypeFactory, setFilterFactory, setGeometryFactory, setNamespaceURI, updateSchema, updateSchema
 
Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JDBC_NATIVE_SRID

public static final String JDBC_NATIVE_SRID
The native SRID associated to a certain descriptor TODO: qualify this key with 'org.geotools.jdbc'

See Also:
Constant Field Values

JDBC_READ_ONLY

public static final String JDBC_READ_ONLY
Boolean marker stating whether the feature type is to be considered read only

See Also:
Constant Field Values

JDBC_NATIVE_TYPENAME

public static final String JDBC_NATIVE_TYPENAME
The key for attribute descriptor user data which specifies the original database column data type.

See Also:
Constant Field Values

GEOMETRY_TABLE

protected static final String GEOMETRY_TABLE
name of table to use to store geometries when associations is set.

See Also:
Constant Field Values

MULTI_GEOMETRY_TABLE

protected static final String MULTI_GEOMETRY_TABLE
name of table to use to store multi geometries made up of non-multi geometries when associations is set.

See Also:
Constant Field Values

GEOMETRY_ASSOCIATION_TABLE

protected static final String GEOMETRY_ASSOCIATION_TABLE
name of table to use to store geometry associations when associations is set.

See Also:
Constant Field Values

FEATURE_RELATIONSHIP_TABLE

protected static final String FEATURE_RELATIONSHIP_TABLE
name of table to use to store feature relationships (information about associations) when associations is set.

See Also:
Constant Field Values

FEATURE_ASSOCIATION_TABLE

protected static final String FEATURE_ASSOCIATION_TABLE
name of table to use to store feature associations when associations is set.

See Also:
Constant Field Values

DEFAULT_PRIMARY_KEY_FINDER

protected static final PrimaryKeyFinder DEFAULT_PRIMARY_KEY_FINDER
The default primary key finder, looks in the default metadata table first, uses heuristics later


EMPTY_ENVELOPE

protected static final ReferencedEnvelope EMPTY_ENVELOPE
The envelope returned when bounds is called against a geometryless feature type


dataSource

protected DataSource dataSource
data source


dialect

protected SQLDialect dialect
the dialect of sql


databaseSchema

protected String databaseSchema
The database schema.


sqlTypeToClassMappings

protected HashMap<Integer,Class<?>> sqlTypeToClassMappings
sql type to java class mappings


sqlTypeNameToClassMappings

protected HashMap<String,Class<?>> sqlTypeNameToClassMappings
sql type name to java class mappings


classToSqlTypeMappings

protected HashMap<Class<?>,Integer> classToSqlTypeMappings
java class to sql type mappings;


sqlTypeToSqlTypeNameOverrides

protected HashMap<Integer,String> sqlTypeToSqlTypeNameOverrides
sql type to sql type name overrides


aggregateFunctions

protected HashMap<Class<? extends FeatureVisitor>,String> aggregateFunctions
Feature visitor to aggregate function name


associations

protected boolean associations
flag controlling if the datastore is supporting feature and geometry relationships with associations


fetchSize

protected int fetchSize
The fetch size for this datastore, defaulting to 1000. Set to a value less or equal to 0 to disable fetch size limit and grab all the records in one shot.


exposePrimaryKeyColumns

protected boolean exposePrimaryKeyColumns
flag controlling whether primary key columns of a table are exposed via the feature type.


primaryKeyFinder

protected PrimaryKeyFinder primaryKeyFinder
Finds the primary key definitions

Constructor Detail

JDBCDataStore

public JDBCDataStore()
Method Detail

getPrimaryKeyFinder

public PrimaryKeyFinder getPrimaryKeyFinder()
Returns the finder used to build PrimaryKey representations

Returns:

setPrimaryKeyFinder

public void setPrimaryKeyFinder(PrimaryKeyFinder primaryKeyFinder)
Sets the finder used to build PrimaryKey representations

Parameters:
primaryKeyFinder -

getFetchSize

public int getFetchSize()
The current fetch size. The fetch size influences how many records are read from the dbms at a time. If set to a value less or equal than zero, all the records will be read in one shot, severily increasing the memory requirements to read a big number of features.

Returns:

setFetchSize

public void setFetchSize(int fetchSize)
Changes the fetch size.

Parameters:
fetchSize -

isExposePrimaryKeyColumns

public boolean isExposePrimaryKeyColumns()
Determines if the datastore creates feature types which include those columns / attributes which compose the primary key.


setExposePrimaryKeyColumns

public void setExposePrimaryKeyColumns(boolean exposePrimaryKeyColumns)
Sets the flag controlling if the datastore creates feature types which include those columns / attributes which compose the primary key.


getSQLDialect

public SQLDialect getSQLDialect()
The dialect the datastore uses to generate sql statements in order to communicate with the underlying database.

Returns:
The dialect, never null.

setSQLDialect

public void setSQLDialect(SQLDialect dialect)
Sets the dialect the datastore uses to generate sql statements in order to communicate with the underlying database.

Parameters:
dialect - The dialect, never null.

getDataSource

public DataSource getDataSource()
The data source the datastore uses to obtain connections to the underlying database.

Returns:
The data source, never null.

setDataSource

public void setDataSource(DataSource dataSource)
Sets the data source the datastore uses to obtain connections to the underlying database.

Parameters:
dataSource - The data source, never null.

getDatabaseSchema

public String getDatabaseSchema()
The schema from which this datastore is serving tables from.

Returns:
the schema, or null if non specified.

setDatabaseSchema

public void setDatabaseSchema(String databaseSchema)
Set the database schema for the datastore.

When this value is set only those tables which are part of the schema are served through the datastore. This value can be set to null to specify no particular schema.

Parameters:
databaseSchema - The schema, may be null.

getFilterCapabilities

public FilterCapabilities getFilterCapabilities()
The filter capabilities which reports which spatial operations the underlying database can handle natively.

Returns:
The filter capabilities, never null.

isAssociations

public boolean isAssociations()
Flag controlling if the datastore is supporting feature and geometry relationships with associations


setAssociations

public void setAssociations(boolean foreignKeyGeometries)
Sets the flag controlling if the datastore is supporting feature and geometry relationships with associations


getSqlTypeToClassMappings

public Map<Integer,Class<?>> getSqlTypeToClassMappings()
The sql type to java type mappings that the datastore uses when reading and writing objects to and from the database.

These mappings are derived from SQLDialect.registerSqlTypeToClassMappings(java.util.Map)

Returns:
The mappings, never null.

getSqlTypeNameToClassMappings

public Map<String,Class<?>> getSqlTypeNameToClassMappings()
The sql type name to java type mappings that the dialect uses when reading and writing objects to and from the database.

These mappings are derived from SQLDialect.registerSqlTypeNameToClassMappings(Map)

Returns:
The mappings, never null.

getClassToSqlTypeMappings

public Map<Class<?>,Integer> getClassToSqlTypeMappings()
The java type to sql type mappings that the datastore uses when reading and writing objects to and from the database.

These mappings are derived from SQLDialect.registerClassToSqlMappings(Map)

Returns:
The mappings, never null.

getSqlTypeToSqlTypeNameOverrides

public Map<Integer,String> getSqlTypeToSqlTypeNameOverrides()
Returns any ovverides which map integer constants for database types (from Types) to database type names.

This method will return an empty map when there are no overrides.


getAggregateFunctions

public Map<Class<? extends FeatureVisitor>,String> getAggregateFunctions()
Returns the supported aggregate functions and the visitors they map to.


getMapping

public Class<?> getMapping(int sqlType)
Returns the java type mapped to the specified sql type.

If there is no such type mapped to sqlType, null is returned.

Parameters:
sqlType - The integer constant for the sql type from Types.
Returns:
The mapped java class, or null. if no such mapping exists.

getMapping

public Class<?> getMapping(String sqlTypeName)
Returns the java type mapped to the specified sql type name.

If there is no such type mapped to sqlTypeName, null is returned.

Parameters:
sqlTypeName - The name of the sql type.
Returns:
The mapped java class, or null. if no such mapping exists.

getMapping

public Integer getMapping(Class<?> clazz)
Returns the sql type mapped to the specified java type.

If there is no such type mapped to clazz, Types.OTHER is returned.

Parameters:
clazz - The java class.
Returns:
The mapped sql type from Types, Types.OTHER if no such mapping exists.

createSchema

public void createSchema(SimpleFeatureType featureType)
                  throws IOException
Creates a table in the underlying database from the specified table.

This method will map the classes of the attributes of featureType to sql types and generate a 'CREATE TABLE' statement against the underlying database.

Specified by:
createSchema in interface DataAccess<SimpleFeatureType,SimpleFeature>
Overrides:
createSchema in class ContentDataStore
Parameters:
featureType - FetureType to add to DataStore
Throws:
IllegalArgumentException - If the table already exists.
IOException - If the table cannot be created due to an error.
See Also:
DataStore#createSchema(SimpleFeatureType)

getGmlObject

public Object getGmlObject(GmlObjectId id,
                           Hints hints)
                    throws IOException
Description copied from interface: GmlObjectStore
Looks up an object by its gml id.

This method returns null if no such object exists.

Specified by:
getGmlObject in interface GmlObjectStore
Parameters:
id - The id of the object, must not be null.
hints - Any hints to use when looking up the gml object, this value may be null.
Returns:
The gml object, or null if one could not be found matching the specified id.
Throws:
IOException - Any I/O errors that occur.

createFeatureSource

protected ContentFeatureSource createFeatureSource(ContentEntry entry)
                                            throws IOException
Creates a new instance of JDBCFeatureStore.

Specified by:
createFeatureSource in class ContentDataStore
Parameters:
entry - The entry.
Returns:
An new instance of ContentFeatureSource for the entry.
Throws:
IOException
See Also:
ContentDataStore.createFeatureSource(ContentEntry)

createContentState

protected ContentState createContentState(ContentEntry entry)
Creates an instanceof JDBCState.

Overrides:
createContentState in class ContentDataStore
Parameters:
entry - The entry.
Returns:
A new instance of ContentState for the entry.
See Also:
ContentDataStore.createContentState(ContentEntry)

createTypeNames

protected List createTypeNames()
                        throws IOException
Generates the list of type names provided by the database.

The list is generated from the underlying database metadata.

Specified by:
createTypeNames in class ContentDataStore
Returns:
A list of Name.
Throws:
IOException - Any errors occuring connecting to data.

getPrimaryKey

protected PrimaryKey getPrimaryKey(ContentEntry entry)
                            throws IOException
Returns the primary key object for a particular entry, deriving it from the underlying database metadata.

Throws:
IOException

getColumnType

protected Class getColumnType(DatabaseMetaData metaData,
                              String databaseSchema2,
                              String tableName,
                              String columnName)
                       throws SQLException
Returns the type of the column by inspecting the metadata, with the collaboration of the dialect

Throws:
SQLException

getPrimaryKey

protected PrimaryKey getPrimaryKey(SimpleFeatureType featureType)
                            throws IOException
Returns the primary key object for a particular feature type / table, deriving it from the underlying database metadata.

Throws:
IOException

isExposePrimaryKeyColumns

protected boolean isExposePrimaryKeyColumns(SimpleFeatureType featureType)
                                     throws IOException
Returns the expose primary key columns flag for the specified feature type

Parameters:
featureType -
Returns:
Throws:
IOException

getBounds

protected ReferencedEnvelope getBounds(SimpleFeatureType featureType,
                                       Query query,
                                       Connection cx)
                                throws IOException
Returns the bounds of the features for a particular feature type / table.

Parameters:
featureType - The feature type / table.
query - Specifies rows to include in bounds calculation, as well as how many features and the offset if needed
Throws:
IOException

getCount

protected int getCount(SimpleFeatureType featureType,
                       Query query,
                       Connection cx)
                throws IOException
Returns the count of the features for a particular feature type / table.

Throws:
IOException

getAggregateValue

protected Object getAggregateValue(FeatureVisitor visitor,
                                   SimpleFeatureType featureType,
                                   Query query,
                                   Connection cx)
                            throws IOException
Results the value of an aggregate function over a query.

Throws:
IOException

insert

protected void insert(SimpleFeature feature,
                      SimpleFeatureType featureType,
                      Connection cx)
               throws IOException
Inserts a new feature into the database for a particular feature type / table.

Throws:
IOException

insert

protected void insert(Collection features,
                      SimpleFeatureType featureType,
                      Connection cx)
               throws IOException
Inserts a collection of new features into the database for a particular feature type / table.

Throws:
IOException

update

protected void update(SimpleFeatureType featureType,
                      List<AttributeDescriptor> attributes,
                      List<Object> values,
                      Filter filter,
                      Connection cx)
               throws IOException
Updates an existing feature(s) in the database for a particular feature type / table.

Throws:
IOException

update

protected void update(SimpleFeatureType featureType,
                      AttributeDescriptor[] attributes,
                      Object[] values,
                      Filter filter,
                      Connection cx)
               throws IOException
Updates an existing feature(s) in the database for a particular feature type / table.

Throws:
IOException

delete

protected void delete(SimpleFeatureType featureType,
                      String fid,
                      Connection cx)
               throws IOException
Deletes an existing feature in the database for a particular feature type / fid.

Throws:
IOException

delete

protected void delete(SimpleFeatureType featureType,
                      Filter filter,
                      Connection cx)
               throws IOException
Deletes an existing feature(s) in the database for a particular feature type / table.

Throws:
IOException

getConnection

public Connection getConnection(Transaction t)
                         throws IOException
Returns a JDCB Connection to the underlying database for the specified GeoTools Transaction. This has two main use cases:
  • Independently accessing the underlying database directly reusing the connection pool contained in the JDBCDataStore
  • Performing some direct access to the database in the same JDBC transaction as the Geotools code
The connection shall be used in a different way depending on the use case:
  • If the transaction is Transaction.AUTO_COMMIT or if the transaction is not shared with this data store and originating FeatureStore objects it is the duty of the caller to properly close the connection after usage, failure to do so will result in the connection pool loose one available connection permanently
  • If the transaction is on the other side a valid transaction is shared with Geotools the client code should refrain from closing the connection, committing or rolling back, and use the Transaction facilities to do so instead

Parameters:
t - The GeoTools transaction. Can be null, in that case a new connection will be returned (as if Transaction.AUTO_COMMIT was provided)
Throws:
IOException

getConnection

protected final Connection getConnection(JDBCState state)
                                  throws IOException
Gets a database connection for the specified feature store.

Throws:
IOException

createConnection

protected final Connection createConnection()
Creates a new connection.

Callers of this method should close the connection when done with it.

.


releaseConnection

protected final void releaseConnection(Connection cx,
                                       JDBCState state)
Releases an existing connection.


encodeFID

protected String encodeFID(PrimaryKey pkey,
                           ResultSet rs)
                    throws SQLException,
                           IOException
Encodes a feature id from a primary key and result set values.

Throws:
SQLException
IOException

encodeFID

protected String encodeFID(List<Object> keyValues)

decodeFID

protected List<Object> decodeFID(PrimaryKey key,
                                 String FID,
                                 boolean strict)
Decodes a fid into its components based on a primary key.

Parameters:
strict - If set to true the value of the fid will be validated against the type of the key columns. If a conversion can not be made, an exception will be thrown.

isGenerated

protected boolean isGenerated(PrimaryKey pkey)
Determines if a primary key is made up entirely of column which are generated via an auto-generating column or a sequence.


getNextValues

protected List<Object> getNextValues(PrimaryKey pkey,
                                     Connection cx)
                              throws SQLException,
                                     IOException
Gets the next value of a primary key.

Throws:
SQLException
IOException

getNextValue

protected Object getNextValue(PrimaryKeyColumn col,
                              PrimaryKey pkey,
                              Connection cx)
                       throws SQLException,
                              IOException
Gets the next value for the column of a primary key.

Throws:
SQLException
IOException

getLastValues

protected List<Object> getLastValues(PrimaryKey pkey,
                                     Connection cx)
                              throws SQLException,
                                     IOException
Gets the last value of a generated primary key.

Throws:
SQLException
IOException

getLastValue

protected Object getLastValue(PrimaryKeyColumn col,
                              PrimaryKey pkey,
                              Connection cx)
                       throws SQLException,
                              IOException
Gets the last value of a generated primary key column.

Throws:
SQLException
IOException

createTableSQL

protected String createTableSQL(SimpleFeatureType featureType,
                                Connection cx)
                         throws Exception
Generates a 'CREATE TABLE' sql statement.

Throws:
Exception

ensureAuthorization

protected void ensureAuthorization(SimpleFeatureType featureType,
                                   Filter filter,
                                   Transaction tx,
                                   Connection cx)
                            throws IOException,
                                   SQLException
Ensures that that the specified transaction has access to features specified by a filter.

If any features matching the filter are locked, and the transaction does not have authorization with respect to the lock, an exception is thrown.

Parameters:
featureType - The feature type / table.
filter - The filters.
tx - The transaction.
cx - The database connection.
Throws:
IOException
SQLException

ensureAssociationTablesExist

protected void ensureAssociationTablesExist(Connection cx)
                                     throws IOException,
                                            SQLException
Helper method for creating geometry association table if it does not exist.

Throws:
IOException
SQLException

createRelationshipTableSQL

protected String createRelationshipTableSQL(Connection cx)
                                     throws SQLException
Creates the sql for the relationship table.

This method is only called when isAssociations() is true.

Throws:
SQLException

createAssociationTableSQL

protected String createAssociationTableSQL(Connection cx)
                                    throws SQLException
Creates the sql for the association table.

This method is only called when isAssociations() is true.

Throws:
SQLException

createGeometryTableSQL

protected String createGeometryTableSQL(Connection cx)
                                 throws SQLException
Creates the sql for the geometry table.

This method is only called when isAssociations() is true.

Throws:
SQLException

createMultiGeometryTableSQL

protected String createMultiGeometryTableSQL(Connection cx)
                                      throws SQLException
Creates the sql for the multi_geometry table.

This method is only called when isAssociations() is true.

Throws:
SQLException

selectRelationshipSQL

protected String selectRelationshipSQL(String table,
                                       String column)
Creates the sql for the relationship table.

This method is only called when isAssociations() is true.

Parameters:
table - The table of the association
column - The column of the association

selectRelationshipSQLPS

protected PreparedStatement selectRelationshipSQLPS(String table,
                                                    String column,
                                                    Connection cx)
                                             throws SQLException
Creates the prepared statement for a query against the relationship table.

This method is only called when isAssociations() is true.

Parameters:
table - The table of the association
column - The column of the association
Throws:
SQLException

selectAssociationSQL

protected String selectAssociationSQL(String fid)
Creates the sql for the association table.

This method is only called when isAssociations() is true.

Parameters:
fid - The feature id of the association

selectAssociationSQLPS

protected PreparedStatement selectAssociationSQLPS(String fid,
                                                   Connection cx)
                                            throws SQLException
Creates the prepared statement for the association table.

This method is only called when isAssociations() is true.

Parameters:
fid - The feature id of the association
Throws:
SQLException

selectGeometrySQL

protected String selectGeometrySQL(String gid)
Creates the sql for a select from the geometry table.

This method is only called when isAssociations() is true.

Parameters:
gid - The geometry id to select for, may be null

selectGeometrySQLPS

protected PreparedStatement selectGeometrySQLPS(String gid,
                                                Connection cx)
                                         throws SQLException
Creates the prepared for a select from the geometry table.

This method is only called when isAssociations() is true.

Parameters:
gid - The geometry id to select for, may be null
Throws:
SQLException

selectMultiGeometrySQL

protected String selectMultiGeometrySQL(String gid)
Creates the sql for a select from the multi geometry table.

This method is only called when isAssociations() is true.

Parameters:
gid - The geometry id to select for, may be null.

selectMultiGeometrySQLPS

protected PreparedStatement selectMultiGeometrySQLPS(String gid,
                                                     Connection cx)
                                              throws SQLException
Creates the prepared statement for a select from the multi geometry table.

This method is only called when isAssociations() is true.

Parameters:
gid - The geometry id to select for, may be null.
Throws:
SQLException

createGeometryAssociationTableSQL

protected String createGeometryAssociationTableSQL(Connection cx)
                                            throws SQLException
Creates the sql for the geometry association table.

This method is only called when isAssociations() is true.

Throws:
SQLException

selectGeometryAssociationSQL

protected String selectGeometryAssociationSQL(String fid,
                                              String gid,
                                              String gname)
Creates the sql for a select from the geometry association table.

Parameters:
fid - The fid to select for, may be null
gid - The geometry id to select for, may be null
gname - The geometry name to select for, may be null

selectGeometryAssociationSQLPS

protected PreparedStatement selectGeometryAssociationSQLPS(String fid,
                                                           String gid,
                                                           String gname,
                                                           Connection cx)
                                                    throws SQLException
Creates the prepared statement for a select from the geometry association table.

Parameters:
fid - The fid to select for, may be null
gid - The geometry id to select for, may be null
gname - The geometry name to select for, may be null
Throws:
SQLException

selectSQL

protected String selectSQL(SimpleFeatureType featureType,
                           Query query)
                    throws IOException
Generates a 'SELECT p1, p2, ... FROM ... WHERE ...' statement.

Parameters:
featureType - the feature type that the query must return (may contain less attributes than the native one)
attributes - the properties queried, or Query.ALL_NAMES to gather all of them
query - the query to be run. The type name and property will be ignored, as they are supposed to have been already embedded into the provided feature type
sort - sort conditions
Throws:
IOException

selectSQLPS

protected PreparedStatement selectSQLPS(SimpleFeatureType featureType,
                                        Query query,
                                        Connection cx)
                                 throws SQLException,
                                        IOException
Generates a 'SELECT p1, p2, ... FROM ... WHERE ...' prepared statement.

Parameters:
featureType - the feature type that the query must return (may contain less attributes than the native one)
attributes - the properties queried, or Query.ALL_NAMES to gather all of them
query - the query to be run. The type name and property will be ignored, as they are supposed to have been already embedded into the provided feature type
cx - The database connection to be used to create the prepared statement
Throws:
SQLException
IOException

setPreparedFilterValues

protected void setPreparedFilterValues(PreparedStatement ps,
                                       PreparedFilterToSQL toSQL,
                                       int offset,
                                       Connection cx)
                                throws SQLException
Helper method for setting the values of the WHERE class of a prepared statement.

Throws:
SQLException

getPropertyName

protected String getPropertyName(SimpleFeatureType featureType,
                                 PropertyName propertyName)
Helper method for executing a property name against a feature type.

This method will fall back on PropertyName.getPropertyName() if it does not evaulate against the feature type.


selectBoundsSQL

protected String selectBoundsSQL(SimpleFeatureType featureType,
                                 Query query)
Generates a 'SELECT' sql statement which selects bounds.

Parameters:
featureType - The feature type / table.
query - Specifies which features are to be used for the bounds computation (and in particular uses filter, start index and max features)

selectBoundsSQLPS

protected PreparedStatement selectBoundsSQLPS(SimpleFeatureType featureType,
                                              Query query,
                                              Connection cx)
                                       throws SQLException
Generates a 'SELECT' prepared statement which selects bounds.

Parameters:
featureType - The feature type / table.
query - Specifies which features are to be used for the bounds computation (and in particular uses filter, start index and max features)
cx - A database connection.
Throws:
SQLException

selectCountSQL

protected String selectCountSQL(SimpleFeatureType featureType,
                                Query query)
Generates a 'SELECT count(*) FROM' sql statement. In case limit/offset is used, we'll need to apply them on a select * as limit/offset usually alters the number of returned rows (and a count returns just one), and then count on the result of that first select


selectCountSQLPS

protected PreparedStatement selectCountSQLPS(SimpleFeatureType featureType,
                                             Query query,
                                             Connection cx)
                                      throws SQLException
Generates a 'SELECT count(*) FROM' prepared statement.

Throws:
SQLException

selectAggregateSQL

protected String selectAggregateSQL(String function,
                                    AttributeDescriptor att,
                                    SimpleFeatureType featureType,
                                    Query query)
Generates a 'SELECT () FROM' statement.


selectAggregateSQLPS

protected PreparedStatement selectAggregateSQLPS(String function,
                                                 AttributeDescriptor att,
                                                 SimpleFeatureType featureType,
                                                 Query query,
                                                 Connection cx)
                                          throws SQLException
Generates a 'SELECT () FROM' prepared statement.

Throws:
SQLException

encodeFunction

protected void encodeFunction(String function,
                              AttributeDescriptor att,
                              Query query,
                              StringBuffer sql)

deleteSQL

protected String deleteSQL(SimpleFeatureType featureType,
                           Filter filter)
Generates a 'DELETE FROM' sql statement.


deleteSQLPS

protected PreparedStatement deleteSQLPS(SimpleFeatureType featureType,
                                        Filter filter,
                                        Connection cx)
                                 throws SQLException
Generates a 'DELETE FROM' prepared statement.

Throws:
SQLException

insertSQL

protected String insertSQL(SimpleFeatureType featureType,
                           SimpleFeature feature,
                           List keyValues,
                           Connection cx)
Generates a 'INSERT INFO' sql statement.

Throws:
IOException

getColumnNames

protected LinkedHashSet<String> getColumnNames(PrimaryKey key)
Returns the set of the primary key column names. The set is guaranteed to have the same iteration order as the primary key.

Parameters:
key -

insertSQLPS

protected PreparedStatement insertSQLPS(SimpleFeatureType featureType,
                                        SimpleFeature feature,
                                        List keyValues,
                                        Connection cx)
                                 throws IOException,
                                        SQLException
Generates a 'INSERT INFO' prepared statement.

Throws:
IOException
SQLException

getGeometrySRID

protected int getGeometrySRID(Geometry g,
                              AttributeDescriptor descriptor)
                       throws IOException
Looks up the geometry srs by trying a number of heuristics. Returns -1 if all attempts at guessing the srid failed.

Throws:
IOException

getDescriptorSRID

protected int getDescriptorSRID(AttributeDescriptor descriptor)
Extracts the eventual native SRID user property from the descriptor, returns -1 if not found

Parameters:
descriptor -

updateSQL

protected String updateSQL(SimpleFeatureType featureType,
                           AttributeDescriptor[] attributes,
                           Object[] values,
                           Filter filter)
                    throws IOException
Generates an 'UPDATE' sql statement.

Throws:
IOException

updateSQLPS

protected PreparedStatement updateSQLPS(SimpleFeatureType featureType,
                                        AttributeDescriptor[] attributes,
                                        Object[] values,
                                        Filter filter,
                                        Connection cx)
                                 throws IOException,
                                        SQLException
Generates an 'UPDATE' prepared statement.

Throws:
IOException
SQLException

createFilterToSQL

protected FilterToSQL createFilterToSQL(SimpleFeatureType featureType)
Creates a new instance of a filter to sql encoder.

The featureType may be null but it is not recommended. Such a case where this may neccessary is when a literal needs to be encoded in isolation.


createPreparedFilterToSQL

protected PreparedFilterToSQL createPreparedFilterToSQL(SimpleFeatureType featureType)
Creates a new instance of a filter to sql encoder to be used in a prepared statement.


initializeFilterToSQL

protected <F extends FilterToSQL> F initializeFilterToSQL(F toSQL,
                                                          SimpleFeatureType featureType)
Helper method to initialize a filter encoder instance.


encodeTableName

protected void encodeTableName(String tableName,
                               StringBuffer sql)
Helper method to encode table name which checks if a schema is set and prefixes the table name with it.


setGmlProperties

protected void setGmlProperties(Geometry g,
                                String gid,
                                String name,
                                String description)
Helper method for setting the gml:id of a geometry as user data.


closeSafe

public void closeSafe(ResultSet rs)
Utility method for closing a result set.

This method closed the result set "safely" in that it never throws an exception. Any exceptions that do occur are logged at Level.FINER.

Parameters:
rs - The result set to close.

closeSafe

public void closeSafe(Statement st)
Utility method for closing a statement.

This method closed the statement"safely" in that it never throws an exception. Any exceptions that do occur are logged at Level.FINER.

Parameters:
st - The statement to close.

closeSafe

public void closeSafe(Connection cx)
Utility method for closing a connection.

This method closed the connection "safely" in that it never throws an exception. Any exceptions that do occur are logged at Level.FINER.

Parameters:
cx - The connection to close.

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throws:
Throwable

dispose

public void dispose()
Description copied from interface: DataAccess
Disposes of this data store and releases any resource that it is using.

A DataStore cannot be used after dispose has been called, neither can any data access object it helped create, such as FeatureReader, FeatureSource or FeatureCollection.

This operation can be called more than once without side effects.

There is no thread safety assurance associated with this method. For example, client code will have to make sure this method is not called while retrieving/saving data from/to the storage, or be prepared for the consequences.

Specified by:
dispose in interface DataAccess<SimpleFeatureType,SimpleFeature>
Overrides:
dispose in class ContentDataStore

isGeneralizationRequired

protected boolean isGeneralizationRequired(Hints hints,
                                           GeometryDescriptor gatt)
Checks if geometry generalization required and makes sense

Parameters:
hints - hints hints passed in
gatt - Geometry attribute descriptor
Returns:
true to indicate generalization

isSimplificationRequired

protected boolean isSimplificationRequired(Hints hints,
                                           GeometryDescriptor gatt)
Checks if geometry simplification required and makes sense

Parameters:
hints - hints hints passed in
gatt - Geometry attribute descriptor
Returns:
true to indicate simplification

isGeometryReduceRequired

protected boolean isGeometryReduceRequired(Hints hints,
                                           GeometryDescriptor gatt,
                                           Hints.Key param)
Checks if reduction required and makes sense

Parameters:
hints - hints passed in
gatt - Geometry attribute descriptor
param - Hints.GEOMETRY_GENERALIZATION or Hints.GEOMETRY_SIMPLIFICATION
Returns:
true to indicate reducing the geometry, false otherwise

encodeGeometryColumn

protected void encodeGeometryColumn(GeometryDescriptor gatt,
                                    StringBuffer sql,
                                    Hints hints)
Encoding a geometry column with respect to hints Supported Hints are provided by SQLDialect.addSupportedHints(Set)

Parameters:
gatt -
sql -
hints - , may be null

buildTransaction

public Transaction buildTransaction(Connection cx)
Builds a transaction object around a user provided connection. The returned transaction allows the store to work against an externally managed transaction, such as in J2EE enviroments. It is the duty of the caller to ensure the connection is to the same database managed by this JDBCDataStore. Calls to Transaction.commit(), Transaction.rollback() and Transaction.close() will not result in corresponding calls to the provided Connection object.

Parameters:
conn - The externally managed connection


Copyright © 1996-2010 Geotools. All Rights Reserved.