Ejemplo n.º 1
0
  /*
   * Result cursors are bidirectional.  You can use hasNext, next,
   * hasPrevious, previous, isFirst, first, isLast, last, isBeforeFirst,
   * beforeFirst, isAfterLast, afterLast.  You can also use Iterator and
   * ListIterator.
   */
  static void movingBackAndForth(Database db) throws DatabaseException {
    Result<Order> result = db.queryObject(Order.class);

    while (result.hasNext()) System.out.println(result.next());

    while (result.hasPrevious()) System.out.println(result.previous());

    result.last();

    System.out.println();

    System.out.println(result.current());

    while (result.hasPrevious()) System.out.println(result.previous());

    System.out.println();

    result = db.queryObject(Order.class);

    ListIterator it;

    for (it = result.listIterator(); it.hasNext(); ) System.out.println(it.next());

    for (; it.hasPrevious(); ) System.out.println(it.previous());
  }
Ejemplo n.º 2
0
  /*
   * Result is a ListIterator and Iterable.
   */
  static void iteratingResults(Database db) throws DatabaseException {
    Result<Customer> result = db.queryObject(Customer.class, "where customer_id = ?", "ssmith");

    for (Customer c : result) System.out.println(c);

    result = db.queryObject(Customer.class);

    while (result.hasNext()) System.out.println(result.next());

    result = db.queryObject(Customer.class);

    for (Iterator it = result.iterator(); it.hasNext(); ) System.out.println(it.next());
  }