From 9b61ded11bf1ea63c174e7a2d63fd7e6e5fe1e60 Mon Sep 17 00:00:00 2001 From: "A. Abram White" Date: Mon, 26 Mar 2007 19:17:10 +0000 Subject: [PATCH] Simplify breaking up long IN clauses into multiple OR'd IN clauses based on the dictionary's IN clause limit git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@522600 13f79535-47bb-0310-9956-ffa450edef68 --- .../kernel/PagingResultObjectProvider.java | 16 +++++----------- .../jdbc/kernel/exps/InExpression.java | 19 +++++-------------- 2 files changed, 10 insertions(+), 25 deletions(-) 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(")"); } }