olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [1/2] olingo-odata2 git commit: [OLINGO-580] Support JTA based transactions in JPA processor
Date Fri, 27 Feb 2015 17:03:16 GMT
Repository: olingo-odata2
Updated Branches:
  refs/heads/master 676aad45d -> c6e0a1a7e


[OLINGO-580] Support JTA based transactions in JPA processor


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

Branch: refs/heads/master
Commit: dee84cf65981671ebdd09b2f6d932edbc463d772
Parents: 676aad4
Author: Michael Bolz <michael.bolz@sap.com>
Authored: Fri Feb 27 10:02:44 2015 +0100
Committer: Michael Bolz <michael.bolz@sap.com>
Committed: Fri Feb 27 10:02:44 2015 +0100

----------------------------------------------------------------------
 .../jpa/processor/api/ODataJPAContext.java      |  8 ++-
 .../processor/api/ODataJPAServiceFactory.java   | 29 ++++++++++-
 .../jpa/processor/api/ODataJPATransaction.java  | 48 +++++++++++++++++
 .../jpa/processor/core/ODataJPAContextImpl.java |  6 +++
 .../core/ODataJPAProcessorDefault.java          |  7 +--
 .../jpa/processor/core/access/data/JPALink.java |  9 ++--
 .../core/access/data/JPAProcessorImpl.java      | 14 ++---
 .../core/ODataJPAProcessorDefaultTest.java      | 12 +++++
 .../core/access/data/JPAProcessorImplTest.java  | 15 ++++++
 .../ODataJPATransactionLocalDefault.java        | 54 ++++++++++++++++++++
 .../ref/web/JPAReferenceServiceFactory.java     |  9 ++--
 11 files changed, 191 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dee84cf6/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAContext.java
b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAContext.java
index 9a57bf3..0ec7ca7 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAContext.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAContext.java
@@ -218,7 +218,7 @@ public interface ODataJPAContext {
 
   /**
    * The method sets the server side paging object
-   * @param an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAPaging}
+   * @param paging an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAPaging}
    */
   public void setPaging(JPAPaging paging);
 
@@ -227,4 +227,10 @@ public interface ODataJPAContext {
    * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAPaging}
    */
   public JPAPaging getPaging();
+
+   /**
+    * The transaction context
+    * @return transaction context
+    */
+   public ODataJPATransaction getODataJpaTransaction();
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dee84cf6/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
index 709a048..ba1248e 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
@@ -81,6 +81,7 @@ public abstract class ODataJPAServiceFactory extends ODataServiceFactory
{
   private ODataContext oDataContext;
   private boolean setDetailErrors = false;
   private OnJPAWriteContent onJPAWriteContent = null;
+  private ODataJPATransaction oDataJPATransaction = null;
 
   /**
    * Creates an OData Service based on the values set in
@@ -201,7 +202,33 @@ public abstract class ODataJPAServiceFactory extends ODataServiceFactory
{
         return (T) onJPAWriteContent;
       }
     }
-    return null;
+
+      if (oDataJPATransaction != null) {
+          if (callbackInterface.isAssignableFrom(ODataJPATransaction.class)) {
+              return (T) oDataJPATransaction;
+          }
+      }
+
+
+      return null;
   }
 
+  /**
+   * The methods sets the context with a callback implementation for JPA transaction specific
content.
+   * For details refer to {@link ODataJPATransaction}
+   * @param oDataJPATransaction is an instance of type
+   * {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPATransaction}
+   */
+  protected void setODataJPATransaction(final ODataJPATransaction oDataJPATransaction) {
+      this.oDataJPATransaction = oDataJPATransaction;
+  }
+
+  /**
+   * Simple method to retrieve the current ODataJPATransactionContext optimized for fast
access
+   *
+   * @return the current ODataJPATransaction
+   */
+  public ODataJPATransaction getDataJPATransaction() {
+      return oDataJPATransaction;
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dee84cf6/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPATransaction.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPATransaction.java
b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPATransaction.java
new file mode 100644
index 0000000..605e5d7
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPATransaction.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.jpa.processor.api;
+
+import org.apache.olingo.odata2.api.ODataCallback;
+
+/**
+ * Interface for JPA-Transaction abstraction. Default implementation is Resource local, while
additional
+ * an override may used to insert JTA compatible transactions as well.
+ *
+ */
+public interface ODataJPATransaction extends ODataCallback {
+  /**
+   * implement the start of the transaction
+   */
+  public void begin();
+
+  /**
+   * implement the commit of the transaction
+   */
+  public void commit();
+
+  /**
+   * implement the rollback of the transaction
+   */
+  public void rollback();
+
+  /**
+   * implement status of the transaction context
+   */
+  public boolean isActive();
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dee84cf6/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImpl.java
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImpl.java
index 43f1850..66d0ff0 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImpl.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImpl.java
@@ -25,6 +25,7 @@ import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
 import org.apache.olingo.odata2.api.processor.ODataContext;
 import org.apache.olingo.odata2.api.processor.ODataProcessor;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPATransaction;
 import org.apache.olingo.odata2.jpa.processor.api.access.JPAPaging;
 import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmExtension;
 
@@ -166,4 +167,9 @@ public class ODataJPAContextImpl implements ODataJPAContext {
   public JPAPaging getPaging() {
     return jpaPaging;
   }
+
+  @Override
+  public ODataJPATransaction getODataJpaTransaction() {
+      return odataContext.getServiceFactory().getCallback(ODataJPATransaction.class);
+  }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dee84cf6/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
index 6b1f40b..2d4e37e 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
@@ -264,21 +264,22 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
       throws ODataException {
     List<ODataResponse> responses = new ArrayList<ODataResponse>();
     try {
-      oDataJPAContext.getEntityManager().getTransaction().begin();
+      oDataJPAContext.getODataJpaTransaction().begin();
 
       for (ODataRequest request : requests) {
         oDataJPAContext.setODataContext(getContext());
         ODataResponse response = handler.handleRequest(request);
         if (response.getStatus().getStatusCode() >= HttpStatusCodes.BAD_REQUEST.getStatusCode())
{
           // Rollback
-          oDataJPAContext.getEntityManager().getTransaction().rollback();
+          oDataJPAContext.getODataJpaTransaction().rollback();
           List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
           errorResponses.add(response);
           return BatchResponsePart.responses(errorResponses).changeSet(false).build();
         }
         responses.add(response);
       }
-      oDataJPAContext.getEntityManager().getTransaction().commit();
+      oDataJPAContext.getODataJpaTransaction().commit();
+
 
       return BatchResponsePart.responses(responses).changeSet(true).build();
     } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dee84cf6/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java
index 64bf56c..7e3ae73 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java
@@ -27,7 +27,6 @@ import java.util.HashMap;
 import java.util.List;
 
 import javax.persistence.EntityManager;
-import javax.persistence.EntityTransaction;
 
 import org.apache.olingo.odata2.api.edm.EdmEntitySet;
 import org.apache.olingo.odata2.api.edm.EdmException;
@@ -44,6 +43,7 @@ import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
 import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
 import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPATransaction;
 import org.apache.olingo.odata2.jpa.processor.api.access.JPAProcessor;
 import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
 import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
@@ -149,10 +149,9 @@ public class JPALink {
 
   public void save() {
     EntityManager em = context.getEntityManager();
-    EntityTransaction tx = em.getTransaction();
-
+    ODataJPATransaction tx = context.getODataJpaTransaction();
     if (!tx.isActive()) {
-      em.getTransaction().begin();
+      tx.begin();
       if (sourceJPAEntity != null) {
         em.persist(sourceJPAEntity);
       }
@@ -160,7 +159,7 @@ public class JPALink {
         em.persist(targetJPAEntity);
         em.flush();
       }
-      em.getTransaction().commit();
+      tx.commit();
     }
 
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dee84cf6/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java
index d926daf..ef4d9dc 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java
@@ -26,7 +26,6 @@ import java.util.List;
 import java.util.Map;
 
 import javax.persistence.EntityManager;
-import javax.persistence.EntityTransaction;
 import javax.persistence.Query;
 
 import org.apache.olingo.odata2.api.commons.InlineCount;
@@ -50,6 +49,7 @@ import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPATombstoneContext;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPATombstoneEntityListener;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPATransaction;
 import org.apache.olingo.odata2.jpa.processor.api.access.JPAFunction;
 import org.apache.olingo.odata2.jpa.processor.api.access.JPAMethodContext;
 import org.apache.olingo.odata2.jpa.processor.api.access.JPAProcessor;
@@ -355,7 +355,7 @@ public class JPAProcessorImpl implements JPAProcessor {
         em.remove(selectedObject);
         em.flush();
         if (isLocalTransaction) {
-          em.getTransaction().commit();
+          oDataJPAContext.getODataJpaTransaction().commit();
         }
 
       } catch (Exception e) {
@@ -456,7 +456,7 @@ public class JPAProcessorImpl implements JPAProcessor {
       em.persist(jpaEntity);
       if (em.contains(jpaEntity)) {
         if (isLocalTransaction) {
-          em.getTransaction().commit();
+          oDataJPAContext.getODataJpaTransaction().commit();
         }
         return jpaEntity;
       }
@@ -507,7 +507,7 @@ public class JPAProcessorImpl implements JPAProcessor {
       }
       em.flush();
       if (isLocalTransaction) {
-        em.getTransaction().commit();
+        oDataJPAContext.getODataJpaTransaction().commit();
       }
     } catch (Exception e) {
       throw ODataJPARuntimeException.throwException(
@@ -572,9 +572,9 @@ public class JPAProcessorImpl implements JPAProcessor {
   }
 
   private boolean setTransaction() {
-    final EntityTransaction transaction = em.getTransaction();
-    if (!transaction.isActive()) {
-      em.getTransaction().begin();
+    ODataJPATransaction transactionContext = oDataJPAContext.getODataJpaTransaction();
+    if (!transactionContext.isActive()) {
+      transactionContext.begin();
       return true;
     }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dee84cf6/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java
b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java
index 8733181..195559e 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java
@@ -67,6 +67,7 @@ import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
 import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
 import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPATransaction;
 import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
 import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
 import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
@@ -320,6 +321,7 @@ public class ODataJPAProcessorDefaultTest extends JPAEdmTestModelView
{
     ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
     EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn("salesorderprocessing");
     EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory());
+    EasyMock.expect(odataJPAContext.getODataJpaTransaction()).andStubReturn(getLocalJpaTransaction());
     EasyMock.expect(odataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
     odataJPAContext.setODataContext((ODataContext) EasyMock.anyObject());
     EasyMock.expectLastCall().anyTimes();
@@ -328,6 +330,16 @@ public class ODataJPAProcessorDefaultTest extends JPAEdmTestModelView
{
     return odataJPAContext;
   }
 
+  private ODataJPATransaction getLocalJpaTransaction() {
+    ODataJPATransaction tx = EasyMock.createMock(ODataJPATransaction.class);
+    tx.begin(); // testing void method
+    tx.commit();// testing void method
+    tx.rollback();// testing void method
+    EasyMock.expect(tx.isActive()).andReturn(false);
+    EasyMock.replay(tx);
+    return tx;
+  }
+
   private EntityManagerFactory mockEntityManagerFactory() {
     EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
     EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dee84cf6/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
index f370c26..05afa5f 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
@@ -67,6 +67,7 @@ import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
 import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
 import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
 import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPATransaction;
 import org.apache.olingo.odata2.jpa.processor.api.access.JPAPaging;
 import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
 import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
@@ -285,6 +286,7 @@ public class JPAProcessorImplTest {
     ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
     EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn("salesorderprocessing");
     EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory());
+    EasyMock.expect(odataJPAContext.getODataJpaTransaction()).andStubReturn(getLocalJpaTransaction());
     EasyMock.expect(odataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
     EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(getLocalEntityManager());
     EasyMock.expect(odataJPAContext.getPageSize()).andReturn(10).anyTimes();
@@ -294,6 +296,19 @@ public class JPAProcessorImplTest {
     return odataJPAContext;
   }
 
+  private ODataJPATransaction getLocalJpaTransaction() {
+    ODataJPATransaction tx = EasyMock.createMock(ODataJPATransaction.class);
+    EasyMock.expect(tx.isActive()).andReturn(false);
+    tx.begin(); // testing void method
+    tx.commit();// testing void method
+    EasyMock.expect(tx.isActive()).andReturn(false);
+    tx.begin(); // testing void method
+    tx.commit();// testing void method
+    EasyMock.replay(tx);
+    return tx;
+  }
+
+
   private EntityManagerFactory mockEntityManagerFactory() {
     EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
     EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dee84cf6/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/ODataJPATransactionLocalDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/ODataJPATransactionLocalDefault.java
b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/ODataJPATransactionLocalDefault.java
new file mode 100644
index 0000000..9291962
--- /dev/null
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/ODataJPATransactionLocalDefault.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.jpa.processor.ref.extension;
+
+
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPATransaction;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+public class ODataJPATransactionLocalDefault implements ODataJPATransaction {
+
+  private EntityTransaction tx = null;
+
+  public ODataJPATransactionLocalDefault(EntityManager em) {
+      this.tx = em.getTransaction();
+  }
+
+  @Override
+  public void begin() {
+      tx.begin();
+  }
+
+  @Override
+  public void commit() {
+      tx.commit();
+  }
+
+  @Override
+  public void rollback() {
+      tx.rollback();
+  }
+
+  @Override
+  public boolean isActive() {
+      return tx.isActive();
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/dee84cf6/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
index 256ffdd..9452535 100644
--- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
@@ -25,6 +25,7 @@ import org.apache.olingo.odata2.jpa.processor.api.ODataJPAServiceFactory;
 import org.apache.olingo.odata2.jpa.processor.api.OnJPAWriteContent;
 import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
 import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmExtension;
+import org.apache.olingo.odata2.jpa.processor.ref.extension.ODataJPATransactionLocalDefault;
 import org.apache.olingo.odata2.jpa.processor.ref.extension.OnDBWriteContent;
 import org.apache.olingo.odata2.jpa.processor.ref.extension.SalesOrderProcessingExtension;
 import org.apache.olingo.odata2.jpa.processor.ref.factory.JPAEntityManagerFactory;
@@ -44,19 +45,21 @@ public class JPAReferenceServiceFactory extends ODataJPAServiceFactory
{
     oDataJPAContext.setEntityManagerFactory(JPAEntityManagerFactory.getEntityManagerFactory(PUNIT_NAME));
     oDataJPAContext.setPersistenceUnitName(PUNIT_NAME);
     oDataJPAContext.setJPAEdmMappingModel(MAPPING_MODEL);
-    oDataJPAContext
-        .setJPAEdmExtension((JPAEdmExtension) new SalesOrderProcessingExtension());
+    oDataJPAContext.setJPAEdmExtension(new SalesOrderProcessingExtension());
     oDataJPAContext.setPageSize(PAGE_SIZE);
     oDataJPAContext.setDefaultNaming(false);
     setErrorLevel();
     setOnWriteJPAContent(onDBWriteContent);
+    if(getDataJPATransaction() == null) {
+        setODataJPATransaction(new ODataJPATransactionLocalDefault(getODataJPAContext().getEntityManager()));
+    }
 
     return oDataJPAContext;
   }
 
   private void setErrorLevel() {
     ResourceBundle config = ResourceBundle.getBundle(CONFIG);
-    boolean error = Boolean.parseBoolean((String) config.getObject(SHOW_DETAIL_ERROR));
+    boolean error = Boolean.parseBoolean(config.getString(SHOW_DETAIL_ERROR));
     setDetailErrors(error);
   }
 }


Mime
View raw message