org.intermine.objectstore.query
Class Results

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<java.lang.Object>
          extended by org.intermine.objectstore.query.Results
All Implemented Interfaces:
java.lang.Iterable<java.lang.Object>, java.util.Collection<java.lang.Object>, java.util.List<java.lang.Object>, java.util.Set<java.lang.Object>, Lazy, LazyCollection<java.lang.Object>
Direct Known Subclasses:
SingletonResults

public class Results
extends java.util.AbstractList<java.lang.Object>
implements LazyCollection<java.lang.Object>

Results representation as a List of ResultRows. Extending AbstractList requires implementation of get(int) and size(). In addition subList(int, int) overrides AbstractList implementation for efficiency. Also iterator() and isEmpty() to avoid evaluating the entire collection.


Field Summary
protected  boolean explain
           
protected  boolean immutable
           
protected  int lastGet
           
protected  boolean optimise
           
protected  boolean prefetch
           
protected  ResultsBatches resultsBatches
           
protected  int sequential
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
protected Results()
          No argument constructor for testing purposes
  Results(Query query, ObjectStore os, java.util.Map<java.lang.Object,java.lang.Integer> sequence)
          Constructor for a Results object.
  Results(ResultsBatches batches, boolean optimise, boolean explain, boolean prefetch)
          Constructor for a Results object, given a ResultsBatches object.
 
Method Summary
 java.util.List<java.lang.Object> asList()
          Return this Collection as a List.
 java.lang.Object get(int index)
          
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.
 ObjectStore getObjectStore()
          Returns the ObjectStore that this Results object will use
 Query getQuery()
          Get the Query that produced this Results object.
 ResultsBatches getResultsBatches()
          Returns the underlying ResultsBatches object that this object is using, in order to create more Results objects (with different settings) from it.
 java.util.Map<java.lang.Object,java.lang.Integer> getSequence()
          Returns the sequence that this Results object was created with
 boolean isEmpty()
          
 boolean isSingleBatch()
          Returns true if the results are known to fit entirely within the first batch.
 java.util.Iterator<java.lang.Object> iterator()
          
 java.util.Iterator<java.lang.Object> iteratorFrom(int from)
          Returns an iterator over the List, starting from the given position.
 java.util.List<java.lang.Object> range(int start, int end)
          Returns a range of rows of results.
 void setBatchSize(int size)
          Sets the number of rows requested from the ObjectStore whenever an execute call is made
 void setImmutable()
          Tells this Results object that it is being put into a cache, so it needs to be made immutable to prevent threads stomping on each other and changing settings.
 void setNoExplain()
          Sets this Results object to bypass the explain check in ObjectStore.execute().
 void setNoOptimise()
          Sets this Results object to bypass the optimiser.
 void setNoPrefetch()
          Tells this Results object to never do any background prefetching.
 int size()
          Gets the number of results rows in this Results object
 java.util.List<java.lang.Object> subList(int start, int end)
          
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from interface java.util.List
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
 

Field Detail

resultsBatches

protected ResultsBatches resultsBatches

optimise

protected boolean optimise

explain

protected boolean explain

prefetch

protected boolean prefetch

immutable

protected boolean immutable

lastGet

protected int lastGet

sequential

protected int sequential
Constructor Detail

Results

protected Results()
No argument constructor for testing purposes


Results

public Results(Query query,
               ObjectStore os,
               java.util.Map<java.lang.Object,java.lang.Integer> sequence)
Constructor for a Results object.

Parameters:
query - the Query that produces this Results
os - the ObjectStore that can be used to get results rows from
sequence - a number representing the state of the ObjectStore, which should be quoted back to the ObjectStore when requests are made

Results

public Results(ResultsBatches batches,
               boolean optimise,
               boolean explain,
               boolean prefetch)
Constructor for a Results object, given a ResultsBatches object.

Parameters:
batches - a ResultsBatches object that will back this new object
optimise - true if queries should be optimised
explain - true if queries should be explained
prefetch - true to switch on the PrefetchManager
Method Detail

setNoOptimise

public void setNoOptimise()
Sets this Results object to bypass the optimiser.

Specified by:
setNoOptimise in interface LazyCollection<java.lang.Object>

setNoExplain

public void setNoExplain()
Sets this Results object to bypass the explain check in ObjectStore.execute().

Specified by:
setNoExplain in interface LazyCollection<java.lang.Object>

setNoPrefetch

public void setNoPrefetch()
Tells this Results object to never do any background prefetching. This means that Query cancellation via the ObjectStoreInterMineImpl.cancelRequest() will never leave the database busy with cancelled work.


setImmutable

public void setImmutable()
Tells this Results object that it is being put into a cache, so it needs to be made immutable to prevent threads stomping on each other and changing settings.


getQuery

public Query getQuery()
Get the Query that produced this Results 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.

Specified by:
getQuery in interface LazyCollection<java.lang.Object>
Returns:
the Query that produced this Results object

getSequence

public java.util.Map<java.lang.Object,java.lang.Integer> getSequence()
Returns the sequence that this Results object was created with

Returns:
the ObjectStore-specific object

getObjectStore

public ObjectStore getObjectStore()
Returns the ObjectStore that this Results object will use

Specified by:
getObjectStore in interface Lazy
Returns:
an ObjectStore

range

public java.util.List<java.lang.Object> range(int start,
                                              int end)
                                       throws ObjectStoreException
Returns a range of rows of results. Will fetch batches from the underlying ObjectStore if necessary.

Parameters:
start - the start index (inclusive)
end - the end index (inclusive)
Returns:
the relevant ResultRows as a List
Throws:
ObjectStoreException - if an error occurs in the underlying ObjectStore
java.lang.IndexOutOfBoundsException - if end is beyond the number of rows in the results
java.lang.IllegalArgumentException - if start > end

get

public java.lang.Object get(int index)

Specified by:
get in interface java.util.List<java.lang.Object>
Specified by:
get in class java.util.AbstractList<java.lang.Object>
Parameters:
index - of the ResultsRow required
Returns:
the relevant ResultsRow as an Object

subList

public java.util.List<java.lang.Object> subList(int start,
                                                int end)

Specified by:
subList in interface java.util.List<java.lang.Object>
Overrides:
subList in class java.util.AbstractList<java.lang.Object>
Parameters:
start - the index to start from (inclusive)
end - the index to end at (exclusive)
Returns:
the sub-list

size

public int size()
Gets the number of results rows in this Results object

Specified by:
size in interface java.util.Collection<java.lang.Object>
Specified by:
size in interface java.util.List<java.lang.Object>
Specified by:
size in interface java.util.Set<java.lang.Object>
Specified by:
size in class java.util.AbstractCollection<java.lang.Object>
Returns:
the number of rows in this Results object

isEmpty

public boolean isEmpty()

Specified by:
isEmpty in interface java.util.Collection<java.lang.Object>
Specified by:
isEmpty in interface java.util.List<java.lang.Object>
Specified by:
isEmpty in interface java.util.Set<java.lang.Object>
Overrides:
isEmpty in class java.util.AbstractCollection<java.lang.Object>

getInfo

public ResultsInfo getInfo()
                    throws ObjectStoreException
Gets the best current estimate of the characteristics of the query.

Specified by:
getInfo in interface LazyCollection<java.lang.Object>
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

Specified by:
setBatchSize in interface LazyCollection<java.lang.Object>
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

asList

public java.util.List<java.lang.Object> asList()
Return this Collection as a List. This may create a new ArrayList if necessary so the returned List is not guaranteed to be consistent if the LazyCollection changes.

Specified by:
asList in interface LazyCollection<java.lang.Object>
Returns:
a List

isSingleBatch

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

Returns:
a boolean

iterator

public java.util.Iterator<java.lang.Object> iterator()

Specified by:
iterator in interface java.lang.Iterable<java.lang.Object>
Specified by:
iterator in interface java.util.Collection<java.lang.Object>
Specified by:
iterator in interface java.util.List<java.lang.Object>
Specified by:
iterator in interface java.util.Set<java.lang.Object>
Overrides:
iterator in class java.util.AbstractList<java.lang.Object>

iteratorFrom

public java.util.Iterator<java.lang.Object> iteratorFrom(int from)
Returns an iterator over the List, starting from the given position. This method is mainly useful for testing.

Parameters:
from - the index of the first object to be fetched
Returns:
an Interator

getResultsBatches

public ResultsBatches getResultsBatches()
Returns the underlying ResultsBatches object that this object is using, in order to create more Results objects (with different settings) from it.

Returns:
a ResultsBatches object