Repository: olingo-odata4
Updated Branches:
  refs/heads/OLINGO-564 2318953c2 -> 3c0990910


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


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/0d015cb7
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/0d015cb7
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/0d015cb7

Branch: refs/heads/OLINGO-564
Commit: 0d015cb7b6e89ac32573fd8021e142689f82beef
Parents: a5c51d6
Author: Ramesh Reddy <[email protected]>
Authored: Fri Apr 24 17:58:00 2015 -0500
Committer: Ramesh Reddy <[email protected]>
Committed: Fri Apr 24 17:58:00 2015 -0500

----------------------------------------------------------------------
 .../olingo/server/core/ServiceHandler.java      | 12 +++++++---
 .../server/core/requests/BatchRequest.java      | 23 +++++++++++++++-----
 2 files changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0d015cb7/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java
 
b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java
index 621f0de..2e84b40 100644
--- 
a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java
+++ 
b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/ServiceHandler.java
@@ -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.

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0d015cb7/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java
 
b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java
index 25af023..0547775 100644
--- 
a/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java
+++ 
b/lib/server-core-ext/src/main/java/org/apache/olingo/server/core/requests/BatchRequest.java
@@ -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);

Reply via email to