Repository: olingo-odata2
Updated Branches:
  refs/heads/master a9f2e4156 -> 6790766c1


[Olingo-1147]Entity read not working due to normalization


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

Branch: refs/heads/master
Commit: 6790766c19f3a7ee150e921a6cd87f465cfb6f36
Parents: a9f2e41
Author: Archana Rai <archana....@sap.com>
Authored: Mon Nov 20 12:03:27 2017 +0530
Committer: Archana Rai <archana....@sap.com>
Committed: Mon Nov 20 12:03:27 2017 +0530

----------------------------------------------------------------------
 .../core/access/data/JPAProcessorImpl.java      | 20 ++++++++++++++------
 .../core/access/data/JPAQueryBuilder.java       | 18 ++++++++++++++++++
 2 files changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6790766c/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 6920c8f..577e80a 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
@@ -30,6 +30,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
 import javax.persistence.Query;
 import javax.persistence.TemporalType;
 
@@ -290,12 +291,15 @@ public class JPAProcessorImpl implements JPAProcessor {
     }
     Object selectedObject = readEntity(new 
JPAQueryBuilder(oDataJPAContext).build(uriParserResultView));
     if (selectedObject != null) {
-
-      boolean isLocalTransaction = setTransaction();
-      em.remove(selectedObject);
-      em.flush();
-      if (isLocalTransaction) {
-        oDataJPAContext.getODataJPATransaction().commit();
+      try{
+        boolean isLocalTransaction = setTransaction();
+        em.remove(selectedObject);
+        em.flush(); 
+        if (isLocalTransaction) {
+          oDataJPAContext.getODataJPATransaction().commit();
+        }
+      } catch(PersistenceException e){
+        em.getTransaction().rollback();
       }
     }
     return selectedObject;
@@ -425,6 +429,10 @@ public class JPAProcessorImpl implements JPAProcessor {
     } catch (EdmException e) {
       throw ODataJPARuntimeException.throwException(
           ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
+    } catch (PersistenceException e) {
+      em.getTransaction().rollback();
+      throw ODataJPARuntimeException.throwException(
+          ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
     }
     return jpaEntity;
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/6790766c/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAQueryBuilder.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAQueryBuilder.java
 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAQueryBuilder.java
index 3319fc3..b1d1a99 100644
--- 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAQueryBuilder.java
+++ 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAQueryBuilder.java
@@ -275,6 +275,9 @@ public class JPAQueryBuilder {
     //check if clause values are string with x.y.z format
     //starting with quotes;
     String query = checkConditionValues(jpqlQuery);
+    //remove any orderby clause parameters  with x.y.z format
+    //no normalization for such clause
+    query = removeExtraClause(jpqlQuery);
     // check if normalization is needed (if query contains "x.y.z" elements
     // starting with space or parenthesis)
     Matcher normalizationNeededMatcher = 
NORMALIZATION_NEEDED_PATTERN.matcher(query);
@@ -330,6 +333,7 @@ public class JPAQueryBuilder {
           alias + JPQLStatement.DELIMITER.PERIOD);
       //check for values like "x.y.z"
       query = checkConditionValues(normalizedJpqlQuery);
+      query = removeExtraClause(normalizedJpqlQuery);
       // check if further normalization is needed
       normalizationNeededMatcher = NORMALIZATION_NEEDED_PATTERN.matcher(query);
       normalizationNeeded = normalizationNeededMatcher.find();
@@ -342,6 +346,20 @@ public class JPAQueryBuilder {
   }
 
   /**
+   * Check if the statement contains ORDERBY having x.y.z kind of format
+   * It will remove those values before checking for normalization 
+   * and later added back
+   * */
+  private static String removeExtraClause(String jpqlQuery) {
+    String query = jpqlQuery;
+    if(query.contains(JPQLStatement.KEYWORD.ORDERBY )){
+      int index = query.indexOf(JPQLStatement.KEYWORD.ORDERBY);
+      query = query.substring(0, index);  
+    }
+    return query;
+  }
+  
+  /**
    * Check if the statement contains string values having x.y.z kind of format
    * It will replace those values with parameters before checking for 
normalization 
    * and later added back

Reply via email to