Class ScrollableQueryResult<E>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, org.datanucleus.store.query.QueryResult<E>

    public final class ScrollableQueryResult<E>
    extends AbstractRDBMSQueryResult<E>
    implements java.io.Serializable
    Lazy collection results from a Query with the ResultSet scrollable. Supports the following query extensions (in addition to those supported by superclasses) :-
    • datanucleus.query.resultCacheType Type of caching of result objects. Supports strong, weak, soft, none
    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

      Fields 
      Modifier and Type Field Description
      (package private) int endIndex
      Position of last result (origin=0, set when known).
      protected java.util.Map<java.lang.Integer,​java.lang.Object> resultIdsByPosition
      Map of persistable object id, keyed by the result position (0, 1, 2, ...).
      private java.util.Map<java.lang.Integer,​E> resultsObjsByIndex
      Map of ResultSet object values, keyed by the list index ("0", "1", etc).
      (package private) int startIndex
      Position of first result (origin=0).
      • Fields inherited from class org.datanucleus.store.query.AbstractQueryResult

        api, closed, connectionListeners, loadResultsAtCommit, query, resultSizeMethod, size
      • Fields inherited from class java.util.AbstractList

        modCount
    • Constructor Summary

      Constructors 
      Constructor Description
      ScrollableQueryResult​(org.datanucleus.store.query.Query query, ResultObjectFactory<E> rof, java.sql.ResultSet rs, org.datanucleus.FetchPlan fp, java.util.Collection candidates)
      Constructor of the result from a Query.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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​(java.lang.Object o)  
      E get​(int index)
      Method to retrieve a particular element from the list.
      protected E getObjectForIndex​(int index)
      Accessor for the result object at an index.
      protected int getSizeUsingMethod()
      Method to get the size using the "resultSizeMethod".
      int hashCode()  
      void initialise()  
      java.util.Iterator<E> iterator()
      Accessor for an iterator for the results.
      java.util.ListIterator<E> 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.
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] a)  
      private <T> T[] toArrayInternal​(T[] a)  
      protected java.lang.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.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

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        addAll, remove, removeAll, replaceAll, retainAll, sort, spliterator
    • Field Detail

      • resultsObjsByIndex

        private java.util.Map<java.lang.Integer,​E> resultsObjsByIndex
        Map of ResultSet object values, keyed by the list index ("0", "1", etc).
      • resultIdsByPosition

        protected java.util.Map<java.lang.Integer,​java.lang.Object> resultIdsByPosition
        Map of persistable object id, keyed by the result position (0, 1, 2, ...).
      • startIndex

        int startIndex
        Position of first result (origin=0).
      • endIndex

        int endIndex
        Position of last result (origin=0, set when known).
    • Constructor Detail

      • ScrollableQueryResult

        public ScrollableQueryResult​(org.datanucleus.store.query.Query query,
                                     ResultObjectFactory<E> rof,
                                     java.sql.ResultSet rs,
                                     org.datanucleus.FetchPlan fp,
                                     java.util.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
        fp - FetchPlan
        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 E 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<E>
        Overrides:
        close in class AbstractRDBMSQueryResult<E>
      • 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<E>
      • cacheQueryResults

        protected void cacheQueryResults()
      • iterator

        public java.util.Iterator<E> iterator()
        Accessor for an iterator for the results.
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.List<E>
        Specified by:
        iterator in class org.datanucleus.store.query.AbstractQueryResult<E>
        Returns:
        The iterator
      • listIterator

        public java.util.ListIterator<E> listIterator()
        Accessor for an iterator for the results.
        Specified by:
        listIterator in interface java.util.List<E>
        Specified by:
        listIterator in class org.datanucleus.store.query.AbstractQueryResult<E>
        Returns:
        The iterator
      • equals

        public boolean equals​(java.lang.Object o)
        Specified by:
        equals in interface java.util.Collection<E>
        Specified by:
        equals in interface java.util.List<E>
        Overrides:
        equals in class AbstractRDBMSQueryResult<E>
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Collection<E>
        Specified by:
        hashCode in interface java.util.List<E>
        Overrides:
        hashCode in class AbstractRDBMSQueryResult<E>
      • get

        public E get​(int index)
        Method to retrieve a particular element from the list.
        Specified by:
        get in interface java.util.List<E>
        Specified by:
        get in class org.datanucleus.store.query.AbstractQueryResult<E>
        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<E>
        Returns:
        The size
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.List<E>
        Overrides:
        toArray in class org.datanucleus.store.query.AbstractQueryResult<E>
      • toArray

        public <T> T[] toArray​(T[] a)
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.List<E>
        Overrides:
        toArray in class org.datanucleus.store.query.AbstractQueryResult<E>
      • toArrayInternal

        private <T> T[] toArrayInternal​(T[] a)
      • writeReplace

        protected java.lang.Object writeReplace()
                                         throws java.io.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:
        java.io.ObjectStreamException - thrown if an error occurs