You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2013/08/30 11:43:39 UTC

git commit: [JPA:] Fix for Deep Inserts

Updated Branches:
  refs/heads/master b57f7febf -> 60b2eaf14


[JPA:] Fix for Deep Inserts


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

Branch: refs/heads/master
Commit: 60b2eaf140a78e81e6dd2f852eb4864fd416521b
Parents: b57f7fe
Author: Chandan V A <ch...@sap.com>
Authored: Fri Aug 30 15:13:22 2013 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Fri Aug 30 15:13:22 2013 +0530

----------------------------------------------------------------------
 .../core/jpa/access/data/JPAEntity.java         | 39 +++++++++++++-------
 .../core/jpa/access/data/JPAProcessorImpl.java  |  3 --
 2 files changed, 25 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/60b2eaf1/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java b/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java
index 7b59d60..31448c6 100644
--- a/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java
+++ b/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java
@@ -175,28 +175,39 @@ public class JPAEntity {
     }
     Map<String, Object> oDataEntryProperties = oDataEntry.getProperties();
     if (oDataEntry.containsInlineEntry()) {
-      try {
-        for (String navigationPropertyName : oDataEntityType.getNavigationPropertyNames()) {
-          ODataFeed feed = (ODataFeed) oDataEntry.getProperties().get(navigationPropertyName);
-          if (feed == null) {
-            continue;
-          }
-          List<ODataEntry> relatedEntries = feed.getEntries();
-          oDataEntryProperties.put(navigationPropertyName, relatedEntries);
-        }
-      } catch (EdmException e) {
-        throw ODataJPARuntimeException
-            .throwException(ODataJPARuntimeException.GENERAL
-                .addContent(e.getMessage()), e);
-      }
+      normalizeInlineEntries(oDataEntryProperties);
     }
     write(oDataEntryProperties, true);
   }
 
   public void create(final Map<String, Object> oDataEntryProperties) throws ODataJPARuntimeException {
+    normalizeInlineEntries(oDataEntryProperties);
     write(oDataEntryProperties, true);
   }
 
+  private void normalizeInlineEntries(final Map<String, Object> oDataEntryProperties) throws ODataJPARuntimeException {
+    List<ODataEntry> entries = null;
+    try {
+      for (String navigationPropertyName : oDataEntityType.getNavigationPropertyNames()) {
+        Object inline = oDataEntryProperties.get(navigationPropertyName);
+        if (inline instanceof ODataFeed) {
+          entries = ((ODataFeed) inline).getEntries();
+        } else if (inline instanceof ODataEntry) {
+          entries = new ArrayList<ODataEntry>();
+          entries.add((ODataEntry) inline);
+        }
+        if (entries != null) {
+          oDataEntryProperties.put(navigationPropertyName, entries);
+          entries = null;
+        }
+      }
+    } catch (EdmException e) {
+      throw ODataJPARuntimeException
+          .throwException(ODataJPARuntimeException.GENERAL
+              .addContent(e.getMessage()), e);
+    }
+  }
+
   public void update(final ODataEntry oDataEntry) throws ODataJPARuntimeException {
     if (oDataEntry == null) {
       throw ODataJPARuntimeException

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/60b2eaf1/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImpl.java
----------------------------------------------------------------------
diff --git a/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImpl.java b/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImpl.java
index 4c38bd3..6f266b9 100644
--- a/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImpl.java
+++ b/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImpl.java
@@ -331,7 +331,6 @@ public class JPAProcessorImpl implements JPAProcessor {
         return (List<T>) createList;
       }
     } catch (Exception e) {
-      em.getTransaction().rollback();
       throw ODataJPARuntimeException.throwException(
           ODataJPARuntimeException.ERROR_JPQL_CREATE_REQUEST, e);
     }
@@ -378,7 +377,6 @@ public class JPAProcessorImpl implements JPAProcessor {
       em.flush();
       em.getTransaction().commit();
     } catch (Exception e) {
-      em.getTransaction().rollback();
       throw ODataJPARuntimeException.throwException(
           ODataJPARuntimeException.ERROR_JPQL_UPDATE_REQUEST, e);
     }
@@ -416,7 +414,6 @@ public class JPAProcessorImpl implements JPAProcessor {
         em.flush();
         em.getTransaction().commit();
       } catch (Exception e) {
-        em.getTransaction().rollback();
         throw ODataJPARuntimeException.throwException(
             ODataJPARuntimeException.ERROR_JPQL_DELETE_REQUEST, e);
       }