org.geotools.data.jdbc
Class JDBCPSFeatureWriter

java.lang.Object
  extended byorg.geotools.data.jdbc.JDBCFeatureWriter
      extended byorg.geotools.data.jdbc.JDBCPSFeatureWriter
All Implemented Interfaces:
FeatureWriter

public abstract class JDBCPSFeatureWriter
extends JDBCFeatureWriter

An abstract class that uses prepared statements to insert, update and delete features from the database. Useful when the resultset got from the database is not updatable, and to get peak performance thru the use of prepared statements and batch updates.

Assumptions made by the code:

Author:
Andrea Aime

Field Summary
 
Fields inherited from class org.geotools.data.jdbc.JDBCFeatureWriter
closed, current, fidAttributes, listenerManager, live, queryData, reader
 
Constructor Summary
JDBCPSFeatureWriter(FeatureReader fReader, QueryData queryData)
          Creates a new instance of JDBCFeatureWriter
 
Method Summary
 void close()
          Release the underlying resources.
protected  java.sql.PreparedStatement createDeleteStatement(java.sql.Connection conn, FeatureType featureType)
          Creates the prepared statement for feature deletes
protected  java.sql.PreparedStatement createInsertStatement(java.sql.Connection conn, FeatureType featureType)
          Creates the prepared statement for feature inserts
protected  java.sql.PreparedStatement createUpdateStatement(java.sql.Connection conn, FeatureType featureType)
          Creates the prepared statement for feature updates
protected  void doInsert(MutableFIDFeature current)
          Override that uses prepared statements to perform the operation.
protected  void doUpdate(Feature live, Feature current)
          Override that uses sql statements to perform the operation.
protected abstract  java.lang.String getGeometryPlaceHolder(AttributeType type)
          Returns the placeholder for the geometry in the insert/update statement.
protected  void remove(MutableFIDFeature current)
          Override that uses prepared statements to perform the operation.
protected  boolean useQueryDataForInsert()
          This version does not use QueryData udpate/insert/remove methods, but uses separate prepared statements instead
 
Methods inherited from class org.geotools.data.jdbc.JDBCFeatureWriter
getFeatureType, hasNext, next, remove, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCPSFeatureWriter

public JDBCPSFeatureWriter(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 prepared 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)

createInsertStatement

protected java.sql.PreparedStatement createInsertStatement(java.sql.Connection conn,
                                                           FeatureType featureType)
                                                    throws java.sql.SQLException
Creates the prepared statement for feature inserts

Parameters:
conn -
featureType -
Returns:
Throws:
java.sql.SQLException

getGeometryPlaceHolder

protected abstract java.lang.String getGeometryPlaceHolder(AttributeType type)
Returns the placeholder for the geometry in the insert/update statement. May be something like "?", "geomFromBinary(?)" and so on, that is, the geometry itself of some function that turns whatever the geometric AttributeIO generates into a geometry for the database.

Parameters:
type -
Returns:

remove

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

Throws:
java.io.IOException
java.sql.SQLException
See Also:
JDBCFeatureWriter.doInsert(org.geotools.data.jdbc.MutableFIDFeature)

createDeleteStatement

protected java.sql.PreparedStatement createDeleteStatement(java.sql.Connection conn,
                                                           FeatureType featureType)
                                                    throws java.sql.SQLException
Creates the prepared statement for feature deletes

Parameters:
conn -
featureType -
Returns:
Throws:
java.sql.SQLException

createUpdateStatement

protected java.sql.PreparedStatement createUpdateStatement(java.sql.Connection conn,
                                                           FeatureType featureType)
                                                    throws java.sql.SQLException
Creates the prepared statement for feature updates

Parameters:
conn -
featureType -
Returns:
Throws:
java.sql.SQLException

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)

useQueryDataForInsert

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

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

close

public void close()
           throws java.io.IOException
Description copied from interface: FeatureWriter
Release the underlying resources.

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


Copyright © GeoTools. All Rights Reserved.