com.centrasite.query
Class LazyQueryResult<ResultItem>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.AbstractSequentialList<ResultItem>
              extended by com.centrasite.query.LazyQueryResult<ResultItem>
Type Parameters:
ResultItem - the type of a result item
All Implemented Interfaces:
java.lang.Iterable<ResultItem>, java.util.Collection<ResultItem>, java.util.List<ResultItem>

public class LazyQueryResult<ResultItem>
extends java.util.AbstractSequentialList<ResultItem>

Fire an XQuery and lazily process the result. Allow separate queries to be used for getting the count and repositioning within the result. Cache the result in vector. Note this should go along with cursor processing - otherwise the full query result would be returned in a single server request.


Field Summary
protected  java.lang.String m_query
           
static java.lang.String rcs_id
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
LazyQueryResult(javax.xml.xquery.XQConnection xqConnection, LazyQueryResultParser<ResultItem> resultParser, java.lang.String query, java.lang.String countQuery, java.lang.String positionQueryPart1, java.lang.String positionQueryPart2)
          Construct a LazyQueryResult from a query.
LazyQueryResult(javax.xml.xquery.XQConnection xqConnection, LazyQueryResultParser<ResultItem> resultParser, java.lang.String query, java.lang.String countQuery, java.lang.String positionQueryPart1, java.lang.String positionQueryPart2, javax.xml.xquery.XQResultSequence resultSequence)
          Alternate constructor for use with a prepared query.
 
Method Summary
 void close()
          Close a LazyQueryResponse, releasing any resources.
protected  void finalize()
          See Object.finalize()
protected  int getRepositioningLimit()
          Return repositioning limit, i.e. the minimum distance (counted in number of result items) from the current position, that will cause a repositioning query to be issued.
 java.util.ListIterator<ResultItem> listIterator(int index)
          See List.listIterator(int)
 int size()
          Retrieve the size of the query result.
 
Methods inherited from class java.util.AbstractSequentialList
add, addAll, get, iterator, remove, set
 
Methods inherited from class java.util.AbstractList
add, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

rcs_id

public static final java.lang.String rcs_id
See Also:
Constant Field Values

m_query

protected java.lang.String m_query
Constructor Detail

LazyQueryResult

public LazyQueryResult(javax.xml.xquery.XQConnection xqConnection,
                       LazyQueryResultParser<ResultItem> resultParser,
                       java.lang.String query,
                       java.lang.String countQuery,
                       java.lang.String positionQueryPart1,
                       java.lang.String positionQueryPart2)
                throws javax.xml.xquery.XQException
Construct a LazyQueryResult from a query. Three versions of the query must be supplied: - the plain query - the count query - the positioning query A sample invocation might look like this: String query = "for $i in 1 to 1000005 return {$i}"; String countQuery = "xs:integer(count(for $i in 1 to 1000005 return $i))"; String positionQueryPart1 = "for $i in (for $i in 1 to 1000005 return $i)"; String positionQueryPart2 = "return {$i}"; LazyQueryResult lqr = new LazyQueryResult(xqConnection, resultParser, query, countQuery, positionQueryPart1, positionQueryPart2 );

Parameters:
xqConnection - an XQJ connection (cursoring should be enabled!)
resultParser - the result item parser
query - the plain query
countQuery - the count query
positionQueryPart1 - the first part of the position query
positionQueryPart2 - the second part of the position query
Throws:
javax.xml.xquery.XQException

LazyQueryResult

public LazyQueryResult(javax.xml.xquery.XQConnection xqConnection,
                       LazyQueryResultParser<ResultItem> resultParser,
                       java.lang.String query,
                       java.lang.String countQuery,
                       java.lang.String positionQueryPart1,
                       java.lang.String positionQueryPart2,
                       javax.xml.xquery.XQResultSequence resultSequence)
                throws javax.xml.xquery.XQException
Alternate constructor for use with a prepared query. Preparation, variable binding, and result sequence construction must be done outside. Note that the result sequence is used for the initial chunk, as long as the result is read sequentially. For repositioning, the extra queries are used in the same way as without the prepared query. Also an early call for getting the result size will fire the count-query in ad-hoc fashion.

Parameters:
xqConnection - an XQJ connection (cursoring should be enabled!)
resultParser - the result item parser
query - the plain query
countQuery - the count query
positionQueryPart1 - the first part of the position query
positionQueryPart2 - the second part of the position query
resultSequence - a result sequence to be used for the initial chunk
Throws:
javax.xml.xquery.XQException
Method Detail

close

public void close()
Close a LazyQueryResponse, releasing any resources.


size

public int size()
Retrieve the size of the query result.

Specified by:
size in interface java.util.Collection<ResultItem>
Specified by:
size in interface java.util.List<ResultItem>
Specified by:
size in class java.util.AbstractCollection<ResultItem>

listIterator

public java.util.ListIterator<ResultItem> listIterator(int index)
See List.listIterator(int)

Specified by:
listIterator in interface java.util.List<ResultItem>
Specified by:
listIterator in class java.util.AbstractSequentialList<ResultItem>

getRepositioningLimit

protected int getRepositioningLimit()
Return repositioning limit, i.e. the minimum distance (counted in number of result items) from the current position, that will cause a repositioning query to be issued. Any forward positioning to a distance less than this number will be approached sequentially.

Returns:
respositioning limit

finalize

protected void finalize()
                 throws java.lang.Throwable
See Object.finalize()

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable