org.intermine.dataloader
Class IntegrationWriterAbstractImpl

java.lang.Object
  extended by org.intermine.dataloader.IntegrationWriterAbstractImpl
All Implemented Interfaces:
IntegrationWriter, ObjectStore, ObjectStoreWriter
Direct Known Subclasses:
IntegrationWriterDataTrackingImpl

public abstract class IntegrationWriterAbstractImpl
extends java.lang.Object
implements IntegrationWriter

Abstract implementation of ObjectStoreIntegrationWriter. To retain O/R mapping independence concrete subclasses should delegate writing to a mapping tool specific implementation of ObjectStoreWriter.


Field Summary
protected  BaseEquivalentObjectFetcher beof
           
protected  IntPresentSet dbIdsStored
           
protected  HintingFetcher eof
           
protected static int FROM_DB
           
protected  IntToIntMap idMap
           
protected  int idMapOps
           
protected  boolean ignoreDuplicates
           
protected  Source lastSource
           
protected  ObjectStoreWriter osw
           
protected  java.util.Set<java.lang.String> seenBrokenOneToMany
           
protected static int SKELETON
           
protected static int SOURCE
           
protected  long timeSpentRecursing
           
 
Fields inherited from interface org.intermine.objectstore.ObjectStore
SEQUENCE_IGNORE
 
Constructor Summary
IntegrationWriterAbstractImpl(ObjectStoreWriter osw)
          Constructs a new instance of an IntegrationWriter
 
Method Summary
 void abortTransaction()
          Request that the ObjectStore aborts and closes the transaction, delegate to internal ObjectStoreWriter.
 void addAllToBag(ObjectStoreBag osb, java.util.Collection<java.lang.Integer> coll)
          Adds a collection of elements to an ObjectStoreBag, delegate to internal ObjectStoreWriter.
 void addToBag(ObjectStoreBag osb, java.lang.Integer element)
          Adds an element to an ObjectStoreBag, delegate to internal ObjectStoreWriter.
 void addToBagFromQuery(ObjectStoreBag osb, Query query)
          Adds elements to an ObjectStoreBag, delegate to internal ObjectStoreWriter.
 void addToCollection(java.lang.Integer hasId, java.lang.Class<?> clazz, java.lang.String fieldName, java.lang.Integer hadId)
          Add an object to another object's collection, delegate to internal ObjectStoreWriter.
 void assignMapping(java.lang.Integer source, java.lang.Integer dest)
          Puts a mapping into idMap.
 void batchCommitTransaction()
          Request that the ObjectStoreWriter commits and closes the transaction and then opens a new one, without guaranteeing that the operation is finished before this method returns.
 void beginTransaction()
          Request that the ObjectStore begins a transaction, delegate to internal ObjectStoreWriter.
 java.lang.Object cacheObjectById(java.lang.Integer id, InterMineObject obj)
          Places an entry into the objectstore getObjectById cache.
 void close()
          Closes the connection associated with this ObjectStoreWriter
 void commitTransaction()
          Request that the ObjectStore commits and closes the transaction, delegate to internal ObjectStoreWriter.
protected  void copyField(FastPathObject srcObj, FastPathObject dest, Source source, Source skelSource, FieldDescriptor field, int type)
          Copies the value of the field given from the source object into the destination object.
 int count(Query q, java.util.Map<java.lang.Object,java.lang.Integer> sequence)
          Counts the number of rows the query will produce
 Clob createClob()
          Creates a new empty Clob that is valid for this ObjectStore.
 ObjectStoreBag createObjectStoreBag()
          Returns a new empty ObjectStoreBag for this ObjectStore, delegate to internal ObjectStoreWriter.
 void delete(InterMineObject o)
          Delete an object from this ObjectStore, delegate to internal ObjectStoreWriter.
 void delete(QueryClass qc, Constraint c)
          Deletes a set of objects from this ObjectStore.
 ResultsInfo estimate(Query q)
          Explain a Query (give estimate for execution time and number of rows).
 Results execute(Query q)
          Execute a Query on this ObjectStore
 Results execute(Query q, int batchSize, boolean optimise, boolean explain, boolean prefetch)
          Execute a Query on this ObjectStore
 java.util.List<ResultsRow<java.lang.Object>> execute(Query q, int start, int limit, boolean optimise, boolean explain, java.util.Map<java.lang.Object,java.lang.Integer> sequence)
          Execute a Query on this ObjectStore, asking for a certain range of rows to be returned.
 SingletonResults executeSingleton(Query q)
          Execute a Query on this ObjectStore, returning a SingletonResults
 SingletonResults executeSingleton(Query q, int batchSize, boolean optimise, boolean explain, boolean prefetch)
          Execute a Query on this ObjectStore, returning a SingletonResults
 void flushObjectById()
          Completely empties the getObjectById cache.
 BaseEquivalentObjectFetcher getBaseEof()
          Returns the base equivalent object fetcher.
 java.util.Set<java.lang.Object> getComponentsForQuery(Query q)
          Returns a Set of independent components that affect the results of the given Query.
 java.util.Set<InterMineObject> getEquivalentObjects(InterMineObject obj, Source source)
          Returns a Set of objects from the idMap or database that are equivalent to the given object, according to the primary keys defined by the given Source.
 int getMaxLimit()
          Get the maximum LIMIT that can be used in an SQL query without throwing an ObjectStoreLimitReachedException
 int getMaxOffset()
          Get the maximum range start index a that can be accessed in a Results object without throwing an ObjectStoreLimitReachedException
 long getMaxTime()
          Get the maximum time a query may take before throwing an ObjectStoreQueryDurationException
 Model getModel()
          Return the metadata associated with this ObjectStore
 ObjectStoreWriter getNewWriter()
          Create an ObjectStoreWriter that writes into this ObjectStore.
 InterMineObject getObjectByExample(InterMineObject o, java.util.Set<java.lang.String> fieldNames)
          Return an object from the objectstore that has the fields mentioned in the list set to the same values as the fields in the provided example object.
 InterMineObject getObjectById(java.lang.Integer id)
          Search database for object matching the given object id
 InterMineObject getObjectById(java.lang.Integer id, java.lang.Class<? extends InterMineObject> clazz)
          Search database for object matching the given object id and class
 java.util.List<InterMineObject> getObjectsByIds(java.util.Collection<java.lang.Integer> ids)
          Get an objects from the ObjectStore that have the IDs in the ids colection
 ObjectStore getObjectStore()
          Retrieve this Writer's ObjectStore.
 ObjectStoreWriter getObjectStoreWriter()
          Returns the underlying ObjectStoreWriter.
 java.util.Map<java.lang.Object,java.lang.Integer> getSequence(java.util.Set<java.lang.Object> tables)
          Return the sequence number representing the state of the ObjectStore.
 java.lang.Integer getSerial()
          Gets an ID number which is unique in the database.
 void invalidateObjectById(java.lang.Integer id)
          Removes an entry from the objectstore getObjectById cache.
 boolean isInTransaction()
          Check whether the ObjectStore is performing a transaction, delegate to internal ObjectStoreWriter.
 boolean isMultiConnection()
          Return whether or not this ObjectStore gives a performance improvement when multiple simultaneous are made.
 InterMineObject pilferObjectById(java.lang.Integer id)
          Gets a object from the cache if it is present.
 void prefetchObjectById(java.lang.Integer id)
          Prefetches an object into the objectstore getObjectById cache.
 void removeAllFromBag(ObjectStoreBag osb, java.util.Collection<java.lang.Integer> coll)
          Removes a collection of elements from an ObjectStoreBag, delegate to internal ObjectStoreWriter.
 void removeFromBag(ObjectStoreBag osb, java.lang.Integer element)
          Removes an element from an ObjectStoreBag, delegate to internal ObjectStoreWriter.
 void replaceClob(Clob clob, java.lang.String text)
          Replaces the contents of the given Clob with the given String.
 void reset()
          Resets the IntegrationWriter, clearing the id map and the hints
 void setEof(HintingFetcher eof)
          Sets the equivalent object fetcher.
 void setIgnoreDuplicates(boolean ignoreDuplicates)
          Tell this IntegrationWriter whether to ignore duplicate objects from the same source.
 void store(FastPathObject o, Source source, Source skelSource)
          Stores the given object in the objectstore.
protected abstract  InterMineObject store(FastPathObject o, Source source, Source skelSource, int type)
          Stores the given object in the objectstore.
 void store(java.lang.Object o)
          Store an object in this ObjectStore, delegates to internal ObjectStoreWriter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.intermine.dataloader.IntegrationWriter
getMainSource, getSkeletonSource
 

Field Detail

osw

protected ObjectStoreWriter osw

SKELETON

protected static final int SKELETON
See Also:
Constant Field Values

FROM_DB

protected static final int FROM_DB
See Also:
Constant Field Values

SOURCE

protected static final int SOURCE
See Also:
Constant Field Values

idMap

protected IntToIntMap idMap

dbIdsStored

protected IntPresentSet dbIdsStored

idMapOps

protected int idMapOps

ignoreDuplicates

protected boolean ignoreDuplicates

eof

protected HintingFetcher eof

beof

protected BaseEquivalentObjectFetcher beof

lastSource

protected Source lastSource

seenBrokenOneToMany

protected java.util.Set<java.lang.String> seenBrokenOneToMany

timeSpentRecursing

protected long timeSpentRecursing
Constructor Detail

IntegrationWriterAbstractImpl

public IntegrationWriterAbstractImpl(ObjectStoreWriter osw)
Constructs a new instance of an IntegrationWriter

Parameters:
osw - an instance of an ObjectStoreWriter, which we can use to access the database
Method Detail

reset

public void reset()
Resets the IntegrationWriter, clearing the id map and the hints


getBaseEof

public BaseEquivalentObjectFetcher getBaseEof()
Returns the base equivalent object fetcher.

Returns:
a BaseEquivalentObjectFetcher

setEof

public void setEof(HintingFetcher eof)
Sets the equivalent object fetcher.

Parameters:
eof - a HintingFetcher

setIgnoreDuplicates

public void setIgnoreDuplicates(boolean ignoreDuplicates)
Tell this IntegrationWriter whether to ignore duplicate objects from the same source. ALL DUPLICATES OF THE OBJECT MUST HAVE THE SAME FIELDS FILLED IN WITH THE SAME DATA. Data that differs between copies will result in undefined behaviour as so what data will appear in the destination database. Data that differs in primary keys may result in an exception being thrown during data loading. Note that setting a field to null differs from another copy with the field set to a value.

Specified by:
setIgnoreDuplicates in interface IntegrationWriter
Parameters:
ignoreDuplicates - the value of ignoreDuplicates

getObjectStoreWriter

public ObjectStoreWriter getObjectStoreWriter()
Returns the underlying ObjectStoreWriter.

Returns:
osw

getEquivalentObjects

public java.util.Set<InterMineObject> getEquivalentObjects(InterMineObject obj,
                                                           Source source)
                                                    throws ObjectStoreException
Returns a Set of objects from the idMap or database that are equivalent to the given object, according to the primary keys defined by the given Source.

Parameters:
obj - the Object to look for
source - the data Source
Returns:
a Set of InterMineObjects
Throws:
ObjectStoreException - if an error occurs

store

public void store(FastPathObject o,
                  Source source,
                  Source skelSource)
           throws ObjectStoreException
Stores the given object in the objectstore. To update an objectstore with data in the form of an interconnected graph of objects, call this method on each of the objects in that structure. This method will take care of merging objects, and resolving field priority issues.

Specified by:
store in interface IntegrationWriter
Parameters:
o - the object to store
source - the data Source to which to attribute the data
skelSource - the data Source to which to attribute skeleton data
Throws:
ObjectStoreException - if an error occurs in the underlying objectstore

store

protected abstract InterMineObject store(FastPathObject o,
                                         Source source,
                                         Source skelSource,
                                         int type)
                                  throws ObjectStoreException
Stores the given object in the objectstore. This method recurses into the object's fields according to the type variable.

Parameters:
o - the object to store
source - the data Source to which to attribute the data
skelSource - the data Source to which to attribute skeleton data
type - the type of action required, from SOURCE, SKELETON, or FROM_DB
Returns:
the InterMineObject that was written to the database
Throws:
ObjectStoreException - if an error occurs in the underlying objectstore

copyField

protected void copyField(FastPathObject srcObj,
                         FastPathObject dest,
                         Source source,
                         Source skelSource,
                         FieldDescriptor field,
                         int type)
                  throws java.lang.IllegalAccessException,
                         ObjectStoreException
Copies the value of the field given from the source object into the destination object.

Parameters:
srcObj - the source object
dest - the destination object
source - the data Source to which to attribute the data
skelSource - the data Source to which to attribute skeleton data
field - the FieldDescriptor describing the field to copy
type - the type of copy required - SOURCE for a full copy, SKELETON for a minimal copy that guarantees limited recursion, and FROM_DB to indicate that the source object originated from the destination database.
Throws:
java.lang.IllegalAccessException - should never happen
ObjectStoreException - if an error occurs in the underlying objectstore

assignMapping

public void assignMapping(java.lang.Integer source,
                          java.lang.Integer dest)
                   throws ObjectStoreException
Puts a mapping into idMap.

Parameters:
source - the ID of the object from the source
dest - the ID of the object from the destination
Throws:
ObjectStoreException - if an attempt is made to change an existing mapping

getObjectById

public InterMineObject getObjectById(java.lang.Integer id)
                              throws ObjectStoreException
Search database for object matching the given object id

Specified by:
getObjectById in interface ObjectStore
Parameters:
id - the object ID
Returns:
the retrieved object
Throws:
ObjectStoreException - if an error occurs retieving the object

getObjectById

public InterMineObject getObjectById(java.lang.Integer id,
                                     java.lang.Class<? extends InterMineObject> clazz)
                              throws ObjectStoreException
Search database for object matching the given object id and class

Specified by:
getObjectById in interface ObjectStore
Parameters:
id - the object ID
clazz - a Class of the object
Returns:
the retrieved object
Throws:
ObjectStoreException - if an error occurs retrieving the object

getObjectsByIds

public java.util.List<InterMineObject> getObjectsByIds(java.util.Collection<java.lang.Integer> ids)
                                                throws ObjectStoreException
Get an objects from the ObjectStore that have the IDs in the ids colection

Specified by:
getObjectsByIds in interface ObjectStore
Parameters:
ids - the IDs of the objects to fetch
Returns:
the objects from the ObjectStore or cache
Throws:
ObjectStoreException - if an error occurs during retrieval of the object

store

public void store(java.lang.Object o)
           throws ObjectStoreException
Store an object in this ObjectStore, delegates to internal ObjectStoreWriter.

Specified by:
store in interface ObjectStoreWriter
Parameters:
o - the object to store
Throws:
ObjectStoreException - if an error occurs during storage of the object

addToCollection

public void addToCollection(java.lang.Integer hasId,
                            java.lang.Class<?> clazz,
                            java.lang.String fieldName,
                            java.lang.Integer hadId)
                     throws ObjectStoreException
Add an object to another object's collection, delegate to internal ObjectStoreWriter.

Specified by:
addToCollection in interface ObjectStoreWriter
Parameters:
hasId - the ID of the object that has the collection
clazz - the class of the object
fieldName - the name of the collection
hadId - the ID of the object to be placed in the collection
Throws:
ObjectStoreException - if something goes wrong

delete

public void delete(InterMineObject o)
            throws ObjectStoreException
Delete an object from this ObjectStore, delegate to internal ObjectStoreWriter.

Specified by:
delete in interface ObjectStoreWriter
Parameters:
o - the object to delete
Throws:
ObjectStoreException - if an error occurs during deletion of the object

delete

public void delete(QueryClass qc,
                   Constraint c)
            throws ObjectStoreException
Deletes a set of objects from this ObjectStore.

Specified by:
delete in interface ObjectStoreWriter
Parameters:
qc - a QueryClass for the class of objects to delete
c - a Constraint based on the QueryClass to filter the objects to delete, or null to delete all objects
Throws:
ObjectStoreException - if an error occurs while deleting the objects

createObjectStoreBag

public ObjectStoreBag createObjectStoreBag()
                                    throws ObjectStoreException
Returns a new empty ObjectStoreBag for this ObjectStore, delegate to internal ObjectStoreWriter.

Specified by:
createObjectStoreBag in interface ObjectStore
Returns:
an ObjectStoreBag
Throws:
ObjectStoreException - if an error occurs fetching a new ID

addToBag

public void addToBag(ObjectStoreBag osb,
                     java.lang.Integer element)
              throws ObjectStoreException
Adds an element to an ObjectStoreBag, delegate to internal ObjectStoreWriter.

Specified by:
addToBag in interface ObjectStoreWriter
Parameters:
osb - an ObjectStoreBag
element - an Integer to add to the bag
Throws:
ObjectStoreException - if an error occurs

addAllToBag

public void addAllToBag(ObjectStoreBag osb,
                        java.util.Collection<java.lang.Integer> coll)
                 throws ObjectStoreException
Adds a collection of elements to an ObjectStoreBag, delegate to internal ObjectStoreWriter.

Specified by:
addAllToBag in interface ObjectStoreWriter
Parameters:
osb - an ObjectStoreBag
coll - a Collection of Integers
Throws:
ObjectStoreException - if an error occurs

removeFromBag

public void removeFromBag(ObjectStoreBag osb,
                          java.lang.Integer element)
                   throws ObjectStoreException
Removes an element from an ObjectStoreBag, delegate to internal ObjectStoreWriter.

Specified by:
removeFromBag in interface ObjectStoreWriter
Parameters:
osb - an ObjectStoreBag
element - an Integer to add to the bag
Throws:
ObjectStoreException - if an error occurs

removeAllFromBag

public void removeAllFromBag(ObjectStoreBag osb,
                             java.util.Collection<java.lang.Integer> coll)
                      throws ObjectStoreException
Removes a collection of elements from an ObjectStoreBag, delegate to internal ObjectStoreWriter.

Specified by:
removeAllFromBag in interface ObjectStoreWriter
Parameters:
osb - an ObjectStoreBag
coll - a Collection of Integers
Throws:
ObjectStoreException - if an error occurs

addToBagFromQuery

public void addToBagFromQuery(ObjectStoreBag osb,
                              Query query)
                       throws ObjectStoreException
Adds elements to an ObjectStoreBag, delegate to internal ObjectStoreWriter.

Specified by:
addToBagFromQuery in interface ObjectStoreWriter
Parameters:
osb - an ObjectStoreBag
query - a Query
Throws:
ObjectStoreException - if an error occurs

createClob

public Clob createClob()
                throws ObjectStoreException
Creates a new empty Clob that is valid for this ObjectStore.

Specified by:
createClob in interface ObjectStore
Returns:
a Clob
Throws:
ObjectStoreException - if an error occurs fetching a new ID

replaceClob

public void replaceClob(Clob clob,
                        java.lang.String text)
                 throws ObjectStoreException
Replaces the contents of the given Clob with the given String.

Specified by:
replaceClob in interface ObjectStoreWriter
Parameters:
clob - the Clob to write to
text - the text to write to the Clob
Throws:
ObjectStoreException - if something goes wrong

getSerial

public java.lang.Integer getSerial()
                            throws ObjectStoreException
Gets an ID number which is unique in the database.

Specified by:
getSerial in interface ObjectStore
Returns:
an Integer
Throws:
ObjectStoreException - if a problem occurs

isInTransaction

public boolean isInTransaction()
                        throws ObjectStoreException
Check whether the ObjectStore is performing a transaction, delegate to internal ObjectStoreWriter.

Specified by:
isInTransaction in interface ObjectStoreWriter
Returns:
true if in a transaction, false otherwise
Throws:
ObjectStoreException - if an error occurs the check

beginTransaction

public void beginTransaction()
                      throws ObjectStoreException
Request that the ObjectStore begins a transaction, delegate to internal ObjectStoreWriter.

Specified by:
beginTransaction in interface ObjectStoreWriter
Throws:
ObjectStoreException - if a transaction is in progress, or is aborted

commitTransaction

public void commitTransaction()
                       throws ObjectStoreException
Request that the ObjectStore commits and closes the transaction, delegate to internal ObjectStoreWriter.

Specified by:
commitTransaction in interface ObjectStoreWriter
Throws:
ObjectStoreException - if a transaction is not in progress, or is aborted

abortTransaction

public void abortTransaction()
                      throws ObjectStoreException
Request that the ObjectStore aborts and closes the transaction, delegate to internal ObjectStoreWriter.

Specified by:
abortTransaction in interface ObjectStoreWriter
Throws:
ObjectStoreException - if a transaction is not in progress

batchCommitTransaction

public void batchCommitTransaction()
                            throws ObjectStoreException
Request that the ObjectStoreWriter commits and closes the transaction and then opens a new one, without guaranteeing that the operation is finished before this method returns. Note that writes that are made AFTER this method may be treated as if they were BEFORE this method and be committed in the transaction.

Specified by:
batchCommitTransaction in interface ObjectStoreWriter
Throws:
ObjectStoreException - if an error occurs

getObjectStore

public ObjectStore getObjectStore()
Retrieve this Writer's ObjectStore. This ObjectStoreWriter is a read-write extension to the read-only ObjectStore. This ObjectStoreWriter uses a single database connection in order to allow proper transaction support - use the ObjectStore for general read-only access.

Specified by:
getObjectStore in interface ObjectStoreWriter
Returns:
the ObjectStore

execute

public Results execute(Query q)
Execute a Query on this ObjectStore

Specified by:
execute in interface ObjectStore
Parameters:
q - the Query to execute
Returns:
the results of the Query

execute

public Results execute(Query q,
                       int batchSize,
                       boolean optimise,
                       boolean explain,
                       boolean prefetch)
Execute a Query on this ObjectStore

Specified by:
execute in interface ObjectStore
Parameters:
q - the Query to execute
batchSize - the batch size to initialise the Results object with
optimise - whether to optimise queries
explain - whether to explain queries
prefetch - whether to use the PrefetchManager
Returns:
the results of the Query

executeSingleton

public SingletonResults executeSingleton(Query q)
Execute a Query on this ObjectStore, returning a SingletonResults

Specified by:
executeSingleton in interface ObjectStore
Parameters:
q - the Query to execute
Returns:
the results of the Query

executeSingleton

public SingletonResults executeSingleton(Query q,
                                         int batchSize,
                                         boolean optimise,
                                         boolean explain,
                                         boolean prefetch)
Execute a Query on this ObjectStore, returning a SingletonResults

Specified by:
executeSingleton in interface ObjectStore
Parameters:
q - the Query to execute
batchSize - the batch size to initialise the Results object with
optimise - whether to optimise queries
explain - whether to explain queries
prefetch - whether to use the PrefetchManager
Returns:
the results of the Query

execute

public java.util.List<ResultsRow<java.lang.Object>> execute(Query q,
                                                            int start,
                                                            int limit,
                                                            boolean optimise,
                                                            boolean explain,
                                                            java.util.Map<java.lang.Object,java.lang.Integer> sequence)
                                                     throws ObjectStoreException
Execute a Query on this ObjectStore, asking for a certain range of rows to be returned. This will usually only be called by the Results object returned from execute(Query q).

Specified by:
execute in interface ObjectStore
Parameters:
q - the Query to execute
start - the start row
limit - the maximum number of rows to return
optimise - true if it is expected that optimising the query will improve performance
explain - true if the ObjectStore should enforce maximum query running time constraints
sequence - an object representing the state of the database corresponding to when the action that resulted in this execute was started. This number must match the ObjectStore's internal sequence number or a DataChangedException is thrown. The sequence number is incremented each time the data in the objectstore is changed
Returns:
a List of ResultRows
Throws:
ObjectStoreException - if an error occurs during the running of the Query

prefetchObjectById

public void prefetchObjectById(java.lang.Integer id)
Prefetches an object into the objectstore getObjectById cache. This method doesn't actually have to do anything - it is merely a hint to the objectstore that a particular operation is likely to be required in the near future.

This method is provided primarily to help speed up our data loader. The method may block until the prefetch has been completed. However, the prefetch can be done outside of any synchronised areas of code, allowing the time-critical synchronised areas of code to access the object from the cache.

Specified by:
prefetchObjectById in interface ObjectStore
Parameters:
id - the ID of the object to prefetch

invalidateObjectById

public void invalidateObjectById(java.lang.Integer id)
Removes an entry from the objectstore getObjectById cache. The objectstore must guarantee that the next time this example object is requested by getObjectById, the objectstore explicitly fetches the object from the database. Obviously, if the objectstore does not have a getObjectById cache, this method will do nothing.

Specified by:
invalidateObjectById in interface ObjectStore
Parameters:
id - the ID of the object to invalidate

cacheObjectById

public java.lang.Object cacheObjectById(java.lang.Integer id,
                                        InterMineObject obj)
Places an entry into the objectstore getObjectById cache. This method (like prefetch) is merely a hint, and provides no guarantees. The method takes the object provided, and creates a lookup in the getObjectById cache, so that subsequent requests for that object do not access the database. If there is no cache, this method will do nothing.

Specified by:
cacheObjectById in interface ObjectStore
Parameters:
id - the ID of the object
obj - a fully populated object, as loaded from the database, or null to negatively cache
Returns:
an object which is softly-held part of the cache entry. This is useful to the caller for the purpose of ensuring the entry does not expire from the cache. To endure this, the caller merely needs to keep a strong reference to this returned value.

flushObjectById

public void flushObjectById()
Completely empties the getObjectById cache. The objectstore must guarantee that the next time any object is mentioned, it must not be taken from the cache.

Specified by:
flushObjectById in interface ObjectStore

pilferObjectById

public InterMineObject pilferObjectById(java.lang.Integer id)
Gets a object from the cache if it is present. If the object is not in the cache, then no attempt is made to retrieve it from the database, and null is returned. A trivial implementation may just return null always for this method.

Specified by:
pilferObjectById in interface ObjectStore
Parameters:
id - the ID of the object
Returns:
the object, or null

estimate

public ResultsInfo estimate(Query q)
                     throws ObjectStoreException
Explain a Query (give estimate for execution time and number of rows).

Specified by:
estimate in interface ObjectStore
Parameters:
q - the query to estimate rows for
Returns:
parsed results of EXPLAIN
Throws:
ObjectStoreException - if an error occurs explaining the query

count

public int count(Query q,
                 java.util.Map<java.lang.Object,java.lang.Integer> sequence)
          throws ObjectStoreException
Counts the number of rows the query will produce

Specified by:
count in interface ObjectStore
Parameters:
q - InterMine Query on which to count rows
sequence - an object representing the state of the database corresponding to when the action that resulted in this execute was started. This number must match the ObjectStore's internal sequence number or a DataChangedException is thrown. The sequence number is incremented each time the data in the objectstore is changed
Returns:
the number of rows that will be produced by query
Throws:
ObjectStoreException - if an error occurs counting the query

getModel

public Model getModel()
Return the metadata associated with this ObjectStore

Specified by:
getModel in interface ObjectStore
Returns:
the Model

getObjectByExample

public InterMineObject getObjectByExample(InterMineObject o,
                                          java.util.Set<java.lang.String> fieldNames)
                                   throws ObjectStoreException
Return an object from the objectstore that has the fields mentioned in the list set to the same values as the fields in the provided example object. If there are no objects in the objectstore like that, then this method returns null. If there are more than one object, then this method throws an IllegalArgumentException.

Specified by:
getObjectByExample in interface ObjectStore
Parameters:
o - an example object
fieldNames - a Set of fieldnames
Returns:
a InterMineObject from the objectstore, or null if none fits
Throws:
ObjectStoreException - if an underlying error occurs

close

public void close()
           throws ObjectStoreException
Closes the connection associated with this ObjectStoreWriter

Specified by:
close in interface ObjectStoreWriter
Throws:
ObjectStoreException - if something goes wrong

isMultiConnection

public boolean isMultiConnection()
Return whether or not this ObjectStore gives a performance improvement when multiple simultaneous are made. Note that ALL Objectstore must be multi-threading safe. If this method returns true, then the ObjectStore probably handles multiple connections to the database. The Results class uses this to work out whether or not to do prefetching.

Specified by:
isMultiConnection in interface ObjectStore
Returns:
true if one should do multiple simultaneous operations

getComponentsForQuery

public java.util.Set<java.lang.Object> getComponentsForQuery(Query q)
Returns a Set of independent components that affect the results of the given Query.

Specified by:
getComponentsForQuery in interface ObjectStore
Parameters:
q - a Query
Returns:
a Set of objects

getSequence

public java.util.Map<java.lang.Object,java.lang.Integer> getSequence(java.util.Set<java.lang.Object> tables)
Return the sequence number representing the state of the ObjectStore. This number is incremented each time the data in the ObjectStore is changed.

Specified by:
getSequence in interface ObjectStore
Parameters:
tables - a Set of independent database components to get data for
Returns:
an object representing the current database state

getMaxLimit

public int getMaxLimit()
Get the maximum LIMIT that can be used in an SQL query without throwing an ObjectStoreLimitReachedException

Specified by:
getMaxLimit in interface ObjectStore
Returns:
the maximum limit

getMaxOffset

public int getMaxOffset()
Get the maximum range start index a that can be accessed in a Results object without throwing an ObjectStoreLimitReachedException

Specified by:
getMaxOffset in interface ObjectStore
Returns:
the maximum offset

getMaxTime

public long getMaxTime()
Get the maximum time a query may take before throwing an ObjectStoreQueryDurationException

Specified by:
getMaxTime in interface ObjectStore
Returns:
the maximum query time

getNewWriter

public ObjectStoreWriter getNewWriter()
Create an ObjectStoreWriter that writes into this ObjectStore. Note that the given object will consume limited resources from the ObjectStore which must be returned by calling the ObjectStoreWriter.close() method.

Specified by:
getNewWriter in interface ObjectStore
Returns:
an ObjectStoreWriter