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/05/21 20:06:02 UTC

git commit: [OLINGO-129] Improved read result for one-to-many bi-directional navigation

Repository: olingo-odata2
Updated Branches:
  refs/heads/Olingo-129_PocJpaDataStore cb0a9cf14 -> 4528e8d36


[OLINGO-129] Improved read result for one-to-many bi-directional navigation


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

Branch: refs/heads/Olingo-129_PocJpaDataStore
Commit: 4528e8d362a5b16d6a1db00ef99aec486a98c4af
Parents: cb0a9cf
Author: Michael Bolz <mi...@apache.org>
Authored: Wed May 21 20:05:51 2014 +0200
Committer: Michael Bolz <mi...@apache.org>
Committed: Wed May 21 20:05:51 2014 +0200

----------------------------------------------------------------------
 .../core/datasource/AnnotationDataSource.java    | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/4528e8d3/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationDataSource.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationDataSource.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationDataSource.java
index 86fdc7e..b2b44ba 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationDataSource.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationDataSource.java
@@ -27,6 +27,7 @@ import org.apache.olingo.odata2.annotation.processor.core.util.AnnotationHelper.
 import org.apache.olingo.odata2.annotation.processor.core.util.AnnotationHelper.ODataAnnotationException;
 import org.apache.olingo.odata2.annotation.processor.core.util.AnnotationRuntimeException;
 import org.apache.olingo.odata2.annotation.processor.core.util.ClassHelper;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
 import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
 import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
 import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
@@ -156,7 +157,7 @@ public class AnnotationDataSource implements DataSource {
           + "', targetStore='" + targetStore + "').");
     }
 
-    List<Object> resultData = readResultData(targetStore, sourceData, sourceField);
+    List<Object> resultData = readResultData(targetStore, sourceData, sourceField, navInfo);
     return extractResultData(targetStore, targetKeys, navInfo, resultData);
   }
 
@@ -169,20 +170,24 @@ public class AnnotationDataSource implements DataSource {
    * @return
    * @throws DataStoreException
    */
-  private List<Object> readResultData(final DataStore<?> targetStore, final Object sourceData, final Field sourceField)
+  private List<Object> readResultData(final DataStore<?> targetStore, final Object sourceData, 
+          final Field sourceField, final AnnotatedNavInfo navInfo)
       throws DataStoreException {
     Object navigationInstance = getValue(sourceField, sourceData);
     if (navigationInstance == null) {
       return Collections.emptyList();
     }
-
+    
     List<Object> resultData = new ArrayList<Object>();
     for (Object targetInstance : targetStore.read()) {
       if (navigationInstance instanceof Collection) {
-        for (Object object : (Collection<?>) navigationInstance) {
-          if (targetStore.isKeyEqualChecked(targetInstance, object)) {
-            resultData.add(targetInstance);
-          }
+        Map<String, Object> keyName2Value = 
+                ANNOTATION_HELPER.getValueForAnnotatedFields(sourceData, EdmKey.class);
+        Field toField = navInfo.getToField();
+        Object backInstance = ClassHelper.getFieldValue(targetInstance, toField);
+        boolean keyMatch = ANNOTATION_HELPER.keyMatch(backInstance, keyName2Value);
+        if(keyMatch) {
+          resultData.add(targetInstance);
         }
       } else if (targetStore.isKeyEqualChecked(targetInstance, navigationInstance)) {
         resultData.add(targetInstance);