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 2016/05/24 07:41:43 UTC

olingo-odata2 git commit: "Deep insert fix and Dual access changes"

Repository: olingo-odata2
Updated Branches:
  refs/heads/master 2e5b98c5c -> 46afc9901


"Deep insert fix and Dual access changes"

Signed-off-by: Christian Amend <ch...@sap.com>


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

Branch: refs/heads/master
Commit: 46afc9901873094faa8d3bb337d8ba2d6706aaaf
Parents: 2e5b98c
Author: Shankara G <sh...@sap.com>
Authored: Tue May 17 10:39:30 2016 +0530
Committer: Christian Amend <ch...@sap.com>
Committed: Tue May 24 09:41:24 2016 +0200

----------------------------------------------------------------------
 .../core/access/data/JPAEntityParser.java       | 67 ++++++++++++++------
 .../jpa/processor/core/access/data/JPALink.java | 50 +++++++++------
 2 files changed, 80 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/46afc990/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
index 203712c..47361a5 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
@@ -45,6 +45,7 @@ import org.apache.olingo.odata2.api.edm.EdmStructuralType;
 import org.apache.olingo.odata2.api.edm.EdmTypeKind;
 import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
 import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
 
 public final class JPAEntityParser {
 
@@ -113,7 +114,15 @@ public final class JPAEntityParser {
         if (method == null) {
           String methodName = jpaEmbeddableKeyMap.get(jpaEntityAccessKey).get(propertyName);
           if (methodName != null) {
-            propertyValue = getEmbeddablePropertyValue(methodName, propertyValue);
+        	  boolean isVirtualAccess = false; 
+        	  if (property.getMapping() != null && property.getMapping() instanceof JPAEdmMappingImpl) {
+        		  isVirtualAccess = ((JPAEdmMappingImpl) property.getMapping()).isVirtualAccess();
+        	  }
+        	if (isVirtualAccess) {
+        		propertyValue = getEmbeddablePropertyValue(methodName, propertyValue, true);
+        	} else {
+        		propertyValue = getEmbeddablePropertyValue(methodName, propertyValue);
+        	}
           }
         } else {
           propertyValue = getPropertyValue(accessModifierMap.get(propertyName), propertyValue, propertyName);
@@ -174,7 +183,8 @@ public final class JPAEntityParser {
     			methodName = getAccessModifierName(navigationProperty.getName(),
     					navigationProperty.getMapping(), ACCESS_MODIFIER_GET);
     			Method getterMethod = null;
-    			if(((JPAEdmMapping)navigationProperty.getMapping()).isVirtualAccess()) {
+    			JPAEdmMapping jpaEdmMapping = (JPAEdmMapping)navigationProperty.getMapping();
+    			if(jpaEdmMapping != null && jpaEdmMapping.isVirtualAccess()) {
     				getterMethod = jpaEntity.getClass().getMethod(ACCESS_MODIFIER_GET, String.class);
     			}else{
     				getterMethod = jpaEntity.getClass()
@@ -392,7 +402,7 @@ public final class JPAEntityParser {
     }
   }
 
-  public Object getEmbeddablePropertyValue(final String methodName, final Object jpaEntity)
+  public Object getEmbeddablePropertyValue(final String methodName, final Object jpaEntity, boolean isVirtualAccess)
       throws ODataJPARuntimeException {
 
     String[] nameParts = methodName.split("\\.");
@@ -403,7 +413,13 @@ public final class JPAEntityParser {
         if (propertyValue == null) {
           break;
         }
-        method = propertyValue.getClass().getMethod(namePart, (Class<?>[]) null);
+        if (isVirtualAccess) {
+
+        	method = propertyValue.getClass().getMethod(ACCESS_MODIFIER_GET, String.class);
+        	namePart = namePart.replaceFirst(ACCESS_MODIFIER_GET, "");
+        } else {
+        	method = propertyValue.getClass().getMethod(namePart, (Class<?>[]) null);
+        }
         method.setAccessible(true);
         propertyValue = getPropertyValue(method, propertyValue,namePart);
       }
@@ -415,6 +431,12 @@ public final class JPAEntityParser {
     return propertyValue;
   }
 
+  public Object getEmbeddablePropertyValue(final String methodName, final Object jpaEntity)
+	      throws ODataJPARuntimeException {
+
+	  return getEmbeddablePropertyValue(methodName, jpaEntity, false);
+  }
+  
   public static String toString(final Character[] input) {
     if (input == null) {
       return null;
@@ -497,22 +519,29 @@ public final class JPAEntityParser {
     try {
 
       JPAEdmMapping navPropMapping = (JPAEdmMapping) navigationProperty.getMapping();
-      String name = getAccessModifierName(navigationProperty.getName(), (EdmMapping) navPropMapping, accessModifier);
 
+      String name;
       Class<?>[] params = null;
-      if (accessModifier.equals(ACCESS_MODIFIER_SET)) {
-        EdmAssociationEnd end = navigationProperty.getRelationship().getEnd(navigationProperty.getToRole());
-        switch (end.getMultiplicity()) {
-        case MANY:
-          params = new Class<?>[] { navPropMapping.getJPAType() };
-          break;
-        case ONE:
-          params = new Class<?>[] { ((JPAEdmMapping) end.getEntityType().getMapping()).getJPAType() };
-        default:
-          break;
-        }
+      if (navPropMapping != null && navPropMapping.isVirtualAccess()) {
+  
+    	  return jpaEntityType.getMethod(ACCESS_MODIFIER_SET, String.class, Object.class);
+      } else {
+	      name = getAccessModifierName(navigationProperty.getName(), (EdmMapping) navPropMapping, accessModifier);
+	
+	      if (accessModifier.equals(ACCESS_MODIFIER_SET)) {
+	        EdmAssociationEnd end = navigationProperty.getRelationship().getEnd(navigationProperty.getToRole());
+	        switch (end.getMultiplicity()) {
+	        case MANY:
+	          params = new Class<?>[] { navPropMapping.getJPAType() };
+	          break;
+	        case ONE:
+	          params = new Class<?>[] { ((JPAEdmMapping) end.getEntityType().getMapping()).getJPAType() };
+	        default:
+	          break;
+	        }
+	      }
+	      return jpaEntityType.getMethod(name, params);
       }
-      return jpaEntityType.getMethod(name, params);
 
     } catch (NoSuchMethodException e) {
       throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
@@ -555,7 +584,7 @@ public final class JPAEntityParser {
           } else {
         	  if (accessModifier.equals(ACCESS_MODIFIER_SET)) {
         		  JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) property.getMapping();
-        		  if(jpaEdmMapping.isVirtualAccess()) {
+        		  if(jpaEdmMapping != null && jpaEdmMapping.isVirtualAccess()) {
         			  accessModifierMap.put(propertyName, jpaEntityType.getMethod(ACCESS_MODIFIER_SET,
         					  new Class<?>[] { String.class,Object.class }));
         		  }else {
@@ -619,4 +648,4 @@ public final class JPAEntityParser {
     return edmProperties;
   }
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/46afc990/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 dd806a5..06db261 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
@@ -49,6 +49,7 @@ import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelExcepti
 import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
 import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
 import org.apache.olingo.odata2.jpa.processor.core.ODataEntityParser;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
 
 public class JPALink {
 
@@ -213,26 +214,39 @@ public class JPALink {
     if (targetJPAEntities == null || sourceJPAEntity == null || navigationProperty == null) {
       return;
     }
+
     try {
+
       JPAEntityParser entityParser = new JPAEntityParser();
-      Method setMethod = entityParser.getAccessModifier(sourceJPAEntity.getClass(),
-          navigationProperty, JPAEntityParser.ACCESS_MODIFIER_SET);
-      switch (navigationProperty.getMultiplicity()) {
-      case MANY:
-        Method getMethod = entityParser.getAccessModifier(sourceJPAEntity.getClass(),
-            navigationProperty, JPAEntityParser.ACCESS_MODIFIER_GET);
-        Collection<Object> relatedEntities = (Collection<Object>) getMethod.invoke(sourceJPAEntity);
-        if (relatedEntities == null) {
-          throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.ERROR_JPQL_CREATE_REQUEST, null);
-        }
-        relatedEntities.addAll(targetJPAEntities);
-        setMethod.invoke(sourceJPAEntity, relatedEntities);
-        break;
-      case ONE:
-      case ZERO_TO_ONE:
-        setMethod.invoke(sourceJPAEntity, targetJPAEntities.iterator().next());
-        break;
-      }
+	  Method setMethod = entityParser.getAccessModifier(sourceJPAEntity.getClass(),
+			navigationProperty, JPAEntityParser.ACCESS_MODIFIER_SET);
+
+	  JPAEdmMappingImpl jpaEdmMappingImpl = null;
+	  if (navigationProperty.getMapping() instanceof JPAEdmMappingImpl) {
+	      jpaEdmMappingImpl = (JPAEdmMappingImpl) navigationProperty.getMapping();	
+	  }
+	  if (jpaEdmMappingImpl != null && jpaEdmMappingImpl.isVirtualAccess()) {
+		  setMethod.invoke(sourceJPAEntity, jpaEdmMappingImpl.getInternalName(), 
+				targetJPAEntities.iterator().next());
+	  } else {
+	      switch (navigationProperty.getMultiplicity()) {
+	      case MANY:
+	        Method getMethod = entityParser.getAccessModifier(sourceJPAEntity.getClass(),
+	            navigationProperty, JPAEntityParser.ACCESS_MODIFIER_GET);
+	        Collection<Object> relatedEntities = (Collection<Object>) getMethod.invoke(sourceJPAEntity);
+	        if (relatedEntities == null) {
+	          throw ODataJPARuntimeException.throwException(
+	              ODataJPARuntimeException.ERROR_JPQL_CREATE_REQUEST, null);
+	        }
+	        relatedEntities.addAll(targetJPAEntities);
+	        setMethod.invoke(sourceJPAEntity, relatedEntities);
+	        break;
+	      case ONE:
+	      case ZERO_TO_ONE:
+	        setMethod.invoke(sourceJPAEntity, targetJPAEntities.iterator().next());
+	        break;
+	      }
+	  }
     } catch (EdmException e) {
       throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
     } catch (IllegalArgumentException e) {