Here is some code of the sort Rick mentions. I hope this helps. I get lots of use out of this. This is my version of some code from some J2EE book on J2EE patterns.


-----------INTERFACE----------------- package com.michaelmcgrady.util.list;

import java.util.Collection;
import java.util.List;

import com.michaelmcgrady.exception.ChainedException;

public interface ListIterator {
  public void       setList(List list) throws ChainedException;
  public Collection getList();
  public int        getSize() throws ChainedException;
  public void       setIndex(int index) throws ChainedException;
  public int        getCurrentIndex() throws ChainedException;
  public Object     getCurrentElement() throws ChainedException;
  public List       getPreviousElements(int count) throws ChainedException;
  public List       getPreviousElements() throws ChainedException;
  public List       getNextElements(int count) throws ChainedException;
  public List       getNextElements() throws ChainedException;
  public void       resetIndex() throws ChainedException;
} /// ;-)


----------------IMPLEMENTATION ------------ package com.michaelmcgrady.util.list;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.michaelmcgrady.exception.ChainedException;

public class ListHandler
    implements com.michaelmcgrady.util.list.ListIterator {
  static Log log = LogFactory.getLog(ListHandler.class);

  private List         list;
  private ListIterator listIterator;

  public ListHandler() {
  }

public void setList(List list)
throws ChainedException {
this.list = list;
if(list != null) {
listIterator = list.listIterator();
} else {
throw new ChainedException("ListHandler: setList(List) failed: list empty");
}
}


  public Collection getList() {
    return list;
  }

  public int getSize()
      throws ChainedException{
    int size = 0;
    if (list != null) {
      size = list.size();
    } else {
      throw new ChainedException("ListHandler: getList() failed"); //No Data
    }
    return size;
  }

public void setIndex(int index)
throws ChainedException {
index -= getCurrentIndex();
int size = list.size();
if(index > size) {
throw new ChainedException("ListHandler: setCurrentIndex() failed -- the current index chosen was greater than size)");
}
getNextElements(index);
return;
}


  public int getCurrentIndex()
      throws ChainedException {
    // Will not advance iterator
    if (list != null) {
      return listIterator.nextIndex();
    } else {
      throw new ChainedException();
    }
  }

  public Object getCurrentElement()
      throws ChainedException {
    Object obj = null;
    // Will not advance iterator
    if (list != null) {
      int currIndex = listIterator.nextIndex();
      obj = list.get(currIndex);
    } else {
      throw new ChainedException();
    }
    return obj;
  }

public List getPreviousElements(int count)
throws ChainedException {
int i = 0;
Object object = null;
LinkedList list = new LinkedList();
if (listIterator != null) {
while(listIterator.hasPrevious() && (i < count)){
object = listIterator.previous();
list.add(object);
i++;
}
} else {
throw new ChainedException("ListHandler: getPreviousElements(int) failed -- listIterator null."); // No data
}
return list;
}


public List getPreviousElements()
throws ChainedException {
Object object = null;
LinkedList list = new LinkedList();
if(listIterator != null) {
while(listIterator.hasPrevious()) {
object = listIterator.previous();
list.add(object);
}
} else {
throw new ChainedException("ListHandler: getNextElements(int) failed -- listIterator null");
}
return list;
}


public List getNextElements(int count)
throws ChainedException {
int i = 0;
Object object = null;
LinkedList list = new LinkedList();
if(listIterator != null) {
while(listIterator.hasNext() && (i < count)) {
object = listIterator.next();
list.add(object);
i++;
}
} else {
throw new ChainedException("ListHandler: getNextElements(int) failed -- listIterator null.");
}
return list;
}


public List getNextElements()
throws ChainedException {
Object object = null;
LinkedList list = new LinkedList();
if(listIterator != null) {
while(listIterator.hasNext()) {
object = listIterator.next();
list.add(object);
}
} else {
throw new ChainedException("ListHandler: getNextElements(int) failed -- listIterator null");
}
return list;
}


  public List getNext()
      throws ChainedException {
    Object object = null;
    LinkedList list = new LinkedList();

if(listIterator != null) {
if(listIterator.hasNext()) {
object = listIterator.next();
list.add(object);
}
} else {
throw new ChainedException("ListHandler: getNextElements(int) failed -- listIterator null");
}


    return list;
  }

public void resetIndex()
throws ChainedException{
if(listIterator != null){
listIterator = list.listIterator();
} else {
throw new ChainedException("ListHandler: resetIndex() failed -- listIterator null.");
}
}
} ///;-)




At 07:46 AM 3/4/2004, you wrote:
Google for the Value List Handler pattern. It should also be on the java.sun.com
J2EE blueprints page.
I use a pager object which encapsulates a list of the sorted results. If the
result set size is over a certain threshhold, the pager instead wraps a value
list handler which only fetches subsets of the results. What you can do depends
on what functionality is available in OpenLDAP. I definitely wouldn't reload
with every request. If each result item is large, perhaps you could sort and
then store only a list of IDs in the session, and with each request make a query
to OpenLDAP to return user information for the set of IDs on the next page.
Hopefully you can batch this, otherwise you'll be making 20 LDAP calls per user
request and that would be a bad thing.


Rick DeBay

On Wed, 03 Mar 2004 19:57 , Arne Brutschy <[EMAIL PROTECTED]> sent:

>Hi,
>
>I'm looking for the best way to handle big search results.
>
>Setting: the user can search for other users in the ldap directory. This
>might return a long list of results (~40.000 entrys). Sadly, OpenLDAP
>doesn't support server-side sorting, so I have to sort the results
>myself. I want to display 20 items per page, and the user can browse
>through these results.
>
>What is the best way to handle these result object? Sorting once and
>storing/caching it in the session or searching and sorting every time
>the user requests a new page of results?
>
>Any thoughts/experiences?
>
>Regards,
>Arne Brutschy



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to