You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/01/30 08:14:01 UTC

git commit: [OLINGO-129] Fixed handling for not instanciated complex value types

Updated Branches:
  refs/heads/Olingo-129_PocJpaDataStore d85c09dd2 -> 3cbebd2cf


[OLINGO-129] Fixed handling for not instanciated complex value types


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 3cbebd2cffbeba784ad9b4cb43a2cf3927017755
Parents: d85c09d
Author: Michael Bolz <mi...@apache.org>
Authored: Thu Jan 30 07:47:59 2014 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Thu Jan 30 07:47:59 2014 +0100

----------------------------------------------------------------------
 .../processor/core/ListsProcessor.java          | 15 ++++++++--
 .../processor/core/util/AnnotationHelper.java   | 30 ++++++++++++--------
 2 files changed, 31 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/3cbebd2c/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessor.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessor.java
index 721a0b1..e63ecf6 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessor.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessor.java
@@ -1569,9 +1569,17 @@ public class ListsProcessor extends DataSourceProcessor {
     for (final String propertyName : type.getPropertyNames()) {
       final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
       if (property.isSimple()) {
-        typeMap.put(propertyName, valueAccess.getPropertyType(data, property));
+        Object value = valueAccess.getPropertyType(data, property);
+        if(value != null) {
+          typeMap.put(propertyName, value);
+        }
       } else {
-        typeMap.put(propertyName, getStructuralTypeTypeMap(valueAccess.getPropertyValue(data, property),
+        Object value = valueAccess.getPropertyValue(data, property);
+        if(value == null) {
+          Class<?> complexClass = valueAccess.getPropertyType(data, property);
+          value = createInstance(complexClass);
+        }
+        typeMap.put(propertyName, getStructuralTypeTypeMap(value,
             (EdmStructuralType) property.getType()));
       }
     }
@@ -1583,6 +1591,9 @@ public class ListsProcessor extends DataSourceProcessor {
 
   private <T> void setStructuralTypeValuesFromMap(final T data, final EdmStructuralType type,
       final Map<String, Object> valueMap, final boolean merge) throws ODataException {
+    if(data == null) {
+      throw new ODataException("Unable to set structural type values to NULL data.");
+    }
     ODataContext context = getContext();
     final int timingHandle =
         context.startRuntimeMeasurement(getClass().getSimpleName(), "setStructuralTypeValuesFromMap");

http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/3cbebd2c/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java
index 54ffb49..c3c146f 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java
@@ -406,26 +406,35 @@ public class AnnotationHelper {
     return null;
   }
 
-  public Class<?> getFieldTypeForProperty(final Object instance, final String propertyName)
+  public Class<?> getFieldTypeForProperty(final Class<?> clazz, final String propertyName)
       throws ODataAnnotationException {
-    if (instance == null) {
+    if (clazz == null) {
       return null;
     }
 
-    Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
+    Field field = getFieldForPropertyName(propertyName, clazz, true);
     if (field == null) {
       throw new ODataAnnotationException("No field for property '" + propertyName
-          + "' found at class '" + instance.getClass() + "'.");
+          + "' found at class '" + clazz + "'.");
     }
     return field.getType();
   }
 
+  public Class<?> getFieldTypeForProperty(final Object instance, final String propertyName)
+      throws ODataAnnotationException {
+    if (instance == null) {
+      return null;
+    }
+
+    return getFieldTypeForProperty(instance.getClass(), propertyName);
+  }
+
   public Object getValueForProperty(final Object instance, final String propertyName) throws ODataAnnotationException {
     if (instance == null) {
       return null;
     }
 
-    Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
+    Field field = getFieldForPropertyName(propertyName, instance.getClass(), true);
     if (field == null) {
       throw new ODataAnnotationException("No field for property '" + propertyName
           + "' found at class '" + instance.getClass() + "'.");
@@ -435,19 +444,16 @@ public class AnnotationHelper {
 
   public void setValueForProperty(final Object instance, final String propertyName, final Object propertyValue) {
     if (instance != null) {
-      Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
+      Field field = getFieldForPropertyName(propertyName, instance.getClass(), true);
       if (field != null) {
         setFieldValue(instance, field, propertyValue);
       }
     }
   }
 
-  private Field getFieldForPropertyName(final Object instance, final String propertyName,
+  private Field getFieldForPropertyName(final String propertyName,
       final Class<?> resultClass, final boolean inherited) {
-    if (instance == null) {
-      return null;
-    }
-
+    
     Field[] fields = resultClass.getDeclaredFields();
     for (Field field : fields) {
       EdmProperty property = field.getAnnotation(EdmProperty.class);
@@ -462,7 +468,7 @@ public class AnnotationHelper {
 
     Class<?> superClass = resultClass.getSuperclass();
     if (inherited && superClass != Object.class) {
-      return getFieldForPropertyName(instance, propertyName, superClass, true);
+      return getFieldForPropertyName(propertyName, superClass, true);
     }
 
     return null;