ioException);
}
}
// result
TransactionResponse result = request.createResponse();
result.setHandle(request.getHandle());
// execute elements in order, recording results as we go
// I will need to record the damaged area for pre commit validation
// checks
// Envelope envelope = new Envelope();
Exception exception = null;
try {
for (Iterator it = elementHandlers.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
TransactionElement element = (TransactionElement) entry.getKey();
TransactionElementHandler handler = (TransactionElementHandler) entry.getValue();
handler.execute(element, request, stores, result, multiplexer);
}
} catch (WFSTransactionException e) {
LOGGER.log(Level.SEVERE, "Transaction failed", e);
exception = e;
//another wfs 2.0 hack, but in the case no lock is specified in the request and the tx
// is trying to update locked features, we need to use the MissingParameterValue
if (request.getVersion().startsWith("2") && e.getCause() instanceof FeatureLockException
&& request.getLockId() == null) {
exception = new WFSTransactionException(e.getMessage(), e, "MissingParameterValue");
}
result.addAction(e.getCode() != null ? e.getCode() : "InvalidParameterValue",
e.getLocator(), e.getMessage());
}
// commit
boolean committed = false;
try {
if (exception != null) {
transaction.rollback();
} else {
// inform plugins we're about to commit
for (Iterator it = transactionPlugins.iterator(); it.hasNext();) {
TransactionPlugin tp = (TransactionPlugin) it.next();
fireBeforeCommit(request, tp);
}
transaction.commit();
committed = true;
//
// Lets deal with the locks
//
// Q: Why talk to Data you ask
// A: Only class that knows all the DataStores
//
// We really need to ask all DataStores to release/refresh
// because we may have locked Features with this Authorizations
// on them, even though we did not refer to them in this
// transaction.
//
// Q: Why here, why now?
// A: The opperation was a success, and we have completed the
// opperation
//
// We also need to do this if the opperation is not a success,
// you can find this same code in the abort method
//
String lockId = request.getLockId();
if (lockId != null) {
if (request.isReleaseActionAll()) {
lockRelease(lockId);
} else if (request.isReleaseActionSome()) {
lockRefresh(lockId);
}
}
}
} finally {
transaction.close();
transaction = null;
request.setTransaction(null);
}
// inform plugins we're done
for (Iterator it = transactionPlugins.iterator(); it.hasNext();) {
TransactionPlugin tp = (TransactionPlugin) it.next();
fireAfterTransaction(request, result, committed, tp);
}
//
// if ( result.getTransactionResult().getStatus().getPARTIAL() != null )
// {
// throw new WFSException("Canceling PARTIAL response");
// }
//
// try {
// if ( result.getTransactionResult().getStatus().getFAILED() != null )
// {
// //transaction failed, roll it back
// transaction.rollback();
// }
// else {
// transaction.commit();
// result.getTransactionResult().getStatus().setSUCCESS(
// WfsFactory.eINSTANCE.createEmptyType() );
// }
//
// }
// finally {
// transaction.close();
// transaction = null;
// }
if (exception != null) {
//WFS 2.0 wants us to throw the exception
if (request.getVersion() != null && request.getVersion().startsWith("2")) {
if (!(exception instanceof WFSException && ((WFSException)exception).getCode() != null)) {
//wrap to get the default code
exception = new WFSException(request, exception);
}
throw exception;
}
}
// JD: this is an issue with the spec, InsertResults must be present,
// even if no insert
// occured, howwever insert results needs to have at least one
// "FeatureId" eliement, sp
// we create an FeatureId with an empty fid
List insertedFeatures = result.getInsertedFeatures();
if (insertedFeatures != null && insertedFeatures.isEmpty()) {
result.addInsertedFeature(null, filterFactory.featureId("none"));
}
return result;
// we will commit in the writeTo method