org.geotools.data.jdbc
Class JDBCTextFeatureWriter

java.lang.Object
  extended byorg.geotools.data.jdbc.JDBCFeatureWriter
      extended byorg.geotools.data.jdbc.JDBCTextFeatureWriter
All Implemented Interfaces:
FeatureWriter
Direct Known Subclasses:
DB2FeatureWriter, GeometrylessFeatureWriter, HsqlFeatureWriter, MySQLFeatureWriter, OracleFeatureWriter, PostgisFeatureWriter

public abstract class JDBCTextFeatureWriter
extends JDBCFeatureWriter

An abstract class that uses sql statements to insert, update and delete features from the database. Useful when the resultset got from the database is not updatable, for example.

Version:
$Id: JDBCTextFeatureWriter.java 17701 2006-01-23 00:00:51Z desruisseaux $
Author:
Andrea Aime
Task:
TODO: Use prepared statements for inserts. Jody says that oracle at least will perform faster, and I imagine postgis will too. This will require a bit of rearchitecture, since the statement should just be made once, right now even if there were many features coming in they would all have to make a new prepared statement - should be able to do it before and then just fill it up for each feature. And for oracle Jody has some convenience methods in his SDO stuff that works with prepared statements and STRUCTS directly. See http://jira.codehaus.org/browse/GEOT-219 (close when done).

Field Summary
 
Fields inherited from class org.geotools.data.jdbc.JDBCFeatureWriter
closed, current, fidAttributes, listenerManager, live, queryData, reader
 
Constructor Summary
JDBCTextFeatureWriter(FeatureReader fReader, QueryData queryData)
          Creates a new instance of JDBCFeatureWriter
 
Method Summary
protected  java.lang.String addQuotes(java.lang.Object value)
          Adds quotes to an object for storage in postgis.
protected  void doInsert(MutableFIDFeature current)
          Override that uses sql statements to perform the operation.
protected  void doUpdate(Feature live, Feature current)
          Override that uses sql statements to perform the operation.
protected  java.lang.String encodeColumnName(java.lang.String colName)
          Encodes the colName, default just calls encodeName(String).
protected  java.lang.String encodeName(java.lang.String tableName)
          Encodes the tableName, default is to do nothing, but postgis will override and put double quotes around the tablename.
protected abstract  java.lang.String getGeometryInsertText(com.vividsolutions.jts.geom.Geometry geom, int srid)
          Turns a geometry into the textual version needed for the sql statement
protected  java.lang.String makeDeleteSql(Feature feature)
          Generates the query for the sql delete statement
protected  java.lang.String makeInsertSql(Feature feature)
          Creates a sql insert statement.
protected  java.lang.String makeUpdateSql(Feature live, Feature current)
          Generate the update sql statement
 void remove()
          Override that uses sql statements to perform the operation.
protected  boolean useQueryDataForInsert()
          This version does not use QueryData udpate/insert/remove methods, but uses separate queries instead
 
Methods inherited from class org.geotools.data.jdbc.JDBCFeatureWriter
close, getFeatureType, hasNext, next, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCTextFeatureWriter

public JDBCTextFeatureWriter(FeatureReader fReader,
                             QueryData queryData)
                      throws java.io.IOException
Creates a new instance of JDBCFeatureWriter

Parameters:
fReader -
queryData -
Throws:
java.io.IOException
Method Detail

doInsert

protected void doInsert(MutableFIDFeature current)
                 throws java.io.IOException,
                        java.sql.SQLException
Override that uses sql statements to perform the operation.

Overrides:
doInsert in class JDBCFeatureWriter
Parameters:
current -
Throws:
java.sql.SQLException
java.io.IOException
See Also:
JDBCFeatureWriter.doInsert(org.geotools.data.jdbc.MutableFIDFeature)

makeInsertSql

protected java.lang.String makeInsertSql(Feature feature)
                                  throws java.io.IOException
Creates a sql insert statement. Uses each feature's schema, which makes it possible to insert out of order, as well as inserting less than all features.

Parameters:
feature - the feature to add.
Returns:
an insert sql statement.
Throws:
java.io.IOException

addQuotes

protected java.lang.String addQuotes(java.lang.Object value)
Adds quotes to an object for storage in postgis. The object should be a string or a number. To perform an insert strings need quotes around them, and numbers work fine with quotes, so this method can be called on unknown objects.

Parameters:
value - The object to add quotes to.
Returns:
a string representation of the object with quotes.

encodeName

protected java.lang.String encodeName(java.lang.String tableName)
Encodes the tableName, default is to do nothing, but postgis will override and put double quotes around the tablename.


encodeColumnName

protected java.lang.String encodeColumnName(java.lang.String colName)
Encodes the colName, default just calls encodeName(String).


getGeometryInsertText

protected abstract java.lang.String getGeometryInsertText(com.vividsolutions.jts.geom.Geometry geom,
                                                          int srid)
                                                   throws java.io.IOException
Turns a geometry into the textual version needed for the sql statement

Parameters:
geom -
srid -
Returns:
Throws:
java.io.IOException

remove

public void remove()
            throws java.io.IOException
Override that uses sql statements to perform the operation.

Specified by:
remove in interface FeatureWriter
Overrides:
remove in class JDBCFeatureWriter
Throws:
java.io.IOException
See Also:
FeatureWriter.remove()

makeDeleteSql

protected java.lang.String makeDeleteSql(Feature feature)
                                  throws java.io.IOException
Generates the query for the sql delete statement

Parameters:
feature -
Returns:
Throws:
java.io.IOException

doUpdate

protected void doUpdate(Feature live,
                        Feature current)
                 throws java.io.IOException,
                        java.sql.SQLException
Override that uses sql statements to perform the operation.

Overrides:
doUpdate in class JDBCFeatureWriter
Throws:
java.io.IOException
java.sql.SQLException
See Also:
JDBCFeatureWriter.doUpdate(org.geotools.feature.Feature, org.geotools.feature.Feature)

makeUpdateSql

protected java.lang.String makeUpdateSql(Feature live,
                                         Feature current)
                                  throws java.io.IOException
Generate the update sql statement

Parameters:
live -
current -
Returns:
Throws:
java.io.IOException

useQueryDataForInsert

protected boolean useQueryDataForInsert()
This version does not use QueryData udpate/insert/remove methods, but uses separate queries instead

Overrides:
useQueryDataForInsert in class JDBCFeatureWriter
Returns:
See Also:
JDBCFeatureWriter.useQueryDataForInsert()


Copyright © GeoTools. All Rights Reserved.