org.datanucleus.store.rdbms.query
Class ScrollableQueryResult

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList
          extended by org.datanucleus.store.query.AbstractQueryResult
              extended by org.datanucleus.store.rdbms.query.AbstractRDBMSQueryResult
                  extended by org.datanucleus.store.rdbms.query.ScrollableQueryResult
All Implemented Interfaces:
Serializable, Iterable, Collection, List, org.datanucleus.store.query.QueryResult

public final class ScrollableQueryResult
extends AbstractRDBMSQueryResult
implements Serializable

Lazy collection results from a Query with the ResultSet scrollable. Supports the following query extensions (in addition to those supported by superclasses) :-

If there is no transaction present, or if the FetchPlan is in "greedy" mode, and where caching is being used will load all results at startup. Otherwise results are only loaded when accessed.

See Also:
Serialized Form

Field Summary
protected  Map<Integer,Object> resultIds
           
 
Fields inherited from class org.datanucleus.store.rdbms.query.AbstractRDBMSQueryResult
rof, rs
 
Fields inherited from class org.datanucleus.store.query.AbstractQueryResult
closed, connectionListeners, loadResultsAtCommit, LOCALISER, query, resultSizeMethod, size
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ScrollableQueryResult(org.datanucleus.store.query.Query query, org.datanucleus.store.query.ResultObjectFactory rof, ResultSet rs, Collection candidates)
          Constructor of the result from a Query.
 
Method Summary
protected  void cacheQueryResults()
           
 void close()
          Method to close the results, making the results unusable thereafter.
protected  void closingConnection()
          Inform the query result that the connection is being closed so perform any operations now, or rest in peace.
 boolean equals(Object o)
          Equality operator for QueryResults.
 Object get(int index)
          Method to retrieve a particular element from the list.
protected  Object getObjectForIndex(int index)
          Accessor for the result object at an index.
protected  int getSizeUsingMethod()
          Method to get the size using the "resultSizeMethod".
 Iterator iterator()
          Accessor for an iterator for the results.
 ListIterator listIterator()
          Accessor for an iterator for the results.
protected  void loadObjects(int start, int maxNumber)
          Convenience method to load up rows starting at the specified position.
 Object[] toArray()
           
 Object[] toArray(Object[] a)
           
protected  Object writeReplace()
          Handle serialisation by returning a java.util.ArrayList of all of the results for this query after disconnecting the query which has the consequence of enforcing the load of all objects.
 
Methods inherited from class org.datanucleus.store.rdbms.query.AbstractRDBMSQueryResult
closeResults, disconnect, hashCode
 
Methods inherited from class org.datanucleus.store.query.AbstractQueryResult
add, add, addAll, addConnectionListener, assertIsOpen, clear, contains, containsAll, indexOf, isEmpty, isOpen, lastIndexOf, remove, set, size, subList
 
Methods inherited from class java.util.AbstractList
listIterator, removeRange
 
Methods inherited from class java.util.AbstractCollection
addAll, remove, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
addAll, remove, removeAll, retainAll
 
Methods inherited from interface java.util.List
addAll, remove, removeAll, retainAll
 

Field Detail

resultIds

protected Map<Integer,Object> resultIds
Constructor Detail

ScrollableQueryResult

public ScrollableQueryResult(org.datanucleus.store.query.Query query,
                             org.datanucleus.store.query.ResultObjectFactory rof,
                             ResultSet rs,
                             Collection candidates)
Constructor of the result from a Query.

Parameters:
query - The Query
rof - The factory to retrieve results from
rs - The ResultSet from the Query Statement
candidates - the Candidates collection. Pass this argument only when distinct = false
Method Detail

loadObjects

protected void loadObjects(int start,
                           int maxNumber)
Convenience method to load up rows starting at the specified position. Optionally takes a maximum number of rows to process.

Parameters:
start - Start row
maxNumber - Max number to process (-1 means no maximum)

getObjectForIndex

protected Object getObjectForIndex(int index)
Accessor for the result object at an index. If the object has already been processed will return that object, otherwise will retrieve the object using the factory.

Parameters:
index - The list index position
Returns:
The result object

close

public void close()
Method to close the results, making the results unusable thereafter.

Specified by:
close in interface org.datanucleus.store.query.QueryResult
Overrides:
close in class AbstractRDBMSQueryResult

closingConnection

protected void closingConnection()
Inform the query result that the connection is being closed so perform any operations now, or rest in peace.

Specified by:
closingConnection in class org.datanucleus.store.query.AbstractQueryResult

cacheQueryResults

protected void cacheQueryResults()

iterator

public Iterator iterator()
Accessor for an iterator for the results.

Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in interface List
Specified by:
iterator in class org.datanucleus.store.query.AbstractQueryResult
Returns:
The iterator

listIterator

public ListIterator listIterator()
Accessor for an iterator for the results.

Specified by:
listIterator in interface List
Specified by:
listIterator in class org.datanucleus.store.query.AbstractQueryResult
Returns:
The iterator

equals

public boolean equals(Object o)
Equality operator for QueryResults. Overrides the AbstractList implementation since that uses size() and iterator() and that would cause problems when closed.

Specified by:
equals in interface Collection
Specified by:
equals in interface List
Specified by:
equals in class org.datanucleus.store.query.AbstractQueryResult
Parameters:
o - The object to compare against
Returns:
Whether they are equal

get

public Object get(int index)
Method to retrieve a particular element from the list.

Specified by:
get in interface List
Specified by:
get in class org.datanucleus.store.query.AbstractQueryResult
Parameters:
index - The index of the element
Returns:
The element at index

getSizeUsingMethod

protected int getSizeUsingMethod()
Method to get the size using the "resultSizeMethod". This implementation supports "LAST" method. Override this in subclasses to implement other methods.

Overrides:
getSizeUsingMethod in class org.datanucleus.store.query.AbstractQueryResult
Returns:
The size

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List
Overrides:
toArray in class org.datanucleus.store.query.AbstractQueryResult

toArray

public Object[] toArray(Object[] a)
Specified by:
toArray in interface Collection
Specified by:
toArray in interface List
Overrides:
toArray in class org.datanucleus.store.query.AbstractQueryResult

writeReplace

protected Object writeReplace()
                       throws ObjectStreamException
Handle serialisation by returning a java.util.ArrayList of all of the results for this query after disconnecting the query which has the consequence of enforcing the load of all objects.

Returns:
The object to serialise
Throws:
ObjectStreamException


Copyright © 2012. All Rights Reserved.