*
*/
private void testInsertAutoCommit(Class<? extends Geometry> geometryClass) throws Exception {
final String typeName = testData.getTempTableName();
final int insertCount = 2;
final SimpleFeatureCollection testFeatures;
testFeatures = testData.createTestFeatures(geometryClass, insertCount);
final DataStore ds = testData.getDataStore();
final SimpleFeatureSource fsource = ds.getFeatureSource(typeName);
// incremented on each feature added event to
// ensure events are being raised as expected
// (the count is wraped inside an array to be able of declaring
// the variable as final and accessing it from inside the anonymous
// inner class)
/*
* final int[] featureAddedEventCount = { 0 };
*
* fsource.addFeatureListener(new FeatureListener() { public void changed(FeatureEvent evt)
* { if (evt.getEventType() != FeatureEvent.FEATURES_ADDED) { throw new
* IllegalArgumentException( "Expected FEATURES_ADDED event, got " + evt.getEventType()); }
*
* ++featureAddedEventCount[0]; } });
*/
final int initialCount = fsource.getCount(Query.ALL);
FeatureWriter<SimpleFeatureType, SimpleFeature> writer = ds.getFeatureWriterAppend(
typeName, Transaction.AUTO_COMMIT);
SimpleFeature source;
SimpleFeature dest;
try {
for (SimpleFeatureIterator fi = testFeatures.features(); fi.hasNext();) {
source = fi.next();
dest = writer.next();
dest.setAttributes(source.getAttributes());
writer.write();
}
} finally {
writer.close();
}
// was the features really inserted?
int fcount = fsource.getCount(Query.ALL);
assertEquals(testFeatures.size() + initialCount, fcount);
/*
* String msg = "a FEATURES_ADDED event should have been called " + features.size() + "
* times"; assertEquals(msg, features.size(), featureAddedEventCount[0]);
*/