org.geotools.data.jdbc
Class JDBCPSFeatureWriter

Object
  extended by JDBCFeatureWriter
      extended by JDBCPSFeatureWriter
All Implemented Interfaces:
FeatureWriter<SimpleFeatureType,SimpleFeature>

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
Module:
trunk/gt/modules   (gt-modules.jar) (Maven report) (SVN head)

Field Summary
protected  FIDMapper mapper
           
 
Fields inherited from class JDBCFeatureWriter
closed, current, fidAttributes, live, queryData, reader
 
Constructor Summary
JDBCPSFeatureWriter(FeatureReader<SimpleFeatureType,SimpleFeature> fReader, QueryData queryData)
          Creates a new instance of JDBCFeatureWriter
 
Method Summary
 void close()
          Release the underlying resources.
protected  PreparedStatement createDeleteStatement(Connection conn, SimpleFeatureType featureType)
          Creates the prepared statement for feature deletes
protected  PreparedStatement createInsertStatement(Connection conn, SimpleFeatureType featureType)
          Creates the prepared statement for feature inserts
protected  PreparedStatement createUpdateStatement(Connection conn, SimpleFeatureType 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(SimpleFeature live, SimpleFeature current)
          Override that uses sql statements to perform the operation.
protected  void executeInsert(PreparedStatement insertStatement)
          Hook for subclasses to use a specific execution mechanism other than the default insertStatement.executeUpdate().
protected abstract  String getGeometryPlaceHolder(AttributeDescriptor type)
          Returns the placeholder for the geometry in the insert/update statement.
protected  PreparedStatement prepareInsertStatement(Connection conn, StringBuffer statementSQL, SimpleFeatureType featureType)
          Provides a hook for subclasses to fine tune the creation of the prepared 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 JDBCFeatureWriter
encodeColumnName, encodeName, getFeatureType, hasNext, next, remove, write
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mapper

protected final FIDMapper mapper
Constructor Detail

JDBCPSFeatureWriter

public JDBCPSFeatureWriter(FeatureReader<SimpleFeatureType,SimpleFeature> fReader,
                           QueryData queryData)
                    throws IOException
Creates a new instance of JDBCFeatureWriter

Parameters:
fReader -
queryData -
Throws:
IOException
Method Detail

doInsert

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

Overrides:
doInsert in class JDBCFeatureWriter
Throws:
IOException
SQLException
See Also:
JDBCFeatureWriter.doInsert(org.geotools.data.jdbc.MutableFIDFeature)

executeInsert

protected void executeInsert(PreparedStatement insertStatement)
                      throws IOException
Hook for subclasses to use a specific execution mechanism other than the default insertStatement.executeUpdate().

Override may be needed in some cases, for example, where the execution expects a ResultSet containing the autogenerated primary key.

Parameters:
insertStatement - the insert statement prepared in doInsert(MutableFIDFeature)
Throws:
IOException

createInsertStatement

protected PreparedStatement createInsertStatement(Connection conn,
                                                  SimpleFeatureType featureType)
                                           throws SQLException
Creates the prepared statement for feature inserts

Parameters:
conn -
featureType -
Throws:
SQLException

prepareInsertStatement

protected PreparedStatement prepareInsertStatement(Connection conn,
                                                   StringBuffer statementSQL,
                                                   SimpleFeatureType featureType)
                                            throws SQLException
Provides a hook for subclasses to fine tune the creation of the prepared statement.

This default implementation just creates the statement with the given connetion and the insert request built at createInsertStatement(java.sql.Connection, org.opengis.feature.simple.SimpleFeatureType)

Parameters:
conn -
statementSQL -
featureType -
Returns:
Throws:
SQLException

getGeometryPlaceHolder

protected abstract String getGeometryPlaceHolder(AttributeDescriptor 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 -

remove

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

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

createDeleteStatement

protected PreparedStatement createDeleteStatement(Connection conn,
                                                  SimpleFeatureType featureType)
                                           throws SQLException
Creates the prepared statement for feature deletes

Parameters:
conn -
featureType -
Throws:
SQLException

createUpdateStatement

protected PreparedStatement createUpdateStatement(Connection conn,
                                                  SimpleFeatureType featureType)
                                           throws SQLException
Creates the prepared statement for feature updates

Parameters:
conn -
featureType -
Throws:
SQLException

doUpdate

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

Overrides:
doUpdate in class JDBCFeatureWriter
Throws:
IOException
SQLException
See Also:
org.geotools.data.jdbc.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
See Also:
JDBCFeatureWriter.useQueryDataForInsert()

close

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

Specified by:
close in interface FeatureWriter<SimpleFeatureType,SimpleFeature>
Overrides:
close in class JDBCFeatureWriter
Throws:
IOException - if there there are problems releasing underlying resources, or possibly if close has been called (up to the implementation).
See Also:
FeatureWriter.close()


Copyright © 1996-2009 Geotools. All Rights Reserved.