Repository: olingo-odata2
Updated Branches:
  refs/heads/master bef01c288 -> b081eed85


[OLINGO-895] First draft for virtual access implementation

Based on the patch files which were contributed to Olingo. The patch files
can be found in our JIRA: https://issues.apache.org/jira/browse/OLINGO-895


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

Branch: refs/heads/master
Commit: 32689c14548ad4973b97ea970635b951d8f5b96b
Parents: eb806b9
Author: Christian Amend <[email protected]>
Authored: Thu Mar 3 15:42:46 2016 +0100
Committer: Christian Amend <[email protected]>
Committed: Thu Mar 3 15:42:46 2016 +0100

----------------------------------------------------------------------
 .../jpa/processor/api/model/JPAEdmMapping.java  |  4 ++
 .../processor/core/access/data/JPAEntity.java   | 16 +++--
 .../core/access/data/JPAEntityParser.java       | 66 +++++++++++++-------
 .../processor/core/model/JPAEdmMappingImpl.java | 11 ++++
 4 files changed, 69 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/32689c14/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmMapping.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmMapping.java
 
b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmMapping.java
index 44f0f29..27fb683 100644
--- 
a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmMapping.java
+++ 
b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmMapping.java
@@ -75,5 +75,9 @@ public interface JPAEdmMapping {
    * @return JPA EntityListener type
    */
   public Class<? extends ODataJPATombstoneEntityListener> 
getODataJPATombstoneEntityListener();
+  
+  public boolean isVirtualAccess();
+  
+  public void setVirtualAccess(boolean virtualAccess);
 
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/32689c14/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
index 07564d5..e8bcbeb 100644
--- 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
+++ 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
@@ -206,7 +206,7 @@ public class JPAEntity {
 
   @SuppressWarnings("unchecked")
   protected void setComplexProperty(Method accessModifier, final Object 
jpaEntity,
-      final EdmStructuralType edmComplexType, final HashMap<String, Object> 
propertyValue)
+      final EdmStructuralType edmComplexType, final HashMap<String, Object> 
propertyValue, String propertyName)
       throws EdmException, IllegalAccessException, IllegalArgumentException, 
InvocationTargetException,
       InstantiationException, ODataJPARuntimeException, NoSuchMethodException, 
SecurityException, SQLException {
 
@@ -223,19 +223,23 @@ public class JPAEntity {
       if 
(edmTyped.getType().getKind().toString().equals(EdmTypeKind.COMPLEX.toString()))
 {
         EdmStructuralType structualType = (EdmStructuralType) 
edmTyped.getType();
         setComplexProperty(accessModifier, embeddableObject, structualType, 
(HashMap<String, Object>) propertyValue
-            .get(edmPropertyName));
+            .get(edmPropertyName),propertyName);
       } else {
         setProperty(accessModifier, embeddableObject, 
propertyValue.get(edmPropertyName), (EdmSimpleType) edmTyped
-            .getType());
+            .getType(),propertyName);
       }
     }
   }
 
   @SuppressWarnings({ "unchecked", "rawtypes" })
   protected void setProperty(final Method method, final Object entity, final 
Object entityPropertyValue,
-      final EdmSimpleType type) throws
+      final EdmSimpleType type, String propertyName) throws
       IllegalAccessException, IllegalArgumentException, 
InvocationTargetException, ODataJPARuntimeException {
     if (entityPropertyValue != null) {
+       if(method.getParameterTypes().length>1) {
+                method.invoke(entity, propertyName,entityPropertyValue);
+                return;
+       }
       Class<?> parameterType = method.getParameterTypes()[0];
       if (type != null && type.getDefaultType().equals(String.class)) {
         if (parameterType.equals(String.class)) {
@@ -422,7 +426,7 @@ public class JPAEntity {
           }
           accessModifier = accessModifiersWrite.get(propertyName);
           setProperty(accessModifier, jpaEntity, 
oDataEntryProperties.get(propertyName), (EdmSimpleType) edmTyped
-              .getType());
+              .getType(),propertyName);
 
           break;
         case COMPLEX:
@@ -430,7 +434,7 @@ public class JPAEntity {
           accessModifier = accessModifiersWrite.get(propertyName);
           setComplexProperty(accessModifier, jpaEntity,
               structuralType,
-              (HashMap<String, Object>) 
oDataEntryProperties.get(propertyName));
+              (HashMap<String, Object>) 
oDataEntryProperties.get(propertyName),propertyName);
           break;
         case NAVIGATION:
         case ENTITY:

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/32689c14/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 03ef879..c8e3c8e 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
@@ -116,7 +116,7 @@ public final class JPAEntityParser {
             propertyValue = getEmbeddablePropertyValue(methodName, 
propertyValue);
           }
         } else {
-          propertyValue = 
getPropertyValue(accessModifierMap.get(propertyName), propertyValue);
+          propertyValue = 
getPropertyValue(accessModifierMap.get(propertyName), propertyValue, 
propertyName);
         }
         if (property.getType().getKind()
             .equals(EdmTypeKind.COMPLEX)) {
@@ -169,17 +169,24 @@ public final class JPAEntityParser {
     if (navigationPropertyList != null
         && navigationPropertyList.size() != 0) {
 
-      try {
-        for (EdmNavigationProperty navigationProperty : 
navigationPropertyList) {
-          methodName = getAccessModifierName(navigationProperty.getName(),
-              navigationProperty.getMapping(), ACCESS_MODIFIER_GET);
-          Method getterMethod = jpaEntity.getClass()
-              .getMethod(methodName, (Class<?>[]) null);
-          getterMethod.setAccessible(true);
-          result = getPropertyValue(getterMethod, jpaEntity);
-          navigationMap.put(navigationProperty.getName(), result);
-        }
-      } catch (IllegalArgumentException e) {
+       try {
+               for (EdmNavigationProperty navigationProperty : 
navigationPropertyList) {
+                       methodName = 
getAccessModifierName(navigationProperty.getName(),
+                                       navigationProperty.getMapping(), 
ACCESS_MODIFIER_GET);
+                       Method getterMethod = null;
+                       
if(((JPAEdmMapping)navigationProperty.getMapping()).isVirtualAccess()) {
+                               getterMethod = 
jpaEntity.getClass().getMethod("get", String.class);
+                       }else{
+                               getterMethod = jpaEntity.getClass()
+                                               .getMethod(methodName, 
(Class<?>[]) null);
+                       }
+
+                       getterMethod.setAccessible(true);
+                       result = getPropertyValue(getterMethod, jpaEntity,
+                                       
navigationProperty.getMapping().getInternalName());
+                       navigationMap.put(navigationProperty.getName(), result);
+               }
+       } catch (IllegalArgumentException e) {
         throw 
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION,
 e);
       } catch (EdmException e) {
         throw 
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION,
 e);
@@ -215,7 +222,8 @@ public final class JPAEntityParser {
     return getAccessModifiers(getEdmProperties(structuralType), 
jpaEntity.getClass(), accessModifier);
   }
 
-  public static Object getPropertyValue(final Method method, final Object 
entity) throws ODataJPARuntimeException {
+  public static Object getPropertyValue(final Method method, final Object 
entity, String propertyName) 
+                 throws ODataJPARuntimeException {
     Object propertyValue = null;
     if (method == null) {
       return null;
@@ -246,7 +254,11 @@ public final class JPAEntityParser {
       } else if (returnType.equals(Clob.class)) {
         propertyValue = getString((Clob) method.invoke(entity));
       } else {
-        propertyValue = method.invoke(entity);
+         if(method.getParameterTypes().length>0) {
+                 propertyValue = method.invoke(entity,propertyName);
+         } else {
+                 propertyValue = method.invoke(entity);
+         }
       }
     } catch (IllegalAccessException e) {
       throw 
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION,
 e);
@@ -393,7 +405,7 @@ public final class JPAEntityParser {
         }
         method = propertyValue.getClass().getMethod(namePart, (Class<?>[]) 
null);
         method.setAccessible(true);
-        propertyValue = getPropertyValue(method, propertyValue);
+        propertyValue = getPropertyValue(method, propertyValue,namePart);
       }
     } catch (NoSuchMethodException e) {
       throw 
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION,
 e);
@@ -541,13 +553,23 @@ public final class JPAEntityParser {
               continue;
             }
           } else {
-            if (accessModifier.equals(ACCESS_MODIFIER_SET)) {
-              JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) 
property.getMapping();
-              accessModifierMap.put(propertyName, 
jpaEntityType.getMethod(methodName,
-                  new Class<?>[] { jpaEdmMapping.getJPAType() }));
-            } else {
-              method = jpaEntityType.getMethod(methodName, (Class<?>[]) null);
-            }
+                 if (accessModifier.equals(ACCESS_MODIFIER_SET)) {
+                         JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) 
property.getMapping();
+                         if(jpaEdmMapping.isVirtualAccess()) {
+                                 accessModifierMap.put(propertyName, 
jpaEntityType.getMethod("set",
+                                                 new Class<?>[] { 
String.class,Object.class }));
+                         }else {
+                                 accessModifierMap.put(propertyName, 
jpaEntityType.getMethod(methodName,
+                                                 new Class<?>[] { 
jpaEdmMapping.getJPAType() }));
+                         }
+                 } else {
+                         JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) 
property.getMapping();
+                         if(jpaEdmMapping.isVirtualAccess()) {
+                                 method = jpaEntityType.getMethod("get", 
String.class);
+                         }else{
+                                 method = jpaEntityType.getMethod(methodName, 
(Class<?>[]) null);
+                         }
+                 }
           }
         } catch (EdmException exp) {
           throw 
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION,
 exp);

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/32689c14/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmMappingImpl.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmMappingImpl.java
 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmMappingImpl.java
index 5944191..b07c7ca 100644
--- 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmMappingImpl.java
+++ 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmMappingImpl.java
@@ -27,6 +27,7 @@ public class JPAEdmMappingImpl extends Mapping implements 
JPAEdmMapping {
   private String columnName = null;
   private Class<?> type = null;
   private Class<? extends ODataJPATombstoneEntityListener> entityListener = 
null;
+  private boolean isVirtualAccess;
 
   @Override
   public void setJPAColumnName(final String name) {
@@ -60,4 +61,14 @@ public class JPAEdmMappingImpl extends Mapping implements 
JPAEdmMapping {
   public Class<? extends ODataJPATombstoneEntityListener> 
getODataJPATombstoneEntityListener() {
     return entityListener;
   }
+
+  @Override
+  public boolean isVirtualAccess() {
+         return isVirtualAccess;
+  }
+
+  @Override
+  public void setVirtualAccess(boolean virtualAccess) {
+         this.isVirtualAccess=virtualAccess;
+  }
 }

Reply via email to