Repository: olingo-odata2
Updated Branches:
  refs/heads/OLINGO-JPA-Fixes 67d646dca -> a1f6d1f5f


[OLINGO-976] Added default ODataJPATransaction for CMP


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

Branch: refs/heads/OLINGO-JPA-Fixes
Commit: a1f6d1f5f76a85567577e32409219b13a30928b5
Parents: 67d646d
Author: mibo <[email protected]>
Authored: Fri Jul 1 06:48:42 2016 +0200
Committer: mibo <[email protected]>
Committed: Fri Jul 1 06:48:42 2016 +0200

----------------------------------------------------------------------
 .../jpa/processor/core/ODataJPAContextImpl.java |  9 +++-
 .../ODataJPATransactionContainerManaged.java    | 49 ++++++++++++++++++++
 2 files changed, 56 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a1f6d1f5/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 75e5174..1fe8f9d 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
@@ -173,9 +173,14 @@ public class ODataJPAContextImpl implements 
ODataJPAContext {
   public ODataJPATransaction getODataJPATransaction() {
     if (transaction == null) {
       transaction = 
odataContext.getServiceFactory().getCallback(ODataJPATransaction.class);
-      // Fallback to RESOURCE_LOCAL based transaction
+      // fallback to default implementations
       if (transaction == null) {
-        transaction = new ODataJPATransactionLocalDefault(getEntityManager());
+        if(isContainerManaged()) {
+          transaction = new ODataJPATransactionContainerManaged();
+        } else {
+          // Fallback to RESOURCE_LOCAL based transaction
+          transaction = new 
ODataJPATransactionLocalDefault(getEntityManager());
+        }
       }
     }
     return transaction;

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/a1f6d1f5/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPATransactionContainerManaged.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPATransactionContainerManaged.java
 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPATransactionContainerManaged.java
new file mode 100644
index 0000000..5a08c74
--- /dev/null
+++ 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPATransactionContainerManaged.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.core;
+
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPATransaction;
+
+/**
+ * <code>ODataJPATransactionContainerManaged</code> only implements the 
methods for
+ * <code>ODataJPATransaction</code> bot does nothing for all methods because 
the
+ * whole persistence is managed by the environment (CMP).
+ */
+public class ODataJPATransactionContainerManaged implements 
ODataJPATransaction {
+  @Override
+  public void begin() {
+    /** do nothing for CMP */
+  }
+
+  @Override
+  public void commit() {
+    /** do nothing for CMP */
+  }
+
+  @Override
+  public void rollback() {
+    /** do nothing for CMP */
+  }
+
+  @Override
+  public boolean isActive() {
+    /** do nothing for CMP */
+    return false;
+  }
+}

Reply via email to