Class ResultsBatches


  • public class ResultsBatches
    extends java.lang.Object
    Class holding the data batches for the Results object. Possibly multiple Results objects with different settings (for prefetch, explain, optimise) will use the same ResultsBatches object.
    Author:
    Matthew Wakeling
    • Constructor Summary

      Constructors 
      Constructor Description
      ResultsBatches​(Query query, ObjectStore os, java.util.Map<java.lang.Object,​java.lang.Integer> sequence)
      Construct a new ResultsBatches object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.List<java.lang.Object> fetchBatchFromObjectStore​(int batchNo, boolean optimise, boolean explain)
      Gets a batch from the ObjectStore.
      protected java.util.List<java.lang.Object> getBatch​(int batchNo, boolean optimise, boolean explain)
      Gets a batch by whatever means - maybe batches, maybe the ObjectStore.
      java.util.List<java.lang.Object> getBatchFromCache​(int batchNo)
      Returns the given batch, if it is already in the batch cache.
      protected int getBatchNoForRow​(int row)
      Gets the batch for a particular row
      int getBatchSize()
      Gets the batch size being used.
      ResultsInfo getInfo()
      Gets the best current estimate of the characteristics of the query.
      int getMaxSize()
      Returns the current maximum number of rows in the results
      int getMinSize()
      Returns the current minimum number of rows in the results
      ObjectStore getObjectStore()
      Returns the ObjectStore that this ResultsBatches object will use
      Query getQuery()
      Get the Query that produced this ResultsBatches object.
      protected java.util.List<java.lang.Object> getRowsFromBatch​(int batchNo, int start, int end, boolean optimise, boolean explain)
      Gets a range of rows from within a batch
      java.util.Map<java.lang.Object,​java.lang.Integer> getSequence()
      Returns the sequence that this ResultsBatches object was created with
      boolean isEmpty​(boolean optimise, boolean explain)
      Returns true is there are no rows in the results.
      boolean isSingleBatch()
      Returns true if the results are known to fit entirely within the first batch.
      ResultsBatches makeWithDifferentBatchSize​(int newBatchSize)
      Returns a new ResultsBatches object with a different batch size with some of the data already filled in.
      void prefetch​(int batchNo, boolean optimise, boolean explain)
      Prefetch into memory the batch indicated with the given batch number.
      void setBatchSize​(int size)
      Sets the number of rows requested from the ObjectStore whenever an execute call is made
      int size​(boolean optimise, boolean explain)
      Gets the number of results rows in this Results object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_BATCH_SIZE

        public static final int DEFAULT_BATCH_SIZE
        This is the default batch size for Results objects
        See Also:
        Constant Field Values
      • query

        protected Query query
      • sequence

        protected java.util.Map<java.lang.Object,​java.lang.Integer> sequence
      • minSize

        protected int minSize
      • maxSize

        protected int maxSize
      • batchSize

        protected int batchSize
      • initialised

        protected boolean initialised
      • batches

        protected java.util.Map<java.lang.Integer,​java.util.List<java.lang.Object>> batches
    • Constructor Detail

      • ResultsBatches

        public ResultsBatches​(Query query,
                              ObjectStore os,
                              java.util.Map<java.lang.Object,​java.lang.Integer> sequence)
        Construct a new ResultsBatches object. This is generally only called by the Results object.
        Parameters:
        query - a Query object to retrieve data for
        os - an ObjectStore
        sequence - the ObjectStore-specific sequence data
    • Method Detail

      • getQuery

        public Query getQuery()
        Get the Query that produced this ResultsBatches object. Note that due to the ObjectStore's Results cache, this may not be the exact same Query as you passed to ObjectStore.execute. The query will have the same meaning, but may not be .equals() to your original query.
        Returns:
        the Query that produced this ResultsBatches object
      • getSequence

        public java.util.Map<java.lang.Object,​java.lang.Integer> getSequence()
        Returns the sequence that this ResultsBatches object was created with
        Returns:
        the ObjectStore-specific object
      • getObjectStore

        public ObjectStore getObjectStore()
        Returns the ObjectStore that this ResultsBatches object will use
        Returns:
        an ObjectStore
      • getMaxSize

        public int getMaxSize()
        Returns the current maximum number of rows in the results
        Returns:
        an int
      • getMinSize

        public int getMinSize()
        Returns the current minimum number of rows in the results
        Returns:
        an int
      • prefetch

        public void prefetch​(int batchNo,
                             boolean optimise,
                             boolean explain)
        Prefetch into memory the batch indicated with the given batch number. If it is already there, do nothing.
        Parameters:
        batchNo - the batch number
        optimise - true if queries should be optimised
        explain - true if this method should explain each query first
      • getRowsFromBatch

        protected java.util.List<java.lang.Object> getRowsFromBatch​(int batchNo,
                                                                    int start,
                                                                    int end,
                                                                    boolean optimise,
                                                                    boolean explain)
                                                             throws ObjectStoreException
        Gets a range of rows from within a batch
        Parameters:
        batchNo - the batch number
        start - the row to start from (based on total rows)
        end - the row to end at (based on total rows) - returned List includes this row
        optimise - true if queries should be optimised
        explain - true if this method should explain each query first
        Returns:
        the rows in the range
        Throws:
        ObjectStoreException - if an error occurs in the underlying ObjectStore
        java.lang.IndexOutOfBoundsException - if the batch is off the end of the results
      • getBatch

        protected java.util.List<java.lang.Object> getBatch​(int batchNo,
                                                            boolean optimise,
                                                            boolean explain)
                                                     throws ObjectStoreException
        Gets a batch by whatever means - maybe batches, maybe the ObjectStore.
        Parameters:
        batchNo - the batch number to get (zero-indexed)
        optimise - true if queries should be optimised
        explain - true if this method should explain each query first
        Returns:
        a List which is the batch
        Throws:
        ObjectStoreException - if an error occurs in the underlying ObjectStore
        java.lang.IndexOutOfBoundsException - if the batch is off the end of the results
      • fetchBatchFromObjectStore

        protected java.util.List<java.lang.Object> fetchBatchFromObjectStore​(int batchNo,
                                                                             boolean optimise,
                                                                             boolean explain)
                                                                      throws ObjectStoreException
        Gets a batch from the ObjectStore.
        Parameters:
        batchNo - the batch number to get (zero-indexed)
        optimise - true if queries should be optimised
        explain - true if this method should explain each query first
        Returns:
        a List which is the batch
        Throws:
        ObjectStoreException - if an error occurs in the underlying ObjectStore
      • size

        public int size​(boolean optimise,
                        boolean explain)
        Gets the number of results rows in this Results object.
        Parameters:
        optimise - true if queries should be optimised
        explain - true if this method should explain each query first
        Returns:
        the number of rows in this Results object
      • isEmpty

        public boolean isEmpty​(boolean optimise,
                               boolean explain)
        Returns true is there are no rows in the results.
        Parameters:
        optimise - true if queries should be optimised
        explain - true if this method should explain each query first
        Returns:
        a boolean
      • setBatchSize

        public void setBatchSize​(int size)
        Sets the number of rows requested from the ObjectStore whenever an execute call is made
        Parameters:
        size - the number of rows
      • getBatchSize

        public int getBatchSize()
        Gets the batch size being used.
        Returns:
        an int
      • getBatchNoForRow

        protected int getBatchNoForRow​(int row)
        Gets the batch for a particular row
        Parameters:
        row - the row to get the batch for
        Returns:
        the batch number
      • isSingleBatch

        public boolean isSingleBatch()
        Returns true if the results are known to fit entirely within the first batch.
        Returns:
        a boolean
      • makeWithDifferentBatchSize

        public ResultsBatches makeWithDifferentBatchSize​(int newBatchSize)
        Returns a new ResultsBatches object with a different batch size with some of the data already filled in.
        Parameters:
        newBatchSize - the batch size of the new ResultsBatch object
        Returns:
        a new ResultsBatches object
      • getBatchFromCache

        public java.util.List<java.lang.Object> getBatchFromCache​(int batchNo)
        Returns the given batch, if it is already in the batch cache.
        Parameters:
        batchNo - the batch number to return
        Returns:
        a batch of rows