org.geotools.data.jdbc
Class ResultSetAttributeReader

java.lang.Object
  extended byorg.geotools.data.AbstractAttributeIO
      extended byorg.geotools.data.jdbc.ResultSetAttributeReader
Direct Known Subclasses:
WKTAttributeReader

public class ResultSetAttributeReader
extends AbstractAttributeIO

An attributeReader to read a sql ResultSet. This reads all columns as objects. The AttributeTypes passed in for each column should be be as constrained as possible, having all be DefaultAttributeTypes with type Object is not very useful for clients. This should be sufficient to read most sql columns, but it will not work for geometries. Those require special mapping. A WKTAttributeReader should work for Simple Features for SQL compliant databases, but is not the most efficient way. Specialized readers should be constructed for better performance.

Keep in mind when using this that the startColumn parameter is based on ResultSet offsets, meaning that the first is at 1, not 0 as in most java arrays. This class will return the proper 0 indexed position required by read(int position).

In the simple case of one geometry and a number of other attributes, if the geometry is the last attribute then one need only construct one ResultSetAttributeReader and one GeometryAttributeReader. If the geometry is not at the end, then one will need two of these readers, one for the attributes before the geometry. If the geometry is column 5 out of 7 then you would need a reader for cols 1 to 4, a geometry reader for 5, and another one for 6 and 7. A JoiningFeatureReader should then be used. One could also construct one of these readers per column, and join them all.

Author:
Chris Holmes

Field Summary
protected  java.lang.Object[] atts
          Offset of ResultSet to normal arrays, index starts at 1, not 0
protected  java.sql.Connection connection
           
protected  int index
           
protected  java.sql.ResultSet results
           
protected  int startColumn
           
protected  Transaction transaction
           
 
Fields inherited from class org.geotools.data.AbstractAttributeIO
metaData
 
Constructor Summary
protected ResultSetAttributeReader(java.sql.ResultSet results, AttributeType[] attTypes, int startColumn, Transaction transaction, java.sql.Connection connection)
          Constructor, for a continuous array of result columns.
 
Method Summary
 void close()
           
static ResultSetAttributeReader getReader(java.sql.ResultSet results, AttributeType[] attributes, int startCol, Transaction transaction)
           
static ResultSetAttributeReader getReader(java.sql.ResultSet results, AttributeType attribute, int startCol, Transaction transaction)
           
 boolean hasNext()
           
 void next()
           
 java.lang.Object read(int position)
           
protected  java.lang.Object readColumn(int column)
           
 
Methods inherited from class org.geotools.data.AbstractAttributeIO
copy, getAttributeCount, getAttributeType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

atts

protected java.lang.Object[] atts
Offset of ResultSet to normal arrays, index starts at 1, not 0


results

protected java.sql.ResultSet results

startColumn

protected int startColumn

index

protected int index

transaction

protected Transaction transaction

connection

protected java.sql.Connection connection
Constructor Detail

ResultSetAttributeReader

protected ResultSetAttributeReader(java.sql.ResultSet results,
                                   AttributeType[] attTypes,
                                   int startColumn,
                                   Transaction transaction,
                                   java.sql.Connection connection)
Constructor, for a continuous array of result columns. If the geometry column.

Parameters:
results - The ResultSet to read attribute from.
attTypes - The array of attributeTypes corresponding to the attributes to be returned by this reader.
startColumn - the offset to start returning attributes from the resultSet. Starts at 1, corresponding to the java ResultSet way of doing things.
Method Detail

hasNext

public boolean hasNext()
                throws java.io.IOException
Throws:
java.io.IOException

next

public void next()
          throws java.io.IOException
Throws:
java.io.IOException

readColumn

protected java.lang.Object readColumn(int column)
                               throws java.io.IOException
Throws:
java.io.IOException

read

public java.lang.Object read(int position)
                      throws java.io.IOException
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

getReader

public static ResultSetAttributeReader getReader(java.sql.ResultSet results,
                                                 AttributeType[] attributes,
                                                 int startCol,
                                                 Transaction transaction)
                                          throws DataSourceException
Throws:
DataSourceException

getReader

public static ResultSetAttributeReader getReader(java.sql.ResultSet results,
                                                 AttributeType attribute,
                                                 int startCol,
                                                 Transaction transaction)
                                          throws DataSourceException
Throws:
DataSourceException


Copyright © 1996-2003 GeoTools. All Rights Reserved.