This is an automated email from the ASF dual-hosted git repository.

mibo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata2.git


The following commit(s) were added to refs/heads/master by this push:
     new 6257c230 [OLINGO-1189] Sorting entities from metamodel before building 
OData Entity Model
6257c230 is described below

commit 6257c23050f7f9d093b1439227442fe9a76b4639
Author: Kiran <[email protected]>
AuthorDate: Tue Oct 10 12:48:19 2017 +0530

    [OLINGO-1189] Sorting entities from metamodel before building OData Entity 
Model
---
 .../jpa/processor/core/model/JPAEdmEntityType.java | 29 +++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
index fd18166b..0e98cd6a 100644
--- 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
+++ 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
@@ -18,6 +18,7 @@
  
******************************************************************************/
 package org.apache.olingo.odata2.jpa.processor.core.model;
 
+import java.util.Collection;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -91,7 +92,7 @@ public class JPAEdmEntityType extends JPAEdmBaseViewImpl 
implements JPAEdmEntity
     @Override
     public void build() throws ODataJPAModelException, 
ODataJPARuntimeException {
 
-      Set<javax.persistence.metamodel.EntityType<?>> jpaEntityTypes = 
metaModel.getEntities();
+      Collection<javax.persistence.metamodel.EntityType<?>> jpaEntityTypes = 
metaModel.getEntities();
 
       if (jpaEntityTypes == null || jpaEntityTypes.isEmpty() == true) {
         return;
@@ -100,6 +101,7 @@ public class JPAEdmEntityType extends JPAEdmBaseViewImpl 
implements JPAEdmEntity
 
       }
 
+      jpaEntityTypes = sortJPAEntityTypes(jpaEntityTypes);
       for (javax.persistence.metamodel.EntityType<?> jpaEntityType : 
jpaEntityTypes) {
         currentEdmEntityType = new EntityType();
         currentJPAEntityType = jpaEntityType;
@@ -142,6 +144,31 @@ public class JPAEdmEntityType extends JPAEdmBaseViewImpl 
implements JPAEdmEntity
 
     }
 
+    private List<javax.persistence.metamodel.EntityType<?>> sortJPAEntityTypes(
+      final Collection<javax.persistence.metamodel.EntityType<?>> entities) {
+
+      List<javax.persistence.metamodel.EntityType<?>> entityTypeList =
+        new 
ArrayList<javax.persistence.metamodel.EntityType<?>>(entities.size());
+
+        Iterator<javax.persistence.metamodel.EntityType<?>> itr;
+        javax.persistence.metamodel.EntityType<?> smallestJpaEntity;
+        javax.persistence.metamodel.EntityType<?> currentJpaEntity;
+        while (!entities.isEmpty()) {
+          itr = entities.iterator();
+          smallestJpaEntity = itr.next();
+          while (itr.hasNext()) {
+            currentJpaEntity = itr.next();
+            if 
(smallestJpaEntity.getName().compareTo(currentJpaEntity.getName()) > 0) {
+              smallestJpaEntity = currentJpaEntity;
+            }
+          }
+          entityTypeList.add(smallestJpaEntity);
+          entities.remove(smallestJpaEntity);
+        }
+
+      return entityTypeList;
+    }
+
     private boolean isExcluded(final JPAEdmEntityType jpaEdmEntityType) {
       JPAEdmMappingModelAccess mappingModelAccess = 
jpaEdmEntityType.getJPAEdmMappingModelAccess();
       if (mappingModelAccess != null && 
mappingModelAccess.isMappingModelExists()

Reply via email to