int queryPos = 0;
q.setString(queryPos++, layoutId);
q.setString(queryPos++, userId);
com.liferay.portal.model.PortletPreferences[] array = new com.liferay.portal.model.PortletPreferences[3];
ScrollableResults sr = q.scroll();
if (sr.first()) {
while (true) {
PortletPreferencesHBM portletPreferencesHBM = (PortletPreferencesHBM)sr.get(0);
if (portletPreferencesHBM == null) {
break;
}
com.liferay.portal.model.PortletPreferences curPortletPreferences =
PortletPreferencesHBMUtil.model(portletPreferencesHBM);
int value = obc.compare(portletPreferences,
curPortletPreferences);
if (value == 0) {
if (!portletPreferences.equals(curPortletPreferences)) {
break;
}
array[1] = curPortletPreferences;
if (sr.previous()) {
array[0] = PortletPreferencesHBMUtil.model((PortletPreferencesHBM)sr.get(
0));
}
sr.next();
if (sr.next()) {
array[2] = PortletPreferencesHBMUtil.model((PortletPreferencesHBM)sr.get(
0));
}
break;
}
if (count == 1) {
break;
}
count = (int)Math.ceil(count / 2.0);
if (value < 0) {
if (!sr.scroll(count * -1)) {
break;
}
}
else {
if (!sr.scroll(count)) {
break;
}
}
}
}