OLINGO-573: fixing the rollback logic in the case of batch changeset error

This commit is contained in:
Ramesh Reddy 2015-04-24 17:58:00 -05:00
parent a5c51d6f8d
commit 0d015cb7b6
2 changed files with 27 additions and 8 deletions

View File

@ -235,21 +235,27 @@ public interface ServiceHandler extends Processor {
* During a batch operation, this method starts the transaction (if any) before any operation is handled
* by the service. No nested transactions.
* @return must return a unique transaction id that references a atomic operation.
* @throws ODataTranslatedException
* @throws ODataApplicationException
*/
String startTransaction();
String startTransaction() throws ODataTranslatedException, ODataApplicationException;;
/**
* When a batch operation is complete and all the intermediate service requests are successful, then
* commit is called with transaction id returned in the startTransaction method.
* @param txnId
* @throws ODataTranslatedException
* @throws ODataApplicationException
*/
void commit(String txnId);
void commit(String txnId) throws ODataTranslatedException, ODataApplicationException;;
/**
* When a batch operation is in-complete due to an error in the middle of changeset, then rollback is
* called with transaction id, that returned from startTransaction method.
* @param txnId
* @throws ODataTranslatedException
* @throws ODataApplicationException
*/
void rollback(String txnId);
void rollback(String txnId) throws ODataTranslatedException, ODataApplicationException;;
/**
* This is not complete, more URL parsing changes required. Cross join between two entities.

View File

@ -77,12 +77,25 @@ public class BatchRequest extends ServiceRequest {
for (BatchRequestPart part : parts) {
if (part.isChangeSet()) {
String txnId = handler.startTransaction();
partResponse = processChangeSet(part, handler);
if (partResponse.getResponses().get(0).getStatusCode() > 400) {
handler.rollback(txnId);
String txnId = null;
try {
txnId = handler.startTransaction();
partResponse = processChangeSet(part, handler);
if (partResponse.getResponses().get(0).getStatusCode() > 400) {
handler.rollback(txnId);
}
handler.commit(txnId);
} catch(ODataTranslatedException e) {
if (txnId != null) {
handler.rollback(txnId);
}
throw e;
} catch (ODataApplicationException e) {
if (txnId != null) {
handler.rollback(txnId);
}
throw e;
}
handler.commit(txnId);
} else {
// single request, a static request
ODataRequest partRequest = part.getRequests().get(0);