openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r522600 - in /incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel: PagingResultObjectProvider.java exps/InExpression.java
Date Mon, 26 Mar 2007 19:17:10 GMT
Author: awhite
Date: Mon Mar 26 12:17:10 2007
New Revision: 522600

URL: http://svn.apache.org/viewvc?view=rev&rev=522600
Log:
Simplify breaking up long IN clauses into multiple OR'd IN clauses based on the
dictionary's IN clause limit


Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PagingResultObjectProvider.java
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PagingResultObjectProvider.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PagingResultObjectProvider.java?view=diff&rev=522600&r1=522599&r2=522600
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PagingResultObjectProvider.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PagingResultObjectProvider.java
Mon Mar 26 12:17:10 2007
@@ -392,22 +392,16 @@
     private void createInContains(Select sel, DBDictionary dict, SQLBuffer buf, 
         ClassMapping mapping, Column[] pks, int start, int end) {
         int inClauseLimit = dict.inClauseLimit;
-        if ((inClauseLimit == -1) || ((end - start) <= inClauseLimit))
+        if (inClauseLimit <= 0 || end - start <= inClauseLimit)
             inContains(sel, buf, mapping, pks, start, end);
         else {
             buf.append("(");
-
-            int low = start;
-            for (int i = 1, stop = (end - start)/inClauseLimit; i <= stop; i++) {
-                inContains(sel, buf, mapping, pks, low, low + inClauseLimit);
-                low += inClauseLimit;
-                if (low < end)
+            for (int low = start, high; low < end; low = high) {
+                if (low > start)
                     buf.append(" OR ");
+                high = Math.min(low + inClauseLimit, end);
+                inContains(sel, buf, mapping, pks, low, high);
             }
-            // Remaining
-            if (low < end)
-                inContains(sel, buf, mapping, pks, low, end);
-
             buf.append(")");
         }
     }

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java?view=diff&rev=522600&r1=522599&r2=522600
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java
Mon Mar 26 12:17:10 2007
@@ -123,25 +123,16 @@
         SQLBuffer buf, List list, Column[] cols) {
 
         int inClauseLimit = ctx.store.getDBDictionary().inClauseLimit;
-        if ((inClauseLimit == -1) || (list.size() < inClauseLimit))
+        if (inClauseLimit <= 0 || list.size() <= inClauseLimit)
             inContains(sel, ctx, state, buf, list, cols);
         else {
             buf.append("(");
-
-            int low = 0;
-            for (int i = 1, stop = list.size()/inClauseLimit; i <= stop; i++) {
-                List subList = list.subList(low, low + inClauseLimit);
-                inContains(sel, ctx, state, buf, subList, cols);
-                low += inClauseLimit;
-                if (low < list.size())
+            for (int low = 0, high; low < list.size(); low = high) {
+                if (low > 0)
                     buf.append(" OR ");
+                high = java.lang.Math.min(low + inClauseLimit, list.size());
+                inContains(sel, ctx, state, buf, list.subList(low, high), cols);
             }
-            // Remaining
-            if (low < list.size()) {
-                List rem = list.subList(low, list.size());
-                inContains(sel, ctx, state, buf, rem, cols);
-            }
-
             buf.append(")");
         }
     }



Mime
View raw message