Skip Headers

# Executing the Finder From the Client

Previous

Next

TopLink offers the following additional elements for traversing finder results:

- `isEmpty` method: As with `java.util.Collection`, `isEmpty` method returns a `boolean` value indicating whether or not the `Collection` is empty.

- `size` method: As with `java.util.Collection`, `size` method returns an integer indicating the number of elements in the `Collection`.

- `iterator` method: As with `java.util.Collection`, `iterator` method returns a `java.util.Iterator` for enumerating the elements in the `Collection`.

TopLink also offers an extended protocol for `oracle.toplink.ejb.cmp.wls.CursoredIterator` (based on `java.util.Iterator`):

- `close` method: Closes the cursor on the server. The client must call this method to close the database connection.

- `hasNext` method: Returns a `boolean` value indicating whether or not any more elements are in the result set.

- `next` method: Returns the next available element.

- `next(int count)` method: Retrieves a `Vector` of at most count elements from the available results, depending on how many elements remain in the result set.

Example: Cursored Finder illustrates client code executing a cursored finder.

Cursored Finder

    // import both CursoredCollection and CursoredIterator
    import oracle.toplink.ejb.cmp.wls.*;
    //... other imports as necessary
    getTransaction().begin();
    CursoredIterator cursoredIterator = (CursoredIterator) getProjectHome().findByNameCursored("proj%").iterator();
    Vector projects = new Vector();
    for (int index = 0; index < 50; i++) {
    Project project = (Project)cursoredIterator.next();
    projects.addElement(project);
    }
    // Rest all at once ...
    Vector projects2 = cursoredIterator.next(50);
    cursoredIterator.close();
    getTransaction().commit();