SimpleFeatureCollection features = store.getFeatures(oldValueFilter);
final int initialSize = features.size();
assertEquals(1, initialSize);// just to not go forward with bad data
final SimpleFeature originalFeature;
SimpleFeatureIterator iterator = features.features();
try {
originalFeature = iterator.next();
} finally {
iterator.close();
}
{
final Transaction transaction = new DefaultTransaction("testModifyFeaturesTransaction");
store.setTransaction(transaction);
try {
final AttributeDescriptor propDescriptor = schema.getDescriptor("INT32_COL");
store.modifyFeatures(propDescriptor.getName(), Integer.valueOf(-1000),
oldValueFilter);
transaction.commit();
} catch (Exception e) {
transaction.rollback();
} finally {
transaction.close();
}
}
store.setTransaction(Transaction.AUTO_COMMIT);
final Query oldValueQuery = new Query(typeName, oldValueFilter);
final Query newValueQuery = new Query(typeName, newValueFilter);
assertEquals(0, store.getCount(oldValueQuery));
assertEquals(1, store.getCount(newValueQuery));
final SimpleFeatureIterator newFeatures = store.getFeatures(newValueQuery).features();
final SimpleFeature modifiedFeature;
try {
modifiedFeature = newFeatures.next();
} finally {
newFeatures.close();
}
// verify the non modified properties stay the same
final List<Attribute> originalValues = (List<Attribute>) originalFeature.getValue();
final List<Attribute> actualValues = (List<Attribute>) modifiedFeature.getValue();