public void execute(EObject element, TransactionType request, Map featureStores,
TransactionResponseType response, TransactionListener listener)
throws WFSTransactionException {
RollbackType rollback = (RollbackType) element;
final QName layerName = rollback.getTypeName();
VersioningFeatureStore vstore = (VersioningFeatureStore) featureStores.get(layerName);
if(vstore == null)
throw new WFSTransactionException("Could not locate feature type " + layerName);
long inserted = response.getTransactionSummary().getTotalInserted().longValue();
long updated = response.getTransactionSummary().getTotalUpdated().longValue();
long deleted = response.getTransactionSummary().getTotalDeleted().longValue();
FeatureDiffReader reader = null;
try {
// we use the difference to compute the number of inserted,
// updated and deleted features, but we can't use these to
// actually perform the rollback, since we would be unable to
// preserve the fids of the ones that were deleted and need to
// be re-inserted
Filter filter = (rollback.getFilter() != null) ? (Filter) rollback.getFilter()
: Filter.INCLUDE;
String version = rollback.getToFeatureVersion();
String user = rollback.getUser();
String[] users = ((user != null) && !user.trim().equals("")) ? new String[] { user }
: null;
reader = vstore.getDifferences("LAST", version, filter, users);
Set insertedIds = new HashSet();
Set updatedIds = new HashSet();
Set deletedIds = new HashSet();
while (reader.hasNext()) {
FeatureDiff fd = reader.next();
if (fd.getState() == FeatureDiff.INSERTED) {
inserted++;
InsertedFeatureType insertedFeature = WfsFactory.eINSTANCE
.createInsertedFeatureType();
insertedFeature.setHandle(rollback.getHandle());
insertedFeature.getFeatureId().add(filterFactory.featureId(fd.getID()));
response.getInsertResults().getFeature().add(insertedFeature);
// accumulate fids for transaction event handling
insertedIds.add(filterFactory.featureId(fd.getID()));
} else if (fd.getState() == FeatureDiff.UPDATED) {
updated++;
// accumulate fids for transaction event handling
updatedIds.add(filterFactory.featureId(fd.getID()));
} else if (fd.getState() == FeatureDiff.DELETED) {
deleted++;
// accumulate fids for transaction event handling
deletedIds.add(filterFactory.featureId(fd.getID()));
}
}
// build filters
Filter insertedFilter = filterFactory.id(insertedIds);
Filter updatedFilter = filterFactory.id(updatedIds);
Filter deletedFilter = filterFactory.id(deletedIds);
// notify pre-update and pre-delete
listener.dataStoreChange(new TransactionEvent(TransactionEventType.PRE_UPDATE, layerName,
vstore.getFeatures(updatedFilter), rollback));
listener.dataStoreChange(new TransactionEvent(TransactionEventType.PRE_DELETE, layerName,
vstore.getFeatures(deletedFilter), rollback));
// now do the actual rollback
try {
vstore.rollback(version, (Filter) rollback.getFilter(), users);
} catch (Exception e) {
throw new WFSTransactionException("Could not perform the rollback", e, rollback
.getHandle());
}
// notify post update and post insert
listener.dataStoreChange(new TransactionEvent(TransactionEventType.POST_INSERT, layerName,
vstore.getFeatures(insertedFilter)));
listener.dataStoreChange(new TransactionEvent(TransactionEventType.POST_UPDATE, layerName,
vstore.getFeatures(updatedFilter)));
// update summary information
response.getTransactionSummary().setTotalInserted(BigInteger.valueOf(inserted));
response.getTransactionSummary().setTotalUpdated(BigInteger.valueOf(updated));
response.getTransactionSummary().setTotalDeleted(BigInteger.valueOf(deleted));