org.geotools.data.mysql
Class MySQLDataStore

java.lang.Object
  extended by org.geotools.data.jdbc.JDBC1DataStore
      extended by org.geotools.data.jdbc.JDBC2DataStore
          extended by org.geotools.data.jdbc.JDBCDataStore
              extended by org.geotools.data.mysql.MySQLDataStore
All Implemented Interfaces:
DataAccess<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature>, DataStore

public class MySQLDataStore
extends JDBCDataStore

An implementation of the GeoTools Data Store API for the MySQL database platform. The plan is to support traditional MySQL datatypes, as well as the new geometric datatypes provided with MySQL 4.1 and higher.

TODO: MySQLDataStore is not yet tested for MySQL 4.1's geometric datatypes.

Please see class JDBCDataStore and interface DataStore for DataStore usage details.

Author:
Gary Sheppard garysheppard@psu.edu, Andrea Aime aaime@users.sourceforge.net, Debasish Sahu debasish.sahu@rmsi.com

Field Summary
protected  boolean wkbEnabled
          When true wkb encoding will be used to transfer geometries over the wire
 
Fields inherited from class org.geotools.data.jdbc.JDBC2DataStore
dataSource
 
Fields inherited from class org.geotools.data.jdbc.JDBC1DataStore
allowWriteOnVolatileFIDs, config, listenerManager, sqlNameEscape, transactionIsolation, TYPE_MAPPINGS, typeHandler
 
Constructor Summary
MySQLDataStore(javax.sql.DataSource dataSource)
          Basic constructor for MySQLDataStore.
MySQLDataStore(javax.sql.DataSource dataSource, java.lang.String databaseSchemaName)
          Constructor for MySQLDataStore where the database schema name is provided.
MySQLDataStore(javax.sql.DataSource dataSource, java.lang.String databaseSchemaName, java.lang.String namespace)
          Constructor for MySQLDataStore where the database schema name is provided.
 
Method Summary
protected  org.opengis.feature.type.AttributeDescriptor buildAttributeType(java.sql.ResultSet rs)
          Constructs an AttributeType from a row in a ResultSet.
protected  JDBCFeatureWriter createFeatureWriter(FeatureReader<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> reader, QueryData queryData)
           
protected  int determineSRID(java.lang.String table, java.lang.String column)
          Provides a hook for subclasses to determine the SRID of a geometry column.
 FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureWriter(java.lang.String typeName)
          Utility method for getting a FeatureWriter for modifying existing features, using no feature filtering and auto-committing.
 FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> getFeatureWriterAppend(java.lang.String typeName)
          Utility method for getting a FeatureWriter for adding new features, using auto-committing.
static java.lang.Class getGeomClass(java.lang.String type)
          Returns the geomoty class associated with the string passed in or null
protected  AttributeIO getGeometryAttributeIO(org.opengis.feature.type.AttributeDescriptor type, QueryData queryData)
          Hook to create the geometry attribute IO for a vendor specific data source.
static MySQLDataStore getInstance(java.lang.String host, int port, java.lang.String schema, java.lang.String username, java.lang.String password)
          Utility method for creating a MySQLDataStore from database connection parameters.
static MySQLDataStore getInstance(java.lang.String host, java.lang.String schema, java.lang.String username, java.lang.String password)
          A utility method for creating a MySQLDataStore from database connection parameters, using the default port (3306) for MySQL.
 SQLBuilder getSqlBuilder(java.lang.String typeName)
          Hook for subclass to return a different sql builder.
 java.util.Set getSupportedHints()
           
 boolean isWKBEnabled()
          Returns true if the WKB format is used to transfer geometries, false otherwise
protected  void setAutoCommit(boolean forWrite, java.sql.Connection conn)
          This method should be overridden to do nothing by DataStores where setting autoCommit causes funky behaviour (ie.
 void setWKBEnabled(boolean enabled)
          If turned on, WKB will be used to transfer geometry data instead of WKT
 
Methods inherited from class org.geotools.data.jdbc.JDBC2DataStore
createConnection, dispose, finalize
 
Methods inherited from class org.geotools.data.jdbc.JDBC1DataStore
allowTable, allSameOrder, attributeNames, buildFIDMapper, buildFIDMapperFactory, buildSchema, createFeatureReader, createLockingManager, createSchema, determineFidColumnName, executeQuery, executeQuery, getAttributeIO, getAttributeTypes, getConcurrency, getConnection, getDatabaseSchemaName, getEnvelope, getFeatureReader, getFeatureReader, getFeatureSource, getFeatureSource, getFeatureTypeHandler, getFeatureWriter, getFeatureWriter, getFeatureWriterAppend, getFIDMapper, getFIDMapperFactory, getInfo, getJDBCFeatureReader, getLockingManager, getNames, getNameSpace, getResultSetType, getSchema, getSchema, getSqlNameEscape, getTransactionIsolation, getTypeNames, getView, propertyNames, requireAutoCommit, setFIDMapper, setFIDMapperFactory, setSqlNameEscape, setTransactionIsolation, updateSchema, updateSchema
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

wkbEnabled

protected boolean wkbEnabled
When true wkb encoding will be used to transfer geometries over the wire

Constructor Detail

MySQLDataStore

public MySQLDataStore(javax.sql.DataSource dataSource)
               throws java.io.IOException
Basic constructor for MySQLDataStore. be done similar to the following:

Parameters:
dataSource - A source of connections for this datastore
Throws:
java.io.IOException - if the database cannot be properly accessed
See Also:
DataSource, MySQLConnectionFactory

MySQLDataStore

public MySQLDataStore(javax.sql.DataSource dataSource,
                      java.lang.String databaseSchemaName)
               throws java.io.IOException
Constructor for MySQLDataStore where the database schema name is provided.

Parameters:
dataSource - A source of connections for this datastore
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

MySQLDataStore

public MySQLDataStore(javax.sql.DataSource dataSource,
                      java.lang.String databaseSchemaName,
                      java.lang.String namespace)
               throws java.io.IOException
Constructor for MySQLDataStore where the database schema name is provided.

Parameters:
dataSource - A source of connections for this datastore
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

getInstance

public static MySQLDataStore getInstance(java.lang.String host,
                                         java.lang.String schema,
                                         java.lang.String username,
                                         java.lang.String password)
                                  throws java.io.IOException,
                                         java.sql.SQLException
A utility method for creating a MySQLDataStore from database connection parameters, using the default port (3306) for MySQL.

Parameters:
host - the host name or IP address of the database server
schema - the name of the database instance
username - the database username
password - the password corresponding to username
Returns:
a MySQLDataStore for the specified parameters
Throws:
java.io.IOException
java.sql.SQLException

getInstance

public static MySQLDataStore getInstance(java.lang.String host,
                                         int port,
                                         java.lang.String schema,
                                         java.lang.String username,
                                         java.lang.String password)
                                  throws java.io.IOException,
                                         java.sql.SQLException
Utility method for creating a MySQLDataStore from database connection parameters.

Parameters:
host - the host name or IP address of the database server
port - the port number of the database
schema - the name of the database instance
username - the database username
password - the password corresponding to username
Throws:
java.io.IOException - if the MySQLDataStore cannot be created because the database cannot be properly accessed
java.sql.SQLException - if a MySQL connection pool cannot be established

getFeatureWriter

public FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> 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

getFeatureWriterAppend

public FeatureWriter<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> 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 org.opengis.feature.type.AttributeDescriptor 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. NOTE: the srid of the features stored is used to build an CRS assuming that it an ESPG srid
java.io.IOException - If an error occurs processing the ResultSet.

getGeomClass

public static java.lang.Class getGeomClass(java.lang.String type)
Returns the geomoty class associated with the string passed in or null


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.

Subclasses requiring a ClientTransactionAccessor should override and instantiate an SQLBuilder with one in the constructor.

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(org.opengis.feature.type.AttributeDescriptor 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 AttributeDescriptor 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.JDBCDataStore#getGeometryAttributeIO(org.geotools.feature.AttributeType)

createFeatureWriter

protected JDBCFeatureWriter createFeatureWriter(FeatureReader<org.opengis.feature.simple.SimpleFeatureType,org.opengis.feature.simple.SimpleFeature> reader,
                                                QueryData queryData)
                                         throws java.io.IOException
Overrides:
createFeatureWriter in class JDBC1DataStore
Throws:
java.io.IOException

getSupportedHints

public java.util.Set getSupportedHints()
Overrides:
getSupportedHints in class JDBC1DataStore

setAutoCommit

protected void setAutoCommit(boolean forWrite,
                             java.sql.Connection conn)
                      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
Throws:
java.sql.SQLException

isWKBEnabled

public boolean isWKBEnabled()
Returns true if the WKB format is used to transfer geometries, false otherwise


setWKBEnabled

public void setWKBEnabled(boolean enabled)
If turned on, WKB will be used to transfer geometry data instead of WKT

Parameters:
enabled -

determineSRID

protected int determineSRID(java.lang.String table,
                            java.lang.String column)
                     throws java.io.IOException
Description copied from class: JDBC1DataStore
Provides a hook for subclasses to determine the SRID of a geometry column.

This allows SRIDs to be determined in a Vendor specific way and to be cached by the default implementation. To retreive these srids, get the FeatureTypeInfo object for the table and call getSRID(geometryColumnName). This will allow storage of SRIDs for multiple geometry columns in each table.

If no SRID can be found, subclasses should return -1. The default implementation always returns -1.

Overrides:
determineSRID in class JDBC1DataStore
Parameters:
table - The name of the table to get the SRID for.
column - The name of the geometry column within the table to get SRID for.
Returns:
The SRID for the geometry column in the table or -1.
Throws:
java.io.IOException


Copyright © 1996-2010 Geotools. All Rights Reserved.