Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sort out jdbc module, mostly use of FeatureIterator with a few cases …

…of needing to use FeatureStore to add to a collection
  • Loading branch information...
commit 20bc02c762742921fa7096b6de0fb5265dc533fa 1 parent 6c6efd4
@jodygarnett jodygarnett authored
View
2  modules/library/jdbc/src/main/java/org/geotools/jdbc/JDBCDataStore.java
@@ -775,7 +775,7 @@ public Object getGmlObject(GmlObjectId id, Hints hints) throws IOException {
}
}
finally {
- features.close( fi );
+ fi.close();
}
}
View
3  modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCConnectionLifecycleTest.java
@@ -23,6 +23,7 @@
import org.geotools.data.DefaultTransaction;
import org.geotools.data.Query;
import org.geotools.data.Transaction;
+import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.feature.DefaultFeatureCollection;
import org.geotools.feature.simple.SimpleFeatureBuilder;
@@ -79,7 +80,7 @@ public void testListenerCalled() throws IOException {
b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(i, i)));
collection.add(b.buildFeature(null));
}
- featureStore.addFeatures(collection);
+ featureStore.addFeatures((SimpleFeatureCollection)collection);
t.commit();
assertTrue(mockListener.onBorrowCalled);
assertTrue(mockListener.onReleaseCalled);
View
75 modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCDataStoreAPITest.java
@@ -1018,9 +1018,12 @@ public void testGetFeatureStoreModifyFeatures1() throws IOException {
SimpleFeatureCollection results = road.getFeatures(td.rd1Filter);
SimpleFeatureIterator features = results.features();
- assertTrue(features.hasNext());
- assertEquals(5, ((Number)features.next().getAttribute(aname("id"))).intValue());
- results.close(features);
+ try {
+ assertTrue(features.hasNext());
+ assertEquals(5, ((Number) features.next().getAttribute(aname("id"))).intValue());
+ } finally {
+ features.close();
+ }
}
public void testGetFeatureStoreModifyFeatures2() throws IOException {
@@ -1038,9 +1041,12 @@ public void testGetFeatureStoreModifyFeatures2() throws IOException {
SimpleFeatureCollection results = road.getFeatures(td.rd1Filter);
SimpleFeatureIterator features = results.features();
- assertTrue(features.hasNext());
- assertEquals("changed", features.next().getAttribute(aname("name")));
- results.close(features);
+ try {
+ assertTrue(features.hasNext());
+ assertEquals("changed", features.next().getAttribute(aname("name")));
+ } finally {
+ features.close();
+ }
}
/**
@@ -1651,12 +1657,15 @@ public void testGeneralization() throws Exception {
return;
SimpleFeatureCollection fColl = fs.getFeatures();
- SimpleFeatureIterator iterator =fColl.features();
- Geometry original = null;
- if (iterator.hasNext())
- original = (Geometry) iterator.next().getDefaultGeometry();
- fColl.close(iterator);
-
+ SimpleFeatureIterator iterator = fColl.features();
+ Geometry original = null;
+ try {
+ if (iterator.hasNext()) {
+ original = (Geometry) iterator.next().getDefaultGeometry();
+ }
+ } finally {
+ iterator.close();
+ }
double width = original.getEnvelope().getEnvelopeInternal().getWidth();
DefaultQuery query = new DefaultQuery();
@@ -1665,11 +1674,14 @@ public void testGeneralization() throws Exception {
Geometry generalized = null;
fColl = fs.getFeatures(query);
- iterator =fColl.features();
- if (iterator.hasNext())
- generalized = (Geometry) iterator.next().getDefaultGeometry();
- fColl.close(iterator);
-
+ iterator = fColl.features();
+ try {
+ if (iterator.hasNext()) {
+ generalized = (Geometry) iterator.next().getDefaultGeometry();
+ }
+ } finally {
+ iterator.close();
+ }
assertTrue(original.getNumPoints()>=generalized.getNumPoints());
}
@@ -1680,25 +1692,30 @@ public void testSimplification() throws Exception {
return;
SimpleFeatureCollection fColl = fs.getFeatures();
- SimpleFeatureIterator iterator =fColl.features();
- Geometry original = null;
- if (iterator.hasNext())
- original = (Geometry) iterator.next().getDefaultGeometry();
- fColl.close(iterator);
-
+ SimpleFeatureIterator iterator = fColl.features();
+ Geometry original = null;
+ try {
+ if (iterator.hasNext()) {
+ original = (Geometry) iterator.next().getDefaultGeometry();
+ }
+ } finally {
+ iterator.close();
+ }
double width = original.getEnvelope().getEnvelopeInternal().getWidth();
- DefaultQuery query = new DefaultQuery();
+ Query query = new Query();
Hints hints = new Hints(Hints.GEOMETRY_SIMPLIFICATION,width/2);
query.setHints(hints);
Geometry simplified = null;
fColl = fs.getFeatures(query);
- iterator =fColl.features();
- if (iterator.hasNext())
- simplified = (Geometry) iterator.next().getDefaultGeometry();
- fColl.close(iterator);
-
+ iterator = fColl.features();
+ try {
+ if (iterator.hasNext())
+ simplified = (Geometry) iterator.next().getDefaultGeometry();
+ } finally {
+ iterator.close();
+ }
assertTrue(original.getNumPoints()>=simplified.getNumPoints());
}
}
View
8 modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCEmptyTest.java
@@ -68,9 +68,11 @@ public void testFeatureCollection() throws Exception {
assertEquals( 0, features.size() );
FeatureIterator i = features.features();
- assertFalse( i.hasNext() );
- features.close( i );
-
+ try {
+ assertFalse(i.hasNext());
+ } finally {
+ i.close();
+ }
}
}
View
59 modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCFeatureCollectionTest.java
@@ -20,7 +20,10 @@
import java.util.Iterator;
import com.vividsolutions.jts.geom.Point;
+
+import org.geotools.data.DataUtilities;
import org.geotools.data.simple.SimpleFeatureCollection;
+import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.CRS;
@@ -41,11 +44,12 @@
*/
public abstract class JDBCFeatureCollectionTest extends JDBCTestSupport {
SimpleFeatureCollection collection;
+ JDBCFeatureStore source;
protected void connect() throws Exception {
super.connect();
- JDBCFeatureStore source = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));
+ source = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));
collection = source.getFeatures();
}
@@ -92,7 +96,6 @@ public void testSubCollection() throws Exception {
SimpleFeatureCollection sub = collection.subCollection(f);
assertNotNull(sub);
-
assertEquals(1, sub.size());
ReferencedEnvelope exp = new ReferencedEnvelope(1, 1, 1, 1, CRS.decode("EPSG:4326"));
@@ -102,9 +105,6 @@ public void testSubCollection() throws Exception {
assertEquals(exp.getMinY(), act.getMinY(), 0.1);
assertEquals(exp.getMaxX(), act.getMaxX(), 0.1);
assertEquals(exp.getMaxY(), act.getMaxY(), 0.1);
-
- sub.clear();
- assertEquals(2, collection.size());
}
public void testAdd() throws IOException {
@@ -117,37 +117,32 @@ public void testAdd() throws IOException {
SimpleFeature feature = b.buildFeature(null);
assertEquals(3, collection.size());
- collection.add(feature);
- assertEquals(4, collection.size());
-
- Iterator i = collection.iterator();
- boolean found = false;
+ source.addFeatures( DataUtilities.collection( feature ));
- while (i.hasNext()) {
- SimpleFeature f = (SimpleFeature) i.next();
+ assertEquals(4, collection.size());
- if ("three".equals(f.getAttribute(aname("stringProperty")))) {
- assertEquals(feature.getAttribute(aname("doubleProperty")),
- f.getAttribute(aname("doubleProperty")));
- assertEquals(feature.getAttribute(aname("stringProperty")),
- f.getAttribute(aname("stringProperty")));
- assertEquals(feature.getAttribute(aname("geometry")),
- f.getAttribute(aname("geometry")));
- found = true;
+ SimpleFeatureIterator i = collection.features();
+ try {
+ boolean found = false;
+
+ while (i.hasNext()) {
+ SimpleFeature f = (SimpleFeature) i.next();
+
+ if ("three".equals(f.getAttribute(aname("stringProperty")))) {
+ assertEquals(feature.getAttribute(aname("doubleProperty")),
+ f.getAttribute(aname("doubleProperty")));
+ assertEquals(feature.getAttribute(aname("stringProperty")),
+ f.getAttribute(aname("stringProperty")));
+ assertEquals(feature.getAttribute(aname("geometry")),
+ f.getAttribute(aname("geometry")));
+ found = true;
+ }
}
+ assertTrue(found);
+ }
+ finally {
+ i.close();
}
-
- assertTrue(found);
-
- collection.close(i);
}
- public void testClear() throws IOException {
- collection.clear();
-
- Iterator i = collection.iterator();
- assertFalse(i.hasNext());
-
- collection.close(i);
- }
}
View
226 modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCFeatureSourceTest.java
@@ -17,12 +17,10 @@
package org.geotools.jdbc;
import java.sql.Connection;
-import java.util.Iterator;
import java.util.NoSuchElementException;
-import org.geotools.data.DefaultQuery;
-import org.geotools.data.DefaultTransaction;
import org.geotools.data.Query;
+import org.geotools.data.DefaultTransaction;
import org.geotools.data.QueryCapabilities;
import org.geotools.data.Transaction;
import org.geotools.data.simple.SimpleFeatureCollection;
@@ -96,7 +94,7 @@ public void testBoundsWithQuery() throws Exception {
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter = ff.equals(ff.property(aname("stringProperty")), ff.literal("one"));
- DefaultQuery query = new DefaultQuery();
+ Query query = new Query();
query.setFilter(filter);
ReferencedEnvelope bounds = featureSource.getBounds(query);
@@ -116,13 +114,13 @@ public void testCountWithFilter() throws Exception {
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter = ff.equals(ff.property(aname("stringProperty")), ff.literal("one"));
- DefaultQuery query = new DefaultQuery();
+ Query query = new Query();
query.setFilter(filter);
assertEquals(1, featureSource.getCount(query));
}
public void testCountWithOffsetLimit() throws Exception {
- DefaultQuery query = new DefaultQuery();
+ Query query = new Query();
query.setStartIndex(1);
query.setMaxFeatures(1);
assertEquals(1, featureSource.getCount(query));
@@ -140,13 +138,16 @@ public void testGetFeaturesWithFilter() throws Exception {
SimpleFeatureCollection features = featureSource.getFeatures(filter);
assertEquals(1, features.size());
- Iterator<SimpleFeature> iterator = features.iterator();
- assertTrue(iterator.hasNext());
-
- SimpleFeature feature = (SimpleFeature) iterator.next();
- assertEquals("one", feature.getAttribute(aname("stringProperty")));
- assertEquals( new Double(1.1), feature.getAttribute( aname("doubleProperty")) );
- features.close(iterator);
+ SimpleFeatureIterator iterator = features.features();
+ try {
+ assertTrue(iterator.hasNext());
+
+ SimpleFeature feature = (SimpleFeature) iterator.next();
+ assertEquals("one", feature.getAttribute(aname("stringProperty")));
+ assertEquals( new Double(1.1), feature.getAttribute( aname("doubleProperty")) );
+ } finally {
+ iterator.close();
+ }
}
public void testGetFeaturesWithInvalidFilter() throws Exception {
@@ -173,44 +174,49 @@ public void testGetFeaturesWithLogicFilter() throws Exception {
SimpleFeatureCollection features = featureSource.getFeatures(filter);
assertEquals(1, features.size());
- Iterator<SimpleFeature> iterator = features.iterator();
- assertTrue(iterator.hasNext());
-
- SimpleFeature feature = (SimpleFeature) iterator.next();
- assertEquals("one", feature.getAttribute(aname("stringProperty")));
- assertEquals( new Double(1.1), feature.getAttribute( aname("doubleProperty")) );
- features.close(iterator);
-
+ SimpleFeatureIterator iterator = features.features();
+ try {
+ assertTrue(iterator.hasNext());
+
+ SimpleFeature feature = (SimpleFeature) iterator.next();
+ assertEquals("one", feature.getAttribute(aname("stringProperty")));
+ assertEquals( new Double(1.1), feature.getAttribute( aname("doubleProperty")) );
+ } finally {
+ iterator.close();
+ }
}
public void testCaseInsensitiveFilter() throws Exception {
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo sensitive = ff.equal(ff.property(aname("stringProperty")), ff.literal("OnE"), true);
PropertyIsEqualTo insensitive = ff.equal(ff.property(aname("stringProperty")), ff.literal("OnE"), false);
- assertEquals(0, featureSource.getCount(new DefaultQuery(null, sensitive)));
- assertEquals(1, featureSource.getCount(new DefaultQuery(null, insensitive)));
+ assertEquals(0, featureSource.getCount(new Query(null, sensitive)));
+ assertEquals(1, featureSource.getCount(new Query(null, insensitive)));
}
public void testGetFeaturesWithQuery() throws Exception {
FilterFactory ff = dataStore.getFilterFactory();
PropertyIsEqualTo filter = ff.equals(ff.property(aname("stringProperty")), ff.literal("one"));
- DefaultQuery query = new DefaultQuery();
+ Query query = new Query();
query.setPropertyNames(new String[] { aname("doubleProperty"), aname("intProperty") });
query.setFilter(filter);
SimpleFeatureCollection features = featureSource.getFeatures(query);
assertEquals(1, features.size());
- Iterator<SimpleFeature> iterator = features.iterator();
- assertTrue(iterator.hasNext());
-
- SimpleFeature feature = (SimpleFeature) iterator.next();
- assertEquals(2, feature.getAttributeCount());
-
- assertEquals(new Double(1.1), feature.getAttribute(aname("doubleProperty")));
- assertNotNull( feature.getAttribute(aname("intProperty")));
- features.close(iterator);
+ SimpleFeatureIterator iterator = features.features();
+ try {
+ assertTrue(iterator.hasNext());
+
+ SimpleFeature feature = (SimpleFeature) iterator.next();
+ assertEquals(2, feature.getAttributeCount());
+
+ assertEquals(new Double(1.1), feature.getAttribute(aname("doubleProperty")));
+ assertNotNull( feature.getAttribute(aname("intProperty")));
+ } finally {
+ iterator.close();
+ }
}
public void testGetFeaturesWithInvalidQuery() {
@@ -219,7 +225,7 @@ public void testGetFeaturesWithInvalidQuery() {
// make sure a complaint related to the invalid filter is thrown here
try {
- SimpleFeatureIterator fi = featureSource.getFeatures(new DefaultQuery("ft1", f)).features();
+ SimpleFeatureIterator fi = featureSource.getFeatures(new Query("ft1", f)).features();
fi.close();
fail("This query should have failed, it contains an invalid filter");
} catch(Exception e) {
@@ -231,50 +237,58 @@ public void testGetFeaturesWithInvalidQuery() {
public void testGetFeaturesWithSort() throws Exception {
FilterFactory ff = dataStore.getFilterFactory();
SortBy sort = ff.sort(aname("stringProperty"), SortOrder.ASCENDING);
- DefaultQuery query = new DefaultQuery();
+ Query query = new Query();
query.setSortBy(new SortBy[] { sort });
SimpleFeatureCollection features = featureSource.getFeatures(query);
assertEquals(3, features.size());
- Iterator<SimpleFeature> iterator = features.iterator();
- assertTrue(iterator.hasNext());
-
- SimpleFeature f = (SimpleFeature) iterator.next();
- assertEquals("one", f.getAttribute(aname("stringProperty")));
-
- assertTrue(iterator.hasNext());
- f = (SimpleFeature) iterator.next();
- assertEquals("two", f.getAttribute(aname("stringProperty")));
-
- assertTrue(iterator.hasNext());
- f = (SimpleFeature) iterator.next();
- assertEquals("zero", f.getAttribute(aname("stringProperty")));
-
- features.close(iterator);
+ SimpleFeatureIterator iterator = features.features();
+ SimpleFeature f;
+ try {
+ assertTrue(iterator.hasNext());
+
+ f = (SimpleFeature) iterator.next();
+ assertEquals("one", f.getAttribute(aname("stringProperty")));
+
+ assertTrue(iterator.hasNext());
+ f = (SimpleFeature) iterator.next();
+ assertEquals("two", f.getAttribute(aname("stringProperty")));
+
+ assertTrue(iterator.hasNext());
+ f = (SimpleFeature) iterator.next();
+ assertEquals("zero", f.getAttribute(aname("stringProperty")));
+ }
+ finally {
+ iterator.close();
+ }
sort = ff.sort(aname("stringProperty"), SortOrder.DESCENDING);
query.setSortBy(new SortBy[] { sort });
features = featureSource.getFeatures(query);
- iterator = features.iterator();
- assertTrue(iterator.hasNext());
-
- f = (SimpleFeature) iterator.next();
- assertEquals("zero", f.getAttribute(aname("stringProperty")));
-
- assertTrue(iterator.hasNext());
- f = (SimpleFeature) iterator.next();
- assertEquals("two", f.getAttribute(aname("stringProperty")));
-
- assertTrue(iterator.hasNext());
- f = (SimpleFeature) iterator.next();
- assertEquals("one", f.getAttribute(aname("stringProperty")));
- features.close(iterator);
+ iterator = features.features();
+ try {
+ assertTrue(iterator.hasNext());
+
+ f = (SimpleFeature) iterator.next();
+ assertEquals("zero", f.getAttribute(aname("stringProperty")));
+
+ assertTrue(iterator.hasNext());
+ f = (SimpleFeature) iterator.next();
+ assertEquals("two", f.getAttribute(aname("stringProperty")));
+
+ assertTrue(iterator.hasNext());
+ f = (SimpleFeature) iterator.next();
+ assertEquals("one", f.getAttribute(aname("stringProperty")));
+ }
+ finally {
+ iterator.close();
+ }
}
public void testGetFeaturesWithMax() throws Exception {
- DefaultQuery q = new DefaultQuery(featureSource.getSchema().getTypeName());
+ Query q = new Query(featureSource.getSchema().getTypeName());
q.setMaxFeatures(2);
SimpleFeatureCollection features = featureSource.getFeatures(q);
@@ -282,23 +296,25 @@ public void testGetFeaturesWithMax() throws Exception {
assertEquals(2, features.size());
// check actual iteration
- Iterator<SimpleFeature> it = features.iterator();
- int count = 0;
- ReferencedEnvelope env = new ReferencedEnvelope(features.getSchema().getCoordinateReferenceSystem());
- while(it.hasNext()) {
- SimpleFeature f = it.next();
- env.expandToInclude(ReferencedEnvelope.reference(f.getBounds()));
- count++;
- }
- assertEquals(2, count);
- features.close(it);
-
- //assertEquals(env, features.getBounds());
- assertTrue(areReferencedEnvelopesEuqal(env, features.getBounds()));
+ SimpleFeatureIterator it = features.features();
+ try {
+ int count = 0;
+ ReferencedEnvelope env = new ReferencedEnvelope(features.getSchema().getCoordinateReferenceSystem());
+ while(it.hasNext()) {
+ SimpleFeature f = it.next();
+ env.expandToInclude(ReferencedEnvelope.reference(f.getBounds()));
+ count++;
+ }
+ assertEquals(2, count);
+ //assertEquals(env, features.getBounds());
+ assertTrue(areReferencedEnvelopesEuqal(env, features.getBounds()));
+ } finally {
+ it.close();
+ }
}
public void testGetFeaturesWithOffset() throws Exception {
- DefaultQuery q = new DefaultQuery(featureSource.getSchema().getTypeName());
+ Query q = new Query(featureSource.getSchema().getTypeName());
q.setSortBy(new SortBy[] {dataStore.getFilterFactory().sort(aname("intProperty"), SortOrder.ASCENDING)});
q.setStartIndex(2);
SimpleFeatureCollection features = featureSource.getFeatures(q);
@@ -307,19 +323,22 @@ public void testGetFeaturesWithOffset() throws Exception {
assertEquals(1, features.size());
// check actual iteration
- Iterator<SimpleFeature> it = features.iterator();
- assertTrue(it.hasNext());
- SimpleFeature f = it.next();
- ReferencedEnvelope fe = ReferencedEnvelope.reference(f.getBounds());
- assertEquals(2, ((Number) f.getAttribute(aname("intProperty"))).intValue());
- assertFalse(it.hasNext());
- features.close(it);
- //assertEquals(fe, features.getBounds());
- assertTrue(areReferencedEnvelopesEuqal(fe, features.getBounds()));
+ SimpleFeatureIterator it = features.features();
+ try {
+ assertTrue(it.hasNext());
+ SimpleFeature f = it.next();
+ ReferencedEnvelope fe = ReferencedEnvelope.reference(f.getBounds());
+ assertEquals(2, ((Number) f.getAttribute(aname("intProperty"))).intValue());
+ assertFalse(it.hasNext());
+ //assertEquals(fe, features.getBounds());
+ assertTrue(areReferencedEnvelopesEuqal(fe, features.getBounds()));
+ } finally {
+ it.close();
+ }
}
public void testGetFeaturesWithOffsetLimit() throws Exception {
- DefaultQuery q = new DefaultQuery(featureSource.getSchema().getTypeName());
+ Query q = new Query(featureSource.getSchema().getTypeName());
// no sorting, let's see if the database can use native one
q.setStartIndex(1);
q.setMaxFeatures(1);
@@ -329,15 +348,18 @@ public void testGetFeaturesWithOffsetLimit() throws Exception {
assertEquals(1, features.size());
// check actual iteration
- Iterator<SimpleFeature> it = features.iterator();
- assertTrue(it.hasNext());
- SimpleFeature f = it.next();
- ReferencedEnvelope fe = ReferencedEnvelope.reference(f.getBounds());
- assertEquals(1, ((Number) f.getAttribute(aname("intProperty"))).intValue());
- assertFalse(it.hasNext());
- features.close(it);
- //assertEquals(fe, features.getBounds());
- assertTrue(areReferencedEnvelopesEuqal(fe, features.getBounds()));
+ SimpleFeatureIterator it = features.features();
+ try {
+ assertTrue(it.hasNext());
+ SimpleFeature f = it.next();
+ ReferencedEnvelope fe = ReferencedEnvelope.reference(f.getBounds());
+ assertEquals(1, ((Number) f.getAttribute(aname("intProperty"))).intValue());
+ assertFalse(it.hasNext());
+ //assertEquals(fe, features.getBounds());
+ assertTrue(areReferencedEnvelopesEuqal(fe, features.getBounds()));
+ } finally {
+ it.close();
+ }
}
/**
@@ -345,7 +367,7 @@ public void testGetFeaturesWithOffsetLimit() throws Exception {
* @throws Exception
*/
public void testRendererBehaviour() throws Exception {
- DefaultQuery query = new DefaultQuery(featureSource.getSchema().getTypeName());
+ Query query = new Query(featureSource.getSchema().getTypeName());
query.setHints(new Hints(new Hints(Hints.JTS_COORDINATE_SEQUENCE_FACTORY, new LiteCoordinateSequenceFactory())));
FeatureCollection fc = featureSource.getFeatures(query);
FeatureIterator fi = fc.features();
@@ -375,7 +397,7 @@ public void testQueryCapabilitiesReliableFid() throws Exception {
}
public void testNaturalSortingAsc() throws Exception {
- DefaultQuery q = new DefaultQuery(featureSource.getSchema().getTypeName());
+ Query q = new Query(featureSource.getSchema().getTypeName());
q.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER});
SimpleFeatureIterator features = featureSource.getFeatures(q).features();
String prevId = null;
@@ -389,7 +411,7 @@ public void testNaturalSortingAsc() throws Exception {
}
public void testNaturalSortingdesc() throws Exception {
- DefaultQuery q = new DefaultQuery(featureSource.getSchema().getTypeName());
+ Query q = new Query(featureSource.getSchema().getTypeName());
q.setSortBy(new SortBy[] {SortBy.REVERSE_ORDER});
SimpleFeatureIterator features = featureSource.getFeatures(q).features();
String prevId = null;
@@ -488,7 +510,7 @@ public void testGetFeaturesWithArithmeticOpFilter() throws Exception {
//this test is very dependant on the specific database, some db's will round, some won't
// so just assert that something is returned
- assertTrue(featureSource.getCount(new DefaultQuery(null, filter)) > 0);
+ assertTrue(featureSource.getCount(new Query(null, filter)) > 0);
}
SimpleFeature getFirstFeature(SimpleFeatureCollection fc) {
View
135 modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCFeatureStoreTest.java
@@ -32,6 +32,7 @@
import org.geotools.data.Transaction;
import org.geotools.data.FeatureEvent.Type;
import org.geotools.data.simple.SimpleFeatureCollection;
+import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.factory.Hints;
import org.geotools.feature.AttributeTypeBuilder;
@@ -79,7 +80,7 @@ public void testAddFeatures() throws IOException {
collection.add(b.buildFeature(null));
}
featureStore.addFeatureListener( watcher );
- List<FeatureId> fids = featureStore.addFeatures(collection);
+ List<FeatureId> fids = featureStore.addFeatures((SimpleFeatureCollection)collection);
assertEquals( watcher.bounds, collection.getBounds() );
assertEquals(3, fids.size());
@@ -97,14 +98,17 @@ public void testAddFeatures() throws IOException {
features = featureStore.getFeatures(filter);
assertEquals(1, features.size());
- Iterator iterator = features.iterator();
- assertTrue(iterator.hasNext());
-
- SimpleFeature feature = (SimpleFeature) iterator.next();
- assertEquals(fid, feature.getID());
- assertFalse(iterator.hasNext());
-
- features.close(iterator);
+ SimpleFeatureIterator iterator = features.features();
+ try {
+ assertTrue(iterator.hasNext());
+
+ SimpleFeature feature = (SimpleFeature) iterator.next();
+ assertEquals(fid, feature.getID());
+ assertFalse(iterator.hasNext());
+ }
+ finally {
+ iterator.close();
+ }
}
}
@@ -123,7 +127,7 @@ public void testAddFeaturesUseProvidedFid() throws IOException {
b.featureUserData(Hints.USE_PROVIDED_FID, Boolean.TRUE);
collection.add(b.buildFeature(typeName + "." + (i * 10)));
}
- List<FeatureId> fids = featureStore.addFeatures(collection);
+ List<FeatureId> fids = featureStore.addFeatures((SimpleFeatureCollection)collection);
assertEquals(3, fids.size());
assertTrue(fids.contains(SimpleFeatureBuilder.createDefaultFeatureIdentifier(typeName + ".30")));
@@ -159,7 +163,7 @@ public void testAddInTransaction() throws IOException {
featureStore.setTransaction(t);
featureStore.addFeatureListener(watcher);
JDBCFeatureStore featureStore2 = (JDBCFeatureStore) dataStore.getFeatureSource(featureStore.getName().getLocalPart());
- List<FeatureId> fids = featureStore.addFeatures(collection);
+ List<FeatureId> fids = featureStore.addFeatures((SimpleFeatureCollection)collection);
assertEquals(1, fids.size());
@@ -192,7 +196,7 @@ public void testExternalConnection() throws IOException, SQLException {
featureStore.setTransaction(t);
featureStore.addFeatureListener(watcher);
JDBCFeatureStore featureStore2 = (JDBCFeatureStore) dataStore.getFeatureSource(featureStore.getName().getLocalPart());
- List<FeatureId> fids = featureStore.addFeatures(collection);
+ List<FeatureId> fids = featureStore.addFeatures((SimpleFeatureCollection)collection);
assertEquals(1, fids.size());
@@ -251,25 +255,27 @@ public void testSetFeatures() throws IOException {
collection.add(b.buildFeature(null));
}
- FeatureReader<SimpleFeatureType, SimpleFeature> reader = new CollectionFeatureReader(collection, collection.getSchema());
+ FeatureReader<SimpleFeatureType, SimpleFeature> reader = new CollectionFeatureReader((SimpleFeatureCollection)collection, collection.getSchema());
featureStore.setFeatures(reader);
SimpleFeatureCollection features = featureStore.getFeatures();
assertEquals(3, features.size());
- Iterator iterator = features.iterator();
- HashSet numbers = new HashSet();
- numbers.add(new Integer(3));
- numbers.add(new Integer(4));
- numbers.add(new Integer(5));
-
- for (int i = 3; iterator.hasNext(); i++) {
- SimpleFeature feature = (SimpleFeature) iterator.next();
- assertTrue(numbers.contains(((Number)feature.getAttribute(aname("intProperty"))).intValue()));
- numbers.remove(feature.getAttribute(aname("intProperty")));
+ SimpleFeatureIterator iterator = features.features();
+ try {
+ HashSet<Integer> numbers = new HashSet<Integer>();
+ numbers.add(new Integer(3));
+ numbers.add(new Integer(4));
+ numbers.add(new Integer(5));
+
+ for (int i = 3; iterator.hasNext(); i++) {
+ SimpleFeature feature = (SimpleFeature) iterator.next();
+ assertTrue(numbers.contains(((Number)feature.getAttribute(aname("intProperty"))).intValue()));
+ numbers.remove(feature.getAttribute(aname("intProperty")));
+ }
+ } finally {
+ iterator.close();
}
-
- features.close(iterator);
}
public void testModifyFeatures() throws IOException {
@@ -285,15 +291,18 @@ public void testModifyFeatures() throws IOException {
assertEquals( Filter.INCLUDE, watcher.filter );
SimpleFeatureCollection features = featureStore.getFeatures();
- Iterator<SimpleFeature> i = features.iterator();
-
- assertTrue(i.hasNext());
-
- while (i.hasNext()) {
- SimpleFeature feature = (SimpleFeature) i.next();
- assertEquals("foo", feature.getAttribute(aname("stringProperty")));
+ SimpleFeatureIterator i = features.features();
+ try {
+ assertTrue(i.hasNext());
+
+ while (i.hasNext()) {
+ SimpleFeature feature = (SimpleFeature) i.next();
+ assertEquals("foo", feature.getAttribute(aname("stringProperty")));
+ }
+ }
+ finally {
+ i.close();
}
- features.close(i);
}
public void testModifyGeometry() throws IOException {
@@ -305,16 +314,18 @@ public void testModifyGeometry() throws IOException {
new Object[] { point }, Filter.INCLUDE);
SimpleFeatureCollection features = featureStore.getFeatures();
- Iterator i = features.iterator();
-
- assertTrue(i.hasNext());
-
- while (i.hasNext()) {
- SimpleFeature feature = (SimpleFeature) i.next();
- assertTrue(point.equalsExact((Geometry) feature.getAttribute(aname("geometry"))));
+ SimpleFeatureIterator i = features.features();
+ try {
+ assertTrue(i.hasNext());
+
+ while (i.hasNext()) {
+ SimpleFeature feature = (SimpleFeature) i.next();
+ assertTrue(point.equalsExact((Geometry) feature.getAttribute(aname("geometry"))));
+ }
+ }
+ finally {
+ i.close();
}
-
- features.close(i);
}
public void testModifyMadeUpGeometry() throws IOException {
@@ -333,16 +344,18 @@ public void testModifyMadeUpGeometry() throws IOException {
new Object[] { point }, Filter.INCLUDE);
SimpleFeatureCollection features = featureStore.getFeatures();
- Iterator i = features.iterator();
-
- assertTrue(i.hasNext());
-
- while (i.hasNext()) {
- SimpleFeature feature = (SimpleFeature) i.next();
- assertTrue(point.equalsExact((Geometry) feature.getAttribute(aname("geometry"))));
+ SimpleFeatureIterator i = features.features();
+ try {
+ assertTrue(i.hasNext());
+
+ while (i.hasNext()) {
+ SimpleFeature feature = (SimpleFeature) i.next();
+ assertTrue(point.equalsExact((Geometry) feature.getAttribute(aname("geometry"))));
+ }
+ }
+ finally {
+ i.close();
}
-
- features.close(i);
}
public void testModifyFeaturesSingleAttribute() throws IOException {
@@ -350,16 +363,18 @@ public void testModifyFeaturesSingleAttribute() throws IOException {
featureStore.modifyFeatures(t.getDescriptor(aname("stringProperty")), "foo" , Filter.INCLUDE);
SimpleFeatureCollection features = featureStore.getFeatures();
- Iterator i = features.iterator();
-
- assertTrue(i.hasNext());
-
- while (i.hasNext()) {
- SimpleFeature feature = (SimpleFeature) i.next();
- assertEquals("foo", feature.getAttribute(aname("stringProperty")));
+ SimpleFeatureIterator i = features.features();
+ try {
+ assertTrue(i.hasNext());
+
+ while (i.hasNext()) {
+ SimpleFeature feature = (SimpleFeature) i.next();
+ assertEquals("foo", feature.getAttribute(aname("stringProperty")));
+ }
+ }
+ finally {
+ i.close();
}
-
- features.close(i);
}
public void testModifyFeaturesInvalidFilter() throws IOException {
View
10 modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCPrimaryKeyFinderTest.java
@@ -16,6 +16,8 @@
*/
package org.geotools.jdbc;
+import org.geotools.data.DataUtilities;
+import org.geotools.data.store.ContentFeatureCollection;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.simple.SimpleFeatureBuilder;
@@ -48,9 +50,9 @@ public void testSequencedPrimaryKey() throws Exception {
assertEquals( 1, fs.getPrimaryKey().getColumns().size() );
assertTrue( fs.getPrimaryKey().getColumns().get(0) instanceof SequencedPrimaryKeyColumn );
- FeatureCollection features = fs.getFeatures();
+ ContentFeatureCollection features = fs.getFeatures();
assertPrimaryKeyValues(features, 3);
- addFeature(fs.getSchema(),features);
+ addFeature(fs.getSchema(),fs);
assertPrimaryKeyValues(features,4);
}
@@ -82,13 +84,13 @@ public void testAssignedMultiPKeyView() throws Exception {
i.close();
}
- protected void addFeature( SimpleFeatureType featureType, FeatureCollection features ) throws Exception {
+ protected void addFeature( SimpleFeatureType featureType, JDBCFeatureStore features ) throws Exception {
SimpleFeatureBuilder b = new SimpleFeatureBuilder( featureType );
b.add("four");
b.add( new GeometryFactory().createPoint( new Coordinate(4,4) ) );
SimpleFeature f = b.buildFeature(null);
- features.add( f );
+ features.addFeatures( DataUtilities.collection( f ) );
//pattern match to handle the multi primary key case
assertTrue(((String)f.getUserData().get( "fid" )).matches( tname(featureType.getTypeName()) + ".4(\\..*)?"));
View
15 modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCPrimaryKeyTest.java
@@ -18,6 +18,7 @@
import java.util.Collections;
+import org.geotools.data.DataUtilities;
import org.geotools.data.FeatureStore;
import org.geotools.feature.FeatureCollection;
import org.geotools.feature.FeatureIterator;
@@ -56,7 +57,7 @@ public void testAutoGeneratedPrimaryKey() throws Exception {
FeatureCollection features = fs.getFeatures();
assertPrimaryKeyValues(features, 3);
- addFeature(fs.getSchema(),features);
+ addFeature(fs.getSchema(),fs);
assertPrimaryKeyValues(features,4);
}
@@ -68,7 +69,7 @@ public void testSequencedPrimaryKey() throws Exception {
FeatureCollection features = fs.getFeatures();
assertPrimaryKeyValues(features, 3);
- addFeature(fs.getSchema(),features);
+ addFeature(fs.getSchema(),fs);
assertPrimaryKeyValues(features,4);
}
@@ -80,17 +81,17 @@ public void testNonIncrementingPrimaryKey() throws Exception {
FeatureCollection features = fs.getFeatures();
assertPrimaryKeyValues(features, 3);
- addFeature(fs.getSchema(),features);
+ addFeature(fs.getSchema(),fs);
assertPrimaryKeyValues(features,4);
}
- protected void addFeature( SimpleFeatureType featureType, FeatureCollection features ) throws Exception {
+ protected void addFeature( SimpleFeatureType featureType, JDBCFeatureStore features ) throws Exception {
SimpleFeatureBuilder b = new SimpleFeatureBuilder( featureType );
b.add("four");
b.add( new GeometryFactory().createPoint( new Coordinate(4,4) ) );
SimpleFeature f = b.buildFeature(null);
- features.add( f );
+ features.addFeatures(DataUtilities.collection( f ) );
//pattern match to handle the multi primary key case
assertTrue(((String)f.getUserData().get( "fid" )).matches( tname(featureType.getTypeName()) + ".4(\\..*)?"));
@@ -118,7 +119,7 @@ public void testMultiColumnPrimaryKey() throws Exception {
assertMultiPrimaryKeyValues(features,3);
- addFeature(fs.getSchema(),features);
+ addFeature(fs.getSchema(),fs);
assertMultiPrimaryKeyValues(features,4);
@@ -163,7 +164,7 @@ public void testUniqueIndex() throws Exception {
FeatureCollection features = fs.getFeatures();
assertPrimaryKeyValues(features, 3);
- addFeature(fs.getSchema(),features);
+ addFeature(fs.getSchema(),fs);
assertPrimaryKeyValues(features,4);
}
View
9 modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCTransactionTest.java
@@ -18,6 +18,7 @@
import java.io.IOException;
+import org.geotools.data.DataUtilities;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.FeatureWriter;
import org.geotools.data.Query;
@@ -37,7 +38,7 @@
*/
public abstract class JDBCTransactionTest extends JDBCTestSupport {
public void testCommit() throws IOException {
- JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));
+ //JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));
Transaction tx = new DefaultTransaction();
@@ -55,7 +56,7 @@ public void testCommit() throws IOException {
}
public void testNoCommit() throws IOException {
- JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));
+ //JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));
Transaction tx = new DefaultTransaction();
@@ -73,7 +74,7 @@ public void testNoCommit() throws IOException {
}
public void testConcurrentTransactions() throws IOException {
- JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));
+ //JDBCFeatureStore fs = (JDBCFeatureStore) dataStore.getFeatureSource(tname("ft1"));
Transaction tx1 = new DefaultTransaction();
@@ -112,7 +113,7 @@ public void testSerialTransactions() throws IOException {
b.set(aname("intProperty"), new Integer(100));
SimpleFeature f1 = b.buildFeature(null);
SimpleFeatureCollection features = new DefaultFeatureCollection(null,null);
- features.add( f1 );
+ st.addFeatures( DataUtilities.collection(f1));
Transaction tx1 = new DefaultTransaction();
st.setTransaction(tx1);
View
16 modules/plugin/jdbc/jdbc-teradata/src/test/java/org/geotools/data/teradata/TeradataPrimaryKeyTest.java
@@ -18,7 +18,9 @@
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
-import org.geotools.feature.FeatureCollection;
+
+import org.geotools.data.DataUtilities;
+import org.geotools.data.store.ContentFeatureCollection;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.jdbc.*;
import org.opengis.feature.simple.SimpleFeature;
@@ -42,7 +44,7 @@ public void testUniqueGeneratedPrimaryKey() throws Exception {
assertEquals(1, fs.getPrimaryKey().getColumns().size());
assertTrue(fs.getPrimaryKey().getColumns().get(0) instanceof NonIncrementingPrimaryKeyColumn);
- FeatureCollection features = fs.getFeatures();
+ ContentFeatureCollection features = fs.getFeatures();
assertPrimaryKeyValues(features, 3);
SimpleFeatureType featureType = fs.getSchema();
@@ -51,7 +53,7 @@ public void testUniqueGeneratedPrimaryKey() throws Exception {
b.add( new GeometryFactory().createPoint( new Coordinate(4,4) ) );
SimpleFeature f = b.buildFeature(null);
- features.add( f );
+ fs.addFeatures( DataUtilities.collection(f));
//pattern match to handle the multi primary key case
assertTrue(((String)f.getUserData().get( "fid" )).matches( tname(featureType.getTypeName()) + ".4(\\..*)?"));
@@ -65,9 +67,9 @@ public void testUniqueNonGeneratedPrimaryKey() throws Exception {
assertEquals(1, fs.getPrimaryKey().getColumns().size());
assertTrue(fs.getPrimaryKey().getColumns().get(0) instanceof AutoGeneratedPrimaryKeyColumn);
- FeatureCollection features = fs.getFeatures();
+ ContentFeatureCollection features = fs.getFeatures();
assertPrimaryKeyValues(features, 3);
- addFeature(fs.getSchema(), features);
+ addFeature(fs.getSchema(), fs);
assertPrimaryKeyValues(features, 4);
}
@@ -77,9 +79,9 @@ public void testSequencedPrimaryKey() throws Exception {
assertEquals(1, fs.getPrimaryKey().getColumns().size());
assertTrue(fs.getPrimaryKey().getColumns().get(0) instanceof AutoGeneratedPrimaryKeyColumn);
- FeatureCollection features = fs.getFeatures();
+ ContentFeatureCollection features = fs.getFeatures();
assertPrimaryKeyValues(features, 3);
- addFeature(fs.getSchema(), features);
+ addFeature(fs.getSchema(), fs);
assertPrimaryKeyValues(features, 4);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.