Class QueryResult<T extends ResultType>

Object
com.tailf.maapi.QueryResult<T>
All Implemented Interfaces:
Iterable<QueryResult.Entry<T>>

public class QueryResult<T extends ResultType> extends Object implements Iterable<QueryResult.Entry<T>>
Represent a result from a XPath query.

It is created trough successful invocation of Maapi.queryStart(int,String,String,int,int,List,Class) method. Its purpose is to iterate, stop or reset a XPath Query specified from parameters in queryStart.

The Iterator that returns from the iterator() method fetches result in chunks from server for local processing as needed and is specified by the chunksize in queryStart method when iterating over the result set.

Iterating trough the result multiple times could be done trough a call to reset() and retrieval of a new iterator() is required.

When iteration is done a call to stop() will free up resources from the server it is good practice to do so when done processing on this object.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Represent result entry in a XPath query.
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieves an iterator from which one could iterate over the result.
    void
    Reset/Rewind a running query so that it starts from the beginning again.
    void
    reset(int offset)
    Reset/Rewind a running query to a specific offset.
    long
    Get number of elements in the result.
    void
    Stops the running query and makes the server end free up any internal resources associated with the query.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Method Details

    • reset

      public void reset() throws ConfException, IOException
      Reset/Rewind a running query so that it starts from the beginning again. Next call to iterator() will then return the first chunk of results.

      The method can be called at any time (i.e. both after all results have been returned to essentially run the same query again, as well as after fetching just one or a couple of results).

      Throws:
      ConfException
      IOException
    • reset

      public void reset(int offset) throws ConfException, IOException
      Reset/Rewind a running query to a specific offset. First element has offset 1. Next call to iterator() will then reinitialize with first chunk starting with element at offset.

      The method can be called at any time.

      Throws:
      ConfException
      IOException
    • resultCount

      public long resultCount() throws ConfException, IOException
      Get number of elements in the result. Note, internally to get this information the expression must be evaluated and the result counted and afterwards the query reset. From a performance point of view this is the same as using the iterator and count the number of hits. Note also, that there is no guarantee that the elements addressed by the expression will not change between this call and the actual iteration, which then will lead to a difference in count.
      Returns:
      long number of elements in the result
      Throws:
      ConfException
      IOException
    • stop

      public void stop() throws ConfException, IOException

      Stops the running query and makes the server end free up any internal resources associated with the query.

      Throws:
      ConfException
      IOException
    • iterator

      public Iterator<QueryResult.Entry<T>> iterator()
      Retrieves an iterator from which one could iterate over the result.
      Specified by:
      iterator in interface Iterable<T extends ResultType>
      Returns:
      a query result iterator