FeatureCollection<SimpleFeatureType, SimpleFeature> collection;
collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1,
(SimpleFeature) points2, (SimpleFeature) points3));
Transaction tx = new DefaultTransaction();
points.setTransaction(tx);
try {
List<FeatureId> newFids = points.addFeatures(collection);
assertNotNull(newFids);
assertEquals(3, newFids.size());
FeatureId fid1 = newFids.get(0);
FeatureId fid2 = newFids.get(1);
FeatureId fid3 = newFids.get(2);
// new ids should have been generated...
assertFalse(idP1.equals(fid1.getID()));
assertFalse(idP1.equals(fid1.getID()));
assertFalse(idP1.equals(fid1.getID()));
// now force the use of provided feature ids
points1.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);
points2.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);
points3.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);
List<FeatureId> providedFids = points.addFeatures(collection);
assertNotNull(providedFids);
assertEquals(3, providedFids.size());
FeatureId fid11 = providedFids.get(0);
FeatureId fid21 = providedFids.get(1);
FeatureId fid31 = providedFids.get(2);
// ids should match provided
assertEquals(idP1, fid11.getID());
assertEquals(idP2, fid21.getID());
assertEquals(idP3, fid31.getID());
tx.commit();
assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid1))).size());
assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid2))).size());
assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid3))).size());
assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid11))).size());
assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid21))).size());
assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid31))).size());
} catch (Exception e) {
tx.rollback();
throw e;
} finally {
tx.close();
}
}