JDBCDataStore iterators violate the FeatureIterator contract ------------------------------------------------------------
Key: GEOT-3190 URL: http://jira.codehaus.org/browse/GEOT-3190 Project: GeoTools Issue Type: Bug Components: data jdbc-ng Affects Versions: 2.7-M1 Reporter: Andrea Aime Assignee: Justin Deoliveira Calling store.getFeatureSource().features().features().next() throws the following: {code} java.lang.IllegalStateException: Must call hasNext before calling next at org.geotools.jdbc.JDBCFeatureReader.ensureNext(JDBCFeatureReader.java:240) {code} Now, looking at the FeatureIterator interface there I don't see any contract asking to call hasNext() before next(): {code} /* * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package org.geotools.feature; import org.opengis.feature.Feature; /** * A drop in replacement for Iterator<Feature> supporting a close method. * * @author Ian Schneider * @source $URL$ */ public interface FeatureIterator<F extends Feature> { /** * Does another Feature exist in this Iteration. * <p> * Iterator defin: Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.) * </p> * @return true if more Features exist, false otherwise. */ public boolean hasNext(); /** * Get the next Feature in this iteration. * * @return The next Feature * * @throws java.util.NoSuchElementException If no more Features exist. */ public F next() throws java.util.NoSuchElementException; /** * Required so SimpleFeatureCollection classes can implement close( FeatureIterator<SimpleFeature> ). */ public void close(); } {code} And then looking at FeatureReader, same, I see no trace of that contract: {code} /* * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2008, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package org.geotools.data; import java.io.IOException; import java.util.NoSuchElementException; import org.opengis.feature.Feature; import org.opengis.feature.type.FeatureType; /** * The low-level interface for reading Features. Will use the underlying * AttributeReader and the given FeatureType to create new Features. * * <p> * Typical use is as follows: * <pre><code> * FeatureReader reader = null; * try{ * for( reader = data.getFeatureReader( filter ); reader.hasNext(); ){ * f = reader.next(); * ... * } * } * catch (IOException problem){ * ... * } * finally { * if( reader != null ){ * try { * reader.close(); * } * catch( IOException eek){ * } * } * } * </code></pre> * * <h2>Questions and Suggestions</h2> * <ul> * <li>Q: Should FeatureReader provide access to the AttributeReaders it uses? * <br>A: * No, it looks like we will make a lazy Feature in order to cleanly * allow for lazy parsing of attribtues. * </li> * <li>Q:FeatureReader has a close method, but no open method? * <br>A: This is by design allowing FeatureReader to encapsulate its InputStream * or Rowset). Please assume that FeatureReaders are a single use proposition. * </li> * <li>Q: All that exception handling is a pain! * A: * Yes it is, we have constructed semi-normal Java iterators to cut down on the * pain. But you *do* still have to close 'em - this is IO after all. * </li> * <li>Q: Can we include skip(int) - SeanG * A: * The order of the contents is not "known" or predicatable to the end user, so * skip( int ) would be useless. For random access (a higher order * of abstraction then FeatureReader) please look at FeatureList. * </li> * </ul> * </p> * * @author Ian Schneider * @author Sean Geoghegan, Defence Science and Technology Organisation. * @source $URL$ * @version $Id$ */ public interface FeatureReader<T extends FeatureType, F extends Feature> { /** * Return the FeatureType this reader has been configured to create. * * @return the FeatureType of the Features this FeatureReader will create. */ T getFeatureType(); /** * Reads the next Feature in the FeatureReader. * * @return The next feature in the reader. * * @throws IOException If an error occurs reading the Feature. * @throws IllegalAttributeException If the attributes read do not comply * with the FeatureType. * @throws NoSuchElementException If there are no more Features in the * Reader. */ F next() throws IOException, IllegalArgumentException, NoSuchElementException; /** * Query whether this FeatureReader has another Feature. * * @return True if there are more Features to be read. In other words, true * if calls to next would return a feature rather than throwing an * exception. * * @throws IOException If an error occurs determining if there are more * Features. */ boolean hasNext() throws IOException; /** * Release the underlying resources associated with this stream. * * @throws IOException DOCUMENT ME! */ void close() throws IOException; } {code} -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira ------------------------------------------------------------------------------ This SF.net email is sponsored by Sprint What will you do first with EVO, the first 4G phone? Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first _______________________________________________ Geotools-devel mailing list Geotools-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-devel