Permalink
Browse files

Close iterators left open by CollectionDataStore getCount and getBoun…

…ds methods as per GEOT-4306
  • Loading branch information...
1 parent a534e45 commit 3a6ff056da52fc99cb646f458f17be9eebe102de @jodygarnett jodygarnett committed Nov 7, 2012
@@ -20,6 +20,7 @@
import org.geotools.data.AbstractDataStore;
import org.geotools.data.DataSourceException;
+import org.geotools.data.DataUtilities;
import org.geotools.data.FeatureReader;
import org.geotools.data.Query;
import org.geotools.data.SchemaNotFoundException;
@@ -136,24 +137,27 @@ protected ReferencedEnvelope getBounds(Query query) throws SchemaNotFoundExcepti
* @param query
*/
protected ReferencedEnvelope getBoundsInternal(Query query) {
- FeatureIterator<SimpleFeature> iterator = collection.features();
ReferencedEnvelope envelope = new ReferencedEnvelope( featureType.getCoordinateReferenceSystem() );
-
- if (iterator.hasNext()) {
- int count = 1;
- Filter filter = query.getFilter();
-
- while (iterator.hasNext() && (count < query.getMaxFeatures())) {
- SimpleFeature feature = iterator.next();
-
- if (filter.evaluate(feature)) {
- count++;
- envelope.expandToInclude(((Geometry)feature.getDefaultGeometry()).getEnvelopeInternal());
+
+ FeatureIterator<SimpleFeature> iterator = collection.features();
+ try {
+ if (iterator.hasNext()) {
+ int count = 1;
+ Filter filter = query.getFilter();
+
+ while (iterator.hasNext() && (count < query.getMaxFeatures())) {
+ SimpleFeature feature = iterator.next();
+ if (filter.evaluate(feature)) {
+ count++;
+ envelope.expandToInclude(((Geometry)feature.getDefaultGeometry()).getEnvelopeInternal());
+ }
}
}
}
- return envelope;
-
+ finally {
+ iterator.close();
+ }
+ return envelope;
}
/**
@@ -165,17 +169,19 @@ protected int getCount(Query query)
if (!featureType.getTypeName().equals(featureTypeName)) {
throw new SchemaNotFoundException(featureTypeName);
}
- int count = 0;
- FeatureIterator<SimpleFeature> iterator = collection.features();
-
+ int count = 0;
+ FeatureIterator<SimpleFeature> iterator = collection.features();
+ try {
Filter filter = query.getFilter();
-
while (iterator.hasNext() && (count < query.getMaxFeatures())) {
if (filter.evaluate(iterator.next())) {
count++;
}
}
-
- return count;
+ }
+ finally {
+ iterator.close();
+ }
+ return count;
}
}

0 comments on commit 3a6ff05

Please sign in to comment.