Repository: olingo-odata2
Updated Branches:
  refs/heads/master 5d88b96e8 -> c04abbad1


[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/c04abbad
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/c04abbad
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/c04abbad

Branch: refs/heads/master
Commit: c04abbad175b615954fc7bf86500230fdfb1501d
Parents: 5d88b96
Author: Archana Rai <archana....@sap.com>
Authored: Wed Nov 29 16:03:15 2017 +0530
Committer: Archana Rai <archana....@sap.com>
Committed: Wed Nov 29 16:03:15 2017 +0530

----------------------------------------------------------------------
 .../jpa/processor/api/jpql/JPQLStatement.java   |  1 +
 .../processor/core/ODataExpressionParser.java   | 11 ++--
 .../JPQLSelectSingleStatementBuilderTest.java   | 54 +++++++++++++++++---
 3 files changed, 56 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c04abbad/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLStatement.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLStatement.java
 
b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLStatement.java
index 57660b0..6d1f22d 100644
--- 
a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLStatement.java
+++ 
b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLStatement.java
@@ -115,6 +115,7 @@ public class JPQLStatement {
     public static final String AND = "AND";
     public static final String NOT = "NOT";
     public static final String OR = "OR";
+    public static final String LIKE = "LIKE";
 
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c04abbad/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
index a2266df..4673675 100644
--- 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
+++ 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
@@ -403,9 +403,14 @@ public class ODataExpressionParser {
           || edmSimpleType == 
EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) {
         literal = literal.substring(literal.indexOf('\''), 
literal.indexOf('}'));
       }
-
-      keyFilters.append(tableAlias + JPQLStatement.DELIMITER.PERIOD + 
propertyName + JPQLStatement.DELIMITER.SPACE
-          + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + 
literal);
+      if(edmSimpleType == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()){
+        keyFilters.append(tableAlias + JPQLStatement.DELIMITER.PERIOD + 
propertyName + JPQLStatement.DELIMITER.SPACE
+            + JPQLStatement.Operator.LIKE + JPQLStatement.DELIMITER.SPACE + 
literal +  " ESCAPE '\\'");
+       
+      }else{
+        keyFilters.append(tableAlias + JPQLStatement.DELIMITER.PERIOD + 
propertyName + JPQLStatement.DELIMITER.SPACE
+            + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + 
literal);
+      }
     }
     if (keyFilters.length() > 0) {
       Map<String, Map<Integer, Object>> parameterizedExpressionMap = 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c04abbad/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilderTest.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilderTest.java
 
b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilderTest.java
index 63b5948..1a7b13b 100644
--- 
a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilderTest.java
+++ 
b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilderTest.java
@@ -58,7 +58,8 @@ public class JPQLSelectSingleStatementBuilderTest {
 
   }
 
-  private JPQLSelectSingleContext createSelectContext() throws 
ODataJPARuntimeException, EdmException {
+  private JPQLSelectSingleContext createSelectContext(EdmSimpleType edmType) 
throws ODataJPARuntimeException,
+  EdmException {
     // Object Instantiation
 
     JPQLSelectSingleContext JPQLSelectSingleContextImpl = null;// new 
JPQLSelectSingleContextImpl();
@@ -71,16 +72,14 @@ public class JPQLSelectSingleStatementBuilderTest {
     // Setting up the expected value
     KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
     EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
-    EdmSimpleType edmType = EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance();
+   
     JPAEdmMappingImpl edmMapping = 
EasyMock.createMock(JPAEdmMappingImpl.class);
     EasyMock.expect(edmMapping.getJPAType())
     .andStubReturn(null);
     EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
-    EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
+    setSpecificProperties(keyPredicate, kpProperty, edmType);
     try {
       EasyMock.expect(kpProperty.getName()).andStubReturn("Field1");
-      EasyMock.expect(kpProperty.getType()).andStubReturn(edmType);
-
       EasyMock.expect(kpProperty.getMapping()).andStubReturn(edmMapping);
 
     } catch (EdmException e2) {
@@ -111,6 +110,21 @@ public class JPQLSelectSingleStatementBuilderTest {
     return JPQLSelectSingleContextImpl;
   }
 
+  private void setSpecificProperties(KeyPredicate keyPredicate, EdmProperty 
kpProperty,  EdmSimpleType edmType) {
+
+    try {
+      EasyMock.expect(kpProperty.getType()).andStubReturn(edmType);
+      if(EdmSimpleTypeKind.Int32.name().equals(edmType.getName())){
+        EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
+      }else{
+        EasyMock.expect(keyPredicate.getLiteral()).andStubReturn(" MiMe-Id1");
+      }
+    } catch (EdmException e) {
+      fail("this should not happen");
+    }
+  
+  }
+
   /**
    * Test method for {@link 
org.apache.olingo.odata2.processor.jpa.jpql.JPQLSelectSingleStatementBuilder#build)}.
    * @throws EdmException
@@ -119,8 +133,8 @@ public class JPQLSelectSingleStatementBuilderTest {
 
   @Test
   public void testBuildSimpleQuery() throws EdmException, 
ODataJPARuntimeException {
-
-    JPQLSelectSingleContext JPQLSelectSingleContextImpl = 
createSelectContext();
+    EdmSimpleType edmType = EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance();
+    JPQLSelectSingleContext JPQLSelectSingleContextImpl = 
createSelectContext(edmType);
     JPQLSelectSingleStatementBuilder = new 
JPQLSelectSingleStatementBuilder(JPQLSelectSingleContextImpl);
 
     String query = JPQLSelectSingleStatementBuilder.build().toString();
@@ -137,4 +151,30 @@ public class JPQLSelectSingleStatementBuilderTest {
   
   }
 
+
+  /**
+   * Test method for {@link 
org.apache.olingo.odata2.processor.jpa.jpql.JPQLSelectSingleStatementBuilder#build)}.
+   * @throws EdmException
+   * @throws ODataJPARuntimeException
+   */
+
+  @Test
+  public void testBuildQueryWithSpecialChars() throws EdmException, 
ODataJPARuntimeException {
+    EdmSimpleType edmType = 
EdmSimpleTypeKind.String.getEdmSimpleTypeInstance();
+    JPQLSelectSingleContext JPQLSelectSingleContextImpl = 
createSelectContext(edmType);
+    JPQLSelectSingleStatementBuilder = new 
JPQLSelectSingleStatementBuilder(JPQLSelectSingleContextImpl);
+
+    String query = JPQLSelectSingleStatementBuilder.build().toString();
+    query = query.substring(0, query.indexOf("?"));
+    Map<String, Map<Integer, Object>> positionalParameters = 
+        ODataParameterizedWhereExpressionUtil.getParameterizedQueryMap();
+    for (Entry<String, Map<Integer, Object>> param : 
positionalParameters.entrySet()) {
+      for (Entry<Integer, Object> postionalParam : 
param.getValue().entrySet()) {
+        query += postionalParam.getValue();
+      }
+    }
+    
+    assertEquals("SELECT E1 FROM SalesOrderHeader E1 WHERE E1.Field1 LIKE  
MiMe-Id1", query);
+  
+  }
 }

Reply via email to