diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PagingResultObjectProvider.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PagingResultObjectProvider.java index d2243b05a..ba7db3450 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PagingResultObjectProvider.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/PagingResultObjectProvider.java @@ -392,22 +392,16 @@ public class PagingResultObjectProvider 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(")"); } } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java index c366654e1..f05393d39 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/InExpression.java @@ -123,25 +123,16 @@ class InExpression 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(")"); } }