Class ForwardQueryResult<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 ForwardQueryResult<E>
    extends AbstractRDBMSQueryResult<E>
    implements java.io.Serializable
    Lazy collection results from a Query with the ResultSet in a forward direction. In general the actual result elements are only loaded when accessed with the exception of non-transactional or optimistic contexts that load the elements at initialisation.

    If the query had a range defined and this was not handled in the datastore query then this QueryResult will skip the unrequired records and just return the range requested.

    See Also:
    Serialized Form
    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void advanceToEndOfResultSet()
      Internal method to advance to the end of the ResultSet, populating the resultObjs, and close the ResultSet when complete.
      void close()
      Method to close the results, making the results unusable thereafter.
      protected void closeResults()
      Internal method to close the ResultSet.
      protected void closingConnection()
      Method called to inform the query result that the connection is being closed so perform any required operations now, or rest in peace.
      boolean contains​(java.lang.Object o)
      Method to check if the specified object is contained in this result.
      boolean containsAll​(java.util.Collection c)
      Method to check if all of the specified objects are contained here.
      boolean equals​(java.lang.Object o)  
      E get​(int index)
      Method to retrieve a particular element from the list.
      protected int getSizeUsingMethod()
      Method to get the size using the "resultSizeMethod".
      int hashCode()  
      void initialise()  
      boolean isEmpty()
      Accessor for whether there are any results.
      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 E nextResultSetElement()
      Accessor for the next object from the ResultSet.
      private void processNumberOfResults​(int number)
      Method to advance through the results, processing the specified number of results.
      java.lang.Object[] toArray()
      Method to return the results as an array.
      <T> T[] toArray​(T[] a)
      Method to return the results as an array.
      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, indexOf, 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

      • moreResultSetRows

        protected boolean moreResultSetRows
        Whether there are still more rows to be processed in the ResultSet.
      • resultObjs

        protected java.util.List<E> resultObjs
        The Result Objects.
      • resultIds

        protected java.util.List<java.lang.Object> resultIds
      • candidates

        private java.util.Collection<java.lang.Object> candidates
        The candidate list restriction (optional).
    • Constructor Detail

      • ForwardQueryResult

        public ForwardQueryResult​(org.datanucleus.store.query.Query query,
                                  ResultObjectFactory<E> rof,
                                  java.sql.ResultSet rs,
                                  org.datanucleus.FetchPlan fp,
                                  java.util.Collection<java.lang.Object> 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 - Candidate elements
    • Method Detail

      • processNumberOfResults

        private void processNumberOfResults​(int number)
        Method to advance through the results, processing the specified number of results.
        Parameters:
        number - Number of results (-1 means process all)
      • advanceToEndOfResultSet

        private void advanceToEndOfResultSet()
        Internal method to advance to the end of the ResultSet, populating the resultObjs, and close the ResultSet when complete.
      • nextResultSetElement

        protected E nextResultSetElement()
        Accessor for the next object from the ResultSet.
        Returns:
        The next element from the ResultSet.
      • 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()
        Method called to inform the query result that the connection is being closed so perform any required operations now, or rest in peace.
        Specified by:
        closingConnection in class org.datanucleus.store.query.AbstractQueryResult<E>
      • 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
      • contains

        public boolean contains​(java.lang.Object o)
        Method to check if the specified object is contained in this result.
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.List<E>
        Overrides:
        contains in class org.datanucleus.store.query.AbstractQueryResult<E>
        Parameters:
        o - The object
        Returns:
        Whether it is contained here.
      • containsAll

        public boolean containsAll​(java.util.Collection c)
        Method to check if all of the specified objects are contained here.
        Specified by:
        containsAll in interface java.util.Collection<E>
        Specified by:
        containsAll in interface java.util.List<E>
        Overrides:
        containsAll in class org.datanucleus.store.query.AbstractQueryResult<E>
        Parameters:
        c - The collection of objects
        Returns:
        Whether they are all contained here.
      • 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
      • isEmpty

        public boolean isEmpty()
        Accessor for whether there are any results.
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Specified by:
        isEmpty in interface java.util.List<E>
        Overrides:
        isEmpty in class org.datanucleus.store.query.AbstractQueryResult<E>
        Returns:
        true if these results are empty.
      • 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()
        Method to return the results as an array.
        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>
        Returns:
        The array.
      • toArray

        public <T> T[] toArray​(T[] a)
        Method to return the results as an array.
        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>
        Parameters:
        a - The array to copy into.
        Returns:
        The array.
      • 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