org.geotools.data.hsql
Class HsqlDataStore

java.lang.Object
  extended byorg.geotools.data.jdbc.JDBC1DataStore
      extended byorg.geotools.data.hsql.HsqlDataStore
All Implemented Interfaces:
DataStore

public class HsqlDataStore
extends JDBC1DataStore
implements DataStore

An implementation of the GeoTools Data Store API for the HSQL database platform.
Please see class JDBC1DataStore and interface DataStore for DataStore usage details.

Author:
Amr Alam, Refractions Research, aalam@refractions.net

Field Summary
 
Fields inherited from class org.geotools.data.jdbc.JDBC1DataStore
allowWriteOnVolatileFIDs, config, listenerManager, sqlNameEscape, TYPE_MAPPINGS, typeHandler
 
Constructor Summary
HsqlDataStore(HsqlConnectionFactory connectionFactory)
          Basic constructor for HsqlDataStore.
HsqlDataStore(HsqlConnectionFactory connectionFactory, java.lang.String databaseSchemaName)
          Constructor for HSQLDataStore where the database schema name is provided.
HsqlDataStore(HsqlConnectionFactory connectionFactory, java.lang.String databaseSchemaName, java.lang.String namespace)
          Constructor for HSQLDataStore where the database schema name is provided.
 
Method Summary
 void addFeatures(Feature[] features)
          Convenience method to add feature to the datastore
protected  boolean allowTable(java.lang.String tablename)
          Provides a hook for sub classes to filter out specific tables in the data store that are not to be used as geospatial tables.
protected  AttributeType buildAttributeType(java.sql.ResultSet rs)
          Constructs an AttributeType from a row in a ResultSet.
protected  FIDMapperFactory buildFIDMapperFactory(JDBCDataStoreConfig config)
          Override the default FIDMapperFactory since it doesn't work well with HSQL
protected  java.sql.Connection createConnection()
          Create a connection for your JDBC1 database
protected  JDBCFeatureWriter createFeatureWriter(FeatureReader reader, QueryData queryData)
           
 void createSchema(FeatureType featureType)
          Adds support for a new featureType to HsqlDataStore.
protected  java.sql.Connection getConnection(Transaction transaction)
          Gets a connection for the provided transaction.
 FeatureReader getFeatureReader(Query query, Transaction transaction)
          Provides a featureReader over the query results using the given transaction
 FeatureReader getFeatureReader(java.lang.String typeName)
          Provides FeatureReader over the entire contents of typeName.
 FeatureWriter getFeatureWriter(java.lang.String typeName)
          Utility method for getting a FeatureWriter for modifying existing features, using no feature filtering and auto-committing.
 FeatureWriter getFeatureWriter(java.lang.String typeName, Filter filter, Transaction transaction)
          Aquire FetureWriter for modification of contents specifed by filter.
 FeatureWriter getFeatureWriterAppend(java.lang.String typeName)
          Utility method for getting a FeatureWriter for adding new features, using auto-committing.
protected  AttributeIO getGeometryAttributeIO(AttributeType type, QueryData queryData)
          Hook to create the geometry attribute IO for a vendor specific data source.
 SQLBuilder getSqlBuilder(java.lang.String typeName)
          Hook for subclass to return a different sql builder.
 void removeSchema(FeatureType featureType)
          Removes support for the featureType schema to HsqlDataStore.
protected  void setAutoCommit(boolean arg0, java.sql.Connection arg1)
          This method should be overridden to do nothing by DataStores where setting autoCommit causes funky behaviour (ie. anytime autoCommit is changed, every thing up to that point is committed...this isn't good at this stage)
 
Methods inherited from class org.geotools.data.jdbc.JDBC1DataStore
allSameOrder, attributeNames, buildSchema, createFeatureReader, createLockingManager, determineFidColumnName, determineSRID, executeQuery, getAttributeIO, getAttributeTypes, getConcurrency, getEnvelope, getFeatureReader, getFeatureSource, getFeatureTypeHandler, getFeatureWriter, getFeatureWriterAppend, getFIDMapper, getFIDMapperFactory, getJDBCFeatureReader, getLockingManager, getNameSpace, getResultSetType, getSchema, getSqlNameEscape, getTypeNames, getView, setFIDMapper, setFIDMapperFactory, setSqlNameEscape, updateSchema
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.geotools.data.DataStore
getFeatureSource, getFeatureWriter, getFeatureWriterAppend, getLockingManager, getSchema, getTypeNames, getView, updateSchema
 

Constructor Detail

HsqlDataStore

public HsqlDataStore(HsqlConnectionFactory connectionFactory)
              throws java.io.IOException
Basic constructor for HsqlDataStore. Requires creation of a HsqlConnectionFactory, which could be done similar to the following:

HsqlConnectionFactory connectionFactory = new HsqlConnectionFactory("dbFileName", "username", "password");
DataStore dataStore = new HsqlDataStore(connectionFactory);

Parameters:
connectionFactory - an HSQL HsqlConnectionFactory
Throws:
java.io.IOException - if the database cannot be properly accessed
See Also:
HsqlConnectionFactory

HsqlDataStore

public HsqlDataStore(HsqlConnectionFactory connectionFactory,
                     java.lang.String databaseSchemaName)
              throws java.io.IOException
Constructor for HSQLDataStore where the database schema name is provided.

Parameters:
connectionFactory - an HSQL HsqlConnectionFactory
databaseSchemaName - the database schema. Can be null. See the comments for the parameter schemaPattern in DatabaseMetaData.getTables, because databaseSchemaName behaves in the same way.
Throws:
java.io.IOException - if the database cannot be properly accessed

HsqlDataStore

public HsqlDataStore(HsqlConnectionFactory connectionFactory,
                     java.lang.String databaseSchemaName,
                     java.lang.String namespace)
              throws java.io.IOException
Constructor for HSQLDataStore where the database schema name is provided.

Parameters:
connectionFactory - an HSQL HsqlConnectionFactory
databaseSchemaName - the database schema. Can be null. See the comments for the parameter schemaPattern in DatabaseMetaData.getTables, because databaseSchemaName behaves in the same way.
namespace - the namespace for this data store. Can be null, in which case the namespace will simply be the schema name.
Throws:
java.io.IOException - if the database cannot be properly accessed
Method Detail

getFeatureReader

public FeatureReader getFeatureReader(java.lang.String typeName)
                               throws java.io.IOException
Provides FeatureReader over the entire contents of typeName.

Implements getFeatureReader contract for AbstractDataStore.

Parameters:
typeName -
Returns:
a featureReader
Throws:
java.io.IOException - If typeName could not be found

getFeatureReader

public FeatureReader getFeatureReader(Query query,
                                      Transaction transaction)
                               throws java.io.IOException
Provides a featureReader over the query results using the given transaction

Specified by:
getFeatureReader in interface DataStore
Overrides:
getFeatureReader in class JDBC1DataStore
Parameters:
query - the Query object we want to narrow the results down by
transaction - the transaction object to be operated on
Returns:
a featureReader based on the given query and transaction
Throws:
java.io.IOException - If an error occurs executing the query.
See Also:
JDBC1DataStore.getFeatureReader(org.geotools.data.Query, org.geotools.data.Transaction)

buildFIDMapperFactory

protected FIDMapperFactory buildFIDMapperFactory(JDBCDataStoreConfig config)
Override the default FIDMapperFactory since it doesn't work well with HSQL

Overrides:
buildFIDMapperFactory in class JDBC1DataStore
See Also:
JDBC1DataStore.buildFIDMapperFactory(org.geotools.data.jdbc.JDBCDataStoreConfig)

addFeatures

public void addFeatures(Feature[] features)
                 throws java.io.IOException
Convenience method to add feature to the datastore

Parameters:
features - an array of features that should be added to the datastore
Throws:
java.io.IOException

getFeatureWriter

public FeatureWriter getFeatureWriter(java.lang.String typeName)
                               throws java.io.IOException
Utility method for getting a FeatureWriter for modifying existing features, using no feature filtering and auto-committing. Not used for adding new features.

Parameters:
typeName - the feature type name (the table name)
Returns:
a FeatureWriter for modifying existing features
Throws:
java.io.IOException - if the database cannot be properly accessed

getFeatureWriter

public FeatureWriter getFeatureWriter(java.lang.String typeName,
                                      Filter filter,
                                      Transaction transaction)
                               throws java.io.IOException
Aquire FetureWriter for modification of contents specifed by filter.

Quick notes: This FeatureWriter is often used to remove contents specified by the provided filter, or perform summary calculations.

It is not used to provide new content and should return null for next() when hasNext() returns false.

Specified by:
getFeatureWriter in interface DataStore
Overrides:
getFeatureWriter in class JDBC1DataStore
Parameters:
typeName -
filter -
transaction -
Returns:
Throws:
java.io.IOException - If typeName could not be located
java.lang.NullPointerException - If the provided filter is null
See Also:
DataStore.getFeatureWriter(java.lang.String, org.geotools.filter.Filter, org.geotools.data.Transaction)

getFeatureWriterAppend

public FeatureWriter getFeatureWriterAppend(java.lang.String typeName)
                                     throws java.io.IOException
Utility method for getting a FeatureWriter for adding new features, using auto-committing. Not used for modifying existing features.

Parameters:
typeName - the feature type name (the table name)
Returns:
a FeatureWriter for adding new features
Throws:
java.io.IOException - if the database cannot be properly accessed

buildAttributeType

protected AttributeType buildAttributeType(java.sql.ResultSet rs)
                                    throws java.io.IOException
Constructs an AttributeType from a row in a ResultSet. The ResultSet contains the information retrieved by a call to getColumns() on the DatabaseMetaData object. This information can be used to construct an Attribute Type.

In addition to standard SQL types, this method identifies MySQL 4.1's geometric datatypes and creates attribute types accordingly. This happens when the datatype, identified by column 5 of the ResultSet parameter, is equal to java.sql.Types.OTHER. If a Types.OTHER ends up not being geometric, this method simply calls the parent class's buildAttributeType method to do something with it.

Note: Overriding methods must never move the current row pointer in the result set.

Overrides:
buildAttributeType in class JDBC1DataStore
Parameters:
rs - The ResultSet containing the result of a DatabaseMetaData.getColumns call.
Returns:
The AttributeType built from the ResultSet.
Throws:
java.sql.SQLException - If an error occurs processing the ResultSet.
DataSourceException - Provided for overriding classes to wrap exceptions caused by other operations they may perform to determine additional types. This will only be thrown by the default implementation if a type is present that is not present in the TYPE_MAPPINGS.
java.io.IOException - If an error occurs processing the ResultSet.

getSqlBuilder

public SQLBuilder getSqlBuilder(java.lang.String typeName)
                         throws java.io.IOException
Description copied from class: JDBC1DataStore
Hook for subclass to return a different sql builder.

Overrides:
getSqlBuilder in class JDBC1DataStore
Parameters:
typeName - The typename for the sql builder.
Returns:
A new sql builder.
Throws:
java.io.IOException - if anything goes wrong.
See Also:
JDBC1DataStore.getSqlBuilder(java.lang.String)

getGeometryAttributeIO

protected AttributeIO getGeometryAttributeIO(AttributeType type,
                                             QueryData queryData)
Description copied from class: JDBC1DataStore
Hook to create the geometry attribute IO for a vendor specific data source.

Specified by:
getGeometryAttributeIO in class JDBC1DataStore
Parameters:
type - The AttributeType to read.
queryData - The connection holder
Returns:
The AttributeIO that will read and write the geometry from the results.
See Also:
org.geotools.data.jdbc.JDBC1DataStore#getGeometryAttributeIO(org.geotools.feature.AttributeType)

createFeatureWriter

protected JDBCFeatureWriter createFeatureWriter(FeatureReader reader,
                                                QueryData queryData)
                                         throws java.io.IOException
Overrides:
createFeatureWriter in class JDBC1DataStore
Throws:
java.io.IOException
See Also:
JDBC1DataStore.createFeatureWriter(org.geotools.data.FeatureReader, org.geotools.data.jdbc.QueryData)

createConnection

protected java.sql.Connection createConnection()
                                        throws java.sql.SQLException
Description copied from class: JDBC1DataStore
Create a connection for your JDBC1 database

Specified by:
createConnection in class JDBC1DataStore
Throws:
java.sql.SQLException
See Also:
JDBC1DataStore.createConnection()

getConnection

protected java.sql.Connection getConnection(Transaction transaction)
                                     throws java.io.IOException
Gets a connection for the provided transaction.

Overrides:
getConnection in class JDBC1DataStore
Parameters:
transaction -
Returns:
A single use connection.
Throws:
java.io.IOException
DataSourceException - If the connection can not be obtained.

createSchema

public void createSchema(FeatureType featureType)
                  throws java.io.IOException
Adds support for a new featureType to HsqlDataStore.

FeatureTypes are stored by typeName (in this case, table name = typeName), an IOException will be thrown if the requested typeName is already in use.

Specified by:
createSchema in interface DataStore
Overrides:
createSchema in class JDBC1DataStore
Parameters:
featureType - FeatureType to be added
Throws:
java.io.IOException - If featureType already exists
See Also:
DataStore.createSchema(org.geotools.feature.FeatureType)

allowTable

protected boolean allowTable(java.lang.String tablename)
Description copied from class: JDBC1DataStore
Provides a hook for sub classes to filter out specific tables in the data store that are not to be used as geospatial tables. The default implementation of this method is to allow all tables.

Overrides:
allowTable in class JDBC1DataStore
Parameters:
tablename - A table name to check.
Returns:
True if the table should be exposed as a FeatureType, false if it should be ignored.

removeSchema

public void removeSchema(FeatureType featureType)
Removes support for the featureType schema to HsqlDataStore. (Drops the table)

FeatureTypes are stored by typeName (in this case, table name = typeName).

Parameters:
featureType - FeatureType to be removed

setAutoCommit

protected void setAutoCommit(boolean arg0,
                             java.sql.Connection arg1)
                      throws java.sql.SQLException
Description copied from class: JDBC1DataStore
This method should be overridden to do nothing by DataStores where setting autoCommit causes funky behaviour (ie. anytime autoCommit is changed, every thing up to that point is committed...this isn't good at this stage)

Overrides:
setAutoCommit in class JDBC1DataStore
Parameters:
arg0 -
arg1 -
Throws:
java.sql.SQLException


Copyright © GeoTools. All Rights Reserved.