[Schmitzm-commits] r550 - branches/1.0-gt2-2.6/src/schmitzm/geotools/feature

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Nov 23 14:37:53 CET 2009


Author: alfonx
Date: 2009-11-23 14:37:51 +0100 (Mon, 23 Nov 2009)
New Revision: 550

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
Log:
Added closing FeatureIterators in three cases


Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-11-23 13:30:15 UTC (rev 549)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-11-23 13:37:51 UTC (rev 550)
@@ -324,9 +324,13 @@
 			result = new Vector<Geometry>();
 
 		FeatureIterator<SimpleFeature> fi = fc.features();
-		for (; fi.hasNext();) {
-			SimpleFeature f = fi.next();
-			result.add((Geometry) f.getDefaultGeometry());
+		try {
+			for (; fi.hasNext();) {
+				SimpleFeature f = fi.next();
+				result.add((Geometry) f.getDefaultGeometry());
+			}
+		} finally {
+			fc.close(fi);
 		}
 		return result;
 	}
@@ -523,10 +527,15 @@
 		// Naiv alle Features durchgehen.
 		Vector<SimpleFeature> fv = new Vector<SimpleFeature>();
 		FeatureIterator<SimpleFeature> fi = fc.features();
-		for (int i = 0; fi.hasNext(); i++) {
-			SimpleFeature f = fi.next();
-			if (includeNullFeatures || f != null)
-				fv.add(f);
+		try {
+
+			for (int i = 0; fi.hasNext(); i++) {
+				SimpleFeature f = fi.next();
+				if (includeNullFeatures || f != null)
+					fv.add(f);
+			}
+		} finally {
+			fc.close(fi);
 		}
 		return fv.toArray(new SimpleFeature[0]);
 	}
@@ -783,11 +792,11 @@
 		// Neue Collection erstellen
 		FeatureCollection<SimpleFeatureType, SimpleFeature> resultFc = DefaultFeatureCollections
 				.newCollection();
+
 		FeatureIterator<SimpleFeature> fi = fc.features();
-		// Array fuer die Attribut-Werte eines Features
-
 		try {
 
+			// Array fuer die Attribut-Werte eines Features
 			List<Object> fValues = new ArrayList<Object>(resultType
 					.getAttributeCount());
 			for (; fi.hasNext();) {
@@ -928,44 +937,54 @@
 				// Passende Features in 2. Colletion suchen
 				filter.setAttributeName(joinAttr2);
 				filter.setCompareValue(f1.getAttribute(joinAttr1));
-				FeatureIterator<SimpleFeature> joinedFeatures = fc2
-						.subCollection(filter).features();
+				FeatureCollection<SimpleFeatureType, SimpleFeature> filteredCollection = fc2
+						.subCollection(filter);
+				FeatureIterator<SimpleFeature> joinedFeaturesIterator = filteredCollection
+						.features();
+				try {
 
-				// Wenn LEFT-OUTER-JOIN und JOIN nicht erfolgreich, ein Dummy
-				// SimpleFeature mit Default-Werten in die Collection einfuegen
-				// Sonst: JOIN-Paare "normal" bilden
-				if (!joinedFeatures.hasNext()
-						&& joinType == JoinType.LEFT_OUTER) {
-					if (!projection)
-						getDefaultAttributeValues(fType2, fValues, fType1
-								.getAttributeCount());
-					else
-						getDefaultAttributeValues(fType2, fValues, 0, projAttr);
-					// Erweitertes SimpleFeature erzeugen und FeatureCollection
-					// fuellen
-					resultFc.add(createFeature(resultType, fValues));
-				} else {
-					for (SimpleFeature f2 = null; joinedFeatures.hasNext();) {
-						f2 = joinedFeatures.next();
-						// Werte der 2. Features in Array schreiben
+					// Wenn LEFT-OUTER-JOIN und JOIN nicht erfolgreich, ein
+					// Dummy
+					// SimpleFeature mit Default-Werten in die Collection
+					// einfuegen
+					// Sonst: JOIN-Paare "normal" bilden
+					if (!joinedFeaturesIterator.hasNext()
+							&& joinType == JoinType.LEFT_OUTER) {
 						if (!projection)
-							getAttributeValues(f2, fValues, fType1
+							getDefaultAttributeValues(fType2, fValues, fType1
 									.getAttributeCount());
 						else
-							getAttributeValues(f2, fValues, 0, projAttr);
+							getDefaultAttributeValues(fType2, fValues, 0,
+									projAttr);
 						// Erweitertes SimpleFeature erzeugen und
 						// FeatureCollection
 						// fuellen
-						SimpleFeature feature = createFeature(resultType,
-								fValues);
-						resultFc.add(feature);
+						resultFc.add(createFeature(resultType, fValues));
+					} else {
+						for (SimpleFeature f2 = null; joinedFeaturesIterator
+								.hasNext();) {
+							f2 = joinedFeaturesIterator.next();
+							// Werte der 2. Features in Array schreiben
+							if (!projection)
+								getAttributeValues(f2, fValues, fType1
+										.getAttributeCount());
+							else
+								getAttributeValues(f2, fValues, 0, projAttr);
+							// Erweitertes SimpleFeature erzeugen und
+							// FeatureCollection
+							// fuellen
+							SimpleFeature feature = createFeature(resultType,
+									fValues);
+							resultFc.add(feature);
+						}
 					}
+				} finally {
+					filteredCollection.close(joinedFeaturesIterator);
 				}
 			}
 		} finally {
 			fc1.close(fi);
 		}
-		;
 
 		return resultFc;
 	}
@@ -1885,7 +1904,6 @@
 				return fc;
 
 			FeatureIterator<SimpleFeature> fIt = fc.features();
-
 			try {
 				SimpleFeature onlyFeature = fIt.next();
 



More information about the Schmitzm-commits mailing list