|
|
|
svn_geotools
|
Author: aaime
Date: 2009-11-12 09:32:50 -0500 (Thu, 12 Nov 2009) New Revision: 34367 Modified: trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/FeatureEventWatcher.java trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCFeatureStoreTest.java trunk/modules/library/main/src/main/java/org/geotools/data/BatchFeatureEvent.java trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisFeatureStoreTest.java Log: GEOT-2829, All ContentDataStore subclasses fail with NPE on transactions that have both inserts and attached feature listeners Modified: trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/FeatureEventWatcher.java =================================================================== --- trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/FeatureEventWatcher.java 2009-11-12 13:52:35 UTC (rev 34366) +++ trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/FeatureEventWatcher.java 2009-11-12 14:32:50 UTC (rev 34367) @@ -38,7 +38,7 @@ public FeatureSource<? extends FeatureType, ? extends Feature> source; /** Total bounds since last reset*/ - public ReferencedEnvelope bounds = new ReferencedEnvelope(); + public ReferencedEnvelope bounds; /** number of events since last reset */ public int count = 0; Modified: trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCFeatureStoreTest.java =================================================================== --- trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCFeatureStoreTest.java 2009-11-12 13:52:35 UTC (rev 34366) +++ trunk/modules/library/jdbc/src/test/java/org/geotools/jdbc/JDBCFeatureStoreTest.java 2009-11-12 14:32:50 UTC (rev 34367) @@ -24,8 +24,9 @@ import java.util.List; import org.geotools.data.CollectionFeatureReader; +import org.geotools.data.DefaultTransaction; import org.geotools.data.FeatureReader; -import org.geotools.data.FeatureSource; +import org.geotools.data.Transaction; import org.geotools.data.FeatureEvent.Type; import org.geotools.factory.CommonFactoryFinder; import org.geotools.feature.AttributeTypeBuilder; @@ -61,16 +62,16 @@ DefaultFeatureCollection collection = new DefaultFeatureCollection(null, featureStore.getSchema()); - //Watcher watcher = new Watcher(); + FeatureEventWatcher watcher = new FeatureEventWatcher(); for (int i = 3; i < 6; i++) { b.set(aname("intProperty"), new Integer(i)); b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(i, i))); collection.add(b.buildFeature(null)); } - //featureStore.addFeatureListener( watcher ); + featureStore.addFeatureListener( watcher ); List<FeatureId> fids = featureStore.addFeatures(collection); - //assertEquals( watcher.bounds, collection.getBounds() ); + assertEquals( watcher.bounds, collection.getBounds() ); assertEquals(3, fids.size()); @@ -98,6 +99,36 @@ } } + public void testAddInTransaction() throws IOException { + SimpleFeatureBuilder b = new SimpleFeatureBuilder(featureStore.getSchema()); + DefaultFeatureCollection collection = new DefaultFeatureCollection(null, + featureStore.getSchema()); + + b.set(aname("intProperty"), new Integer(3)); + b.set(aname("geometry"), new GeometryFactory().createPoint(new Coordinate(3, 3))); + collection.add(b.buildFeature(null)); + + FeatureEventWatcher watcher = new FeatureEventWatcher(); + Transaction t = new DefaultTransaction(); + featureStore.setTransaction(t); + featureStore.addFeatureListener(watcher); + JDBCFeatureStore featureStore2 = (JDBCFeatureStore) dataStore.getFeatureSource(featureStore.getName().getLocalPart()); + List<FeatureId> fids = featureStore.addFeatures(collection); + + assertEquals(1, fids.size()); + + // check the store with the transaction sees the new features, but the other store does not + assertEquals(4, featureStore.getFeatures().size()); + assertEquals(3, featureStore2.getFeatures().size()); + + // check that after the commit everybody sees 4 + t.commit(); + assertEquals(4, featureStore.getFeatures().size()); + assertEquals(4, featureStore2.getFeatures().size()); + + t.close(); + } + /** * Check null encoding is working properly * @throws IOException Modified: trunk/modules/library/main/src/main/java/org/geotools/data/BatchFeatureEvent.java =================================================================== --- trunk/modules/library/main/src/main/java/org/geotools/data/BatchFeatureEvent.java 2009-11-12 13:52:35 UTC (rev 34366) +++ trunk/modules/library/main/src/main/java/org/geotools/data/BatchFeatureEvent.java 2009-11-12 14:32:50 UTC (rev 34367) @@ -63,7 +63,7 @@ * by the client to track selection. */ @SuppressWarnings("unchecked") - protected WeakHashSet<Identifier> fids; + protected WeakHashSet<Identifier> fids = new WeakHashSet<Identifier>(Identifier.class); /** * Used to change this into a COMMIT or ROLLBACK if needed. @@ -134,6 +134,7 @@ } } } + /** * This is the set of Identifiers that have been created * over the course of this operation. @@ -145,7 +146,7 @@ * @return Set of Identifiers created during this commit */ @SuppressWarnings("unchecked") - public WeakHashSet<Identifier> getCreatedFeatureIds(){ + public WeakHashSet<Identifier> getCreatedFeatureIds() { return fids; } } Modified: trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisFeatureStoreTest.java =================================================================== --- trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisFeatureStoreTest.java 2009-11-12 13:52:35 UTC (rev 34366) +++ trunk/modules/plugin/jdbc/jdbc-postgis/src/test/java/org/geotools/data/postgis/PostgisFeatureStoreTest.java 2009-11-12 14:32:50 UTC (rev 34367) @@ -28,8 +28,4 @@ return new PostGISTestSetup(); } - @Override - public void testAddFeatures() throws IOException { - // wont' pass right now, see http://jira.codehaus.org/browse/GEOT-2231 - } } ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ GeoTools-commits mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-commits |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |