cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [2/7] cayenne git commit: CAY-2141 Skip repetitive query parameters
Date Sun, 27 Nov 2016 14:22:25 GMT
CAY-2141
Skip repetitive query parameters


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/6818800a
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/6818800a
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/6818800a

Branch: refs/heads/master
Commit: 6818800aa84fbd2857cc15ca9ccf032cbb177442
Parents: a117694
Author: Nikita Timofeev <ntimofeev@objectstyle.com>
Authored: Mon Nov 21 11:12:58 2016 +0300
Committer: Nikita Timofeev <ntimofeev@objectstyle.com>
Committed: Mon Nov 21 11:12:58 2016 +0300

----------------------------------------------------------------------
 .../access/HierarchicalObjectResolver.java      | 42 ++++++++++++--------
 1 file changed, 25 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/6818800a/cayenne-server/src/main/java/org/apache/cayenne/access/HierarchicalObjectResolver.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/main/java/org/apache/cayenne/access/HierarchicalObjectResolver.java
b/cayenne-server/src/main/java/org/apache/cayenne/access/HierarchicalObjectResolver.java
index 9d1e5f6..e220f9c 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/access/HierarchicalObjectResolver.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/access/HierarchicalObjectResolver.java
@@ -173,37 +173,23 @@ class HierarchicalObjectResolver {
                     .getParentDataDomain()
                     .getMaxIdQualifierSize();
 
-            List<PrefetchSelectQuery> queries = new ArrayList<PrefetchSelectQuery>();
+            List<PrefetchSelectQuery> queries = new ArrayList<>();
             int qualifiersCount = 0;
             PrefetchSelectQuery currentQuery = null;
             List<DbJoin> joins = lastDbRelationship.getJoins();
             Set<List<Object>> values = new HashSet<>();
 
             for (Object dataRow : parentDataRows) {
-                Expression allJoinsQualifier = null;
-
                 // handling too big qualifiers
                 if (currentQuery == null
                         || (maxIdQualifierSize > 0 && qualifiersCount + joins.size()
> maxIdQualifierSize)) {
 
-                    if(currentQuery != null) {
-                        for(List<Object> joinValues : values) {
-                            for(int i=0; i<joins.size(); i++) {
-                                Expression joinQualifier = ExpressionFactory.matchDbExp(pathPrefix
-                                        + joins.get(i).getTargetName(), joinValues.get(i));
-                                if (allJoinsQualifier == null) {
-                                    allJoinsQualifier = joinQualifier;
-                                } else {
-                                    allJoinsQualifier = allJoinsQualifier.andExp(joinQualifier);
-                                }
-                            }
-                            currentQuery.orQualifier(allJoinsQualifier);
-                        }
-                    }
+                    createDisjointByIdPrefetchQualifier(pathPrefix, currentQuery, joins,
values);
 
                     currentQuery = new PrefetchSelectQuery(node.getPath(), relationship);
                     queries.add(currentQuery);
                     qualifiersCount = 0;
+                    values = new HashSet<>();
                 }
 
                 List<Object> joinValues = new ArrayList<>();
@@ -216,6 +202,8 @@ class HierarchicalObjectResolver {
                     qualifiersCount += joins.size();
                 }
             }
+            // add final part of values
+            createDisjointByIdPrefetchQualifier(pathPrefix, currentQuery, joins, values);
 
             PrefetchTreeNode jointSubtree = node.cloneJointSubtree();
 
@@ -240,6 +228,26 @@ class HierarchicalObjectResolver {
             return startDisjointPrefetch(node);
         }
 
+        private void createDisjointByIdPrefetchQualifier(String pathPrefix, PrefetchSelectQuery
currentQuery,
+                                                         List<DbJoin> joins, Set<List<Object>>
values) {
+            Expression allJoinsQualifier;
+            if(currentQuery != null) {
+                for(List<Object> joinValues : values) {
+                    allJoinsQualifier = null;
+                    for(int i=0; i<joins.size(); i++) {
+                        Expression joinQualifier = ExpressionFactory.matchDbExp(pathPrefix
+                                + joins.get(i).getTargetName(), joinValues.get(i));
+                        if (allJoinsQualifier == null) {
+                            allJoinsQualifier = joinQualifier;
+                        } else {
+                            allJoinsQualifier = allJoinsQualifier.andExp(joinQualifier);
+                        }
+                    }
+                    currentQuery.orQualifier(allJoinsQualifier);
+                }
+            }
+        }
+
         public boolean startJointPrefetch(PrefetchTreeNode node) {
 
             // delegate processing of the top level joint prefetch to a joint processor,


Mime
View raw message