Skip to content

Commit

Permalink
LEP-4628
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.liferay.com/repos/public/portal/trunk@12372 05bdf26c-840f-0410-9ced-eb539d925f36
  • Loading branch information
brianchandotcom committed Dec 30, 2007
1 parent 16bc656 commit 0cd902c
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions util-java/src/com/liferay/util/dao/hibernate/QueryUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public static List randomList(
public static Comparable[] getPrevAndNext(
Query query, int count, OrderByComparator obc, Comparable comparable) {

int pos = count;
int boundary = 0;

Comparable[] array = new Comparable[3];

ScrollableResults sr = query.scroll();
Expand Down Expand Up @@ -162,20 +165,30 @@ public static Comparable[] getPrevAndNext(
break;
}

if (count == 1) {
if (_log.isDebugEnabled()) {
_log.debug("Scroll count is 1");
}

if (pos == 1) {
break;
}

count = (int)Math.ceil(count / 2.0);
pos = (int)Math.ceil(pos / 2.0);

int scrollPos = count;
int scrollPos = pos;

if (value < 0) {
scrollPos = scrollPos * -1;
scrollPos = scrollPos * -1;
}

boundary += scrollPos;

if (boundary < 0) {
scrollPos = scrollPos + (boundary * -1) + 1;

boundary = 0;
}

if (boundary > count) {
scrollPos = scrollPos - (boundary - count);

boundary = scrollPos;
}

if (_log.isDebugEnabled()) {
Expand All @@ -184,12 +197,12 @@ public static Comparable[] getPrevAndNext(

if (!sr.scroll(scrollPos)) {
if (value < 0) {
if (!sr.scroll(1)) {
if (!sr.next()) {
break;
}
}
else {
if (!sr.scroll(-1)) {
if (!sr.previous()) {
break;
}
}
Expand Down

0 comments on commit 0cd902c

Please sign in to comment.