Package org.intermine.objectstore.query
Class ResultsBatches
- java.lang.Object
-
- org.intermine.objectstore.query.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
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.Integer,java.util.List<java.lang.Object>>
batches
protected int
batchSize
static int
DEFAULT_BATCH_SIZE
This is the default batch size for Results objectsprotected ResultsInfo
info
protected boolean
initialised
protected int
maxSize
protected int
minSize
protected ObjectStore
os
protected Query
query
protected java.util.Map<java.lang.Object,java.lang.Integer>
sequence
-
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 rowint
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 resultsint
getMinSize()
Returns the current minimum number of rows in the resultsObjectStore
getObjectStore()
Returns the ObjectStore that this ResultsBatches object will useQuery
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 batchjava.util.Map<java.lang.Object,java.lang.Integer>
getSequence()
Returns the sequence that this ResultsBatches object was created withboolean
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 madeint
size(boolean optimise, boolean explain)
Gets the number of results rows in this Results object.
-
-
-
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
-
os
protected ObjectStore os
-
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
-
info
protected ResultsInfo info
-
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 foros
- an ObjectStoresequence
- 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 numberoptimise
- true if queries should be optimisedexplain
- 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 numberstart
- the row to start from (based on total rows)end
- the row to end at (based on total rows) - returned List includes this rowoptimise
- true if queries should be optimisedexplain
- true if this method should explain each query first- Returns:
- the rows in the range
- Throws:
ObjectStoreException
- if an error occurs in the underlying ObjectStorejava.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 optimisedexplain
- 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 ObjectStorejava.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 optimisedexplain
- 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 optimisedexplain
- 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 optimisedexplain
- true if this method should explain each query first- Returns:
- a boolean
-
getInfo
public ResultsInfo getInfo() throws ObjectStoreException
Gets the best current estimate of the characteristics of the query.- Returns:
- a ResultsInfo object
- Throws:
ObjectStoreException
- if an error occurs in the underlying ObjectStore
-
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
-
-