Package org.intermine.objectstore
Class ObjectStorePassthruImpl
- java.lang.Object
-
- org.intermine.objectstore.ObjectStorePassthruImpl
-
- All Implemented Interfaces:
ObjectStore
- Direct Known Subclasses:
ObjectStoreFastCollectionsForTranslatorImpl
,ObjectStoreFastCollectionsImpl
,ObjectStoreSafeImpl
public class ObjectStorePassthruImpl extends java.lang.Object implements ObjectStore
A generic ObjectStore that passes through every request to an underlying ObjectStore. Extend this to make useful ObjectStores.- Author:
- Matthew Wakeling
-
-
Field Summary
Fields Modifier and Type Field Description protected ObjectStore
os
-
Fields inherited from interface org.intermine.objectstore.ObjectStore
SEQUENCE_IGNORE
-
-
Constructor Summary
Constructors Constructor Description ObjectStorePassthruImpl(ObjectStore os)
Creates an instance, from another ObjectStore instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
cacheObjectById(java.lang.Integer id, InterMineObject obj2)
Places an entry into the objectstore getObjectById cache.int
count(Query q, java.util.Map<java.lang.Object,java.lang.Integer> sequence)
Counts the number of rows the query will produceClob
createClob()
Creates a new empty Clob that is valid for this ObjectStore.ObjectStoreBag
createObjectStoreBag()
Returns a new empty ObjectStoreBag object that is valid for 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 ObjectStoreResults
execute(Query q, int batchSize, boolean optimise, boolean explain, boolean prefetch)
Execute a Query on this ObjectStorejava.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 SingletonResultsSingletonResults
executeSingleton(Query q, int batchSize, boolean optimise, boolean explain, boolean prefetch)
Execute a Query on this ObjectStore, returning a SingletonResultsvoid
flushObjectById()
Completely empties the getObjectById cache.java.util.Set<java.lang.Object>
getComponentsForQuery(Query q)
Returns a Set of independent components that affect the results of the given Query.int
getMaxLimit()
Get the maximum LIMIT that can be used in an SQL query without throwing an ObjectStoreLimitReachedExceptionint
getMaxOffset()
Get the maximum range start index a that can be accessed in a Results object without throwing an ObjectStoreLimitReachedExceptionlong
getMaxTime()
Get the maximum time a query may take before throwing an ObjectStoreQueryDurationExceptionModel
getModel()
Return the metadata associated with this ObjectStoreObjectStoreWriter
getNewWriter()
Create an ObjectStoreWriter that writes into this ObjectStore.<T extends InterMineObject>
TgetObjectByExample(T 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)
Get an object from the ObjectStore by giving an ID.InterMineObject
getObjectById(java.lang.Integer id, java.lang.Class<? extends InterMineObject> clazz)
Get an object from the ObjectStore by giving an ID and a hint of the Class of the object.<T extends InterMineObject>
java.util.Collection<T>getObjectsByExample(T 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.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 colectionjava.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
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.
-
-
-
Field Detail
-
os
protected ObjectStore os
-
-
Constructor Detail
-
ObjectStorePassthruImpl
public ObjectStorePassthruImpl(ObjectStore os)
Creates an instance, from another ObjectStore instance.- Parameters:
os
- an ObjectStore object to use
-
-
Method Detail
-
getNewWriter
public ObjectStoreWriter getNewWriter() throws ObjectStoreException
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 interfaceObjectStore
- Returns:
- an ObjectStoreWriter
- Throws:
ObjectStoreException
- if an error occurs
-
execute
public Results execute(Query q)
Execute a Query on this ObjectStore- Specified by:
execute
in interfaceObjectStore
- 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 interfaceObjectStore
- Parameters:
q
- the Query to executebatchSize
- the batch size to initialise the Results object withoptimise
- whether to optimise queriesexplain
- whether to explain queriesprefetch
- 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 interfaceObjectStore
- 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 interfaceObjectStore
- Parameters:
q
- the Query to executebatchSize
- the batch size to initialise the Results object withoptimise
- whether to optimise queriesexplain
- whether to explain queriesprefetch
- 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 fromexecute(Query q)
.- Specified by:
execute
in interfaceObjectStore
- Parameters:
q
- the Query to executestart
- the start rowlimit
- the maximum number of rows to returnoptimise
- true if it is expected that optimising the query will improve performanceexplain
- true if the ObjectStore should enforce maximum query running time constraintssequence
- 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
-
getObjectById
public InterMineObject getObjectById(java.lang.Integer id) throws ObjectStoreException
Get an object from the ObjectStore by giving an ID.- Specified by:
getObjectById
in interfaceObjectStore
- Parameters:
id
- the ID of the object to fetch- Returns:
- the object from the ObjectStore or cache, or null if none exists
- Throws:
ObjectStoreException
- if an error occurs during retrieval of the object
-
getObjectById
public InterMineObject getObjectById(java.lang.Integer id, java.lang.Class<? extends InterMineObject> clazz) throws ObjectStoreException
Get an object from the ObjectStore by giving an ID and a hint of the Class of the object. WARNING: If you provide the wrong class hint, this method will negatively cache the non-presence of the object which will cause other getObjectById calls to return null even if the object exists in another class.- Specified by:
getObjectById
in interfaceObjectStore
- Parameters:
id
- the ID of the object to fetchclazz
- a class of the object- Returns:
- the object from the ObjectStore or the cache, or null if none exists
- Throws:
ObjectStoreException
- if an error occurs during the retrieval of 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 interfaceObjectStore
- 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
-
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 interfaceObjectStore
- 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 interfaceObjectStore
- Parameters:
id
- the ID of the object to invalidate
-
cacheObjectById
public java.lang.Object cacheObjectById(java.lang.Integer id, InterMineObject obj2)
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 interfaceObjectStore
- Parameters:
id
- the ID of the objectobj2
- 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 interfaceObjectStore
-
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 interfaceObjectStore
- 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 interfaceObjectStore
- 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 interfaceObjectStore
- Parameters:
q
- InterMine Query on which to count rowssequence
- 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 interfaceObjectStore
- Returns:
- the Model
-
getObjectByExample
public <T extends InterMineObject> T getObjectByExample(T 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 interfaceObjectStore
- Type Parameters:
T
- The actual type to return.- Parameters:
o
- an example objectfieldNames
- a Set of fieldnames- Returns:
- an InterMineObject from the objectstore, or null if none fits
- Throws:
ObjectStoreException
- if an underlying error occurs
-
getObjectsByExample
public <T extends InterMineObject> java.util.Collection<T> getObjectsByExample(T o, java.util.Set<java.lang.String> fieldNames) throws ObjectStoreException
Description copied from interface:ObjectStore
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:
getObjectsByExample
in interfaceObjectStore
- Type Parameters:
T
- The actual type to return.- Parameters:
o
- an example objectfieldNames
- a Set of fieldnames- Returns:
- zero or more InterMineObjects from the objectstore
- Throws:
ObjectStoreException
- if an underlying error occurs
-
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 interfaceObjectStore
- 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 interfaceObjectStore
- 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 interfaceObjectStore
- 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 interfaceObjectStore
- 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 interfaceObjectStore
- Returns:
- the maximum offset
-
getMaxTime
public long getMaxTime()
Get the maximum time a query may take before throwing an ObjectStoreQueryDurationException- Specified by:
getMaxTime
in interfaceObjectStore
- Returns:
- the maximum query time
-
getSerial
public java.lang.Integer getSerial() throws ObjectStoreException
Gets an ID number which is unique in the database.- Specified by:
getSerial
in interfaceObjectStore
- Returns:
- an Integer
- Throws:
ObjectStoreException
- if a problem occurs
-
createObjectStoreBag
public ObjectStoreBag createObjectStoreBag() throws ObjectStoreException
Returns a new empty ObjectStoreBag object that is valid for this ObjectStore.- Specified by:
createObjectStoreBag
in interfaceObjectStore
- Returns:
- an ObjectStoreBag
- Throws:
ObjectStoreException
- if an error occurs fetching a new ID
-
createClob
public Clob createClob() throws ObjectStoreException
Creates a new empty Clob that is valid for this ObjectStore.- Specified by:
createClob
in interfaceObjectStore
- Returns:
- a Clob
- Throws:
ObjectStoreException
- if an error occurs fetching a new ID
-
-