adam bien's blog

p4j5: Source For The Paginator Java EE 5 Pattern Available 📎

I even checked in the source code sample for the Paginator pattern. Paginator is a new name for the Value List Handler Pattern from the ancient J2EE 1.4 days :-). The name Value List Handler is no more appropriate, because Paginator is also able to return persistent JPA-Entities (they do not have necessarily to be attached, or Value Object). Paginator is able to iterate over a set of entities, so it is very similar to the [GoF] Iterator-Pattern.

The usage is very straight-forward - it works like an iterator:

    CustomerQuery query = (CustomerQuery)PortableRemoteObject.narrow(remote,CustomerQuery.class);
 
      while(query.hasNext()){
            List<Customer> customers = query.next();
                System.out.println("Size: " + customers.size());
            for (Customer customer : customers) {
                System.out.println("Customer: " +customer);
            }
           
        }

The Paginator is realized as a stateful EJB 3 which works with JPA's Entity Manager. The whole source is available in p4j5.