Class ObjectStoreInterMineImpl
- java.lang.Object
-
- org.intermine.objectstore.ObjectStoreAbstractImpl
-
- org.intermine.objectstore.intermine.ObjectStoreInterMineImpl
-
- All Implemented Interfaces:
ObjectStore
,Shutdownable
- Direct Known Subclasses:
ObjectStoreWriterInterMineImpl
public class ObjectStoreInterMineImpl extends ObjectStoreAbstractImpl implements Shutdownable
An SQL-backed implementation of the ObjectStore interface. The schema is oriented towards data retrieval and multiple inheritance, rather than efficient data storage.- Author:
- Matthew Wakeling, Andrew Varley
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ObjectStoreInterMineImpl.BagTableToRemove
Class describing a temporary bag table, which can be removed.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.Object,java.lang.String>
bagConstraintTables
static java.lang.String
BAGID_COLUMN
The name of the bagid column in the osbag table.protected java.util.Set<ObjectStoreInterMineImpl.BagTableToRemove>
bagTablesInDatabase
protected java.lang.ref.ReferenceQueue<java.lang.String>
bagTablesToRemove
static java.lang.String
BAGVAL_COLUMN
The name of the value column in the osbag table.protected java.util.Map<java.lang.String,java.util.Map<java.lang.Integer,ResultsBatches>>
batchesCache
protected static int
CACHE_LARGEST_OBJECT
static java.lang.String
CLOB_TABLE_NAME
The name of the table that stores Clobs.static java.lang.String
CLOBID_COLUMN
The name of the clobid column in the clob table.static java.lang.String
CLOBPAGE_COLUMN
The name of the page number column in the clob table.static java.lang.String
CLOBVAL_COLUMN
The name of the value column in the clob table.protected Database
db
protected java.lang.String
description
protected boolean
disableResultsCache
protected java.util.Map<Query,OptimiserCache>
goFasterCacheMap
protected java.util.Map<Query,java.lang.Integer>
goFasterCountMap
protected java.util.Map<Query,java.util.Set<PrecomputedTable>>
goFasterMap
protected static java.util.Map<java.lang.String,ObjectStoreInterMineImpl>
instances
static java.lang.String
INT_BAG_TABLE_NAME
The name of the table that holds the integer ObjectStoreBag elements.protected QueryOptimiserContext
limitedContext
protected java.io.Writer
log
protected boolean
logBeforeExecute
protected boolean
logEverything
protected boolean
logExplains
protected Batch
logTableBatch
protected java.sql.Connection
logTableConnection
protected java.lang.String
logTableName
protected int
minBagTableSize
protected java.util.Map<java.lang.String,Results>
resultsCache
protected DatabaseSchema
schema
protected static int
SEQUENCE_MULTIPLE
protected int
sequenceBase
protected int
sequenceOffset
protected java.util.Map<java.lang.String,SingletonResults>
singletonResultsCache
protected long
statsBagTableTime
protected long
statsConTime
protected long
statsEstTime
protected long
statsExeTime
protected long
statsGenTime
protected long
statsOptTime
static java.lang.String
UNIQUE_INTEGER_SEQUENCE_NAME
The name of the SEQUENCE in the database to use when generating unique integers in getUniqueInteger().protected boolean
verboseQueryLog
protected java.util.Set<ObjectStoreWriterInterMineImpl>
writers
-
Fields inherited from class org.intermine.objectstore.ObjectStoreAbstractImpl
cache, getObjectHits, getObjectOps, getObjectPrefetches, maxLimit, maxOffset, maxQueryParseTime, maxTime, model, rand, sequenceKeys, sequenceNumber
-
Fields inherited from interface org.intermine.objectstore.ObjectStore
SEQUENCE_IGNORE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ObjectStoreInterMineImpl(Model model)
Constructs an ObjectStoreInterMineImpl - for use by the ObjectStoreWriter only!protected
ObjectStoreInterMineImpl(Database db, DatabaseSchema schema)
Constructs an ObjectStoreInterMineImpl, with a schema.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancelRequest(java.lang.Object id)
This method cancels any Statement running in a given request ID, and blacklists that ID.void
close()
Closes this ObjectStore's DB log connection.int
count(Query q, java.util.Map<java.lang.Object,java.lang.Integer> sequence)
Counts the number of rows the query will produceprotected int
countWithConnection(java.sql.Connection c, Query q, java.util.Map<java.lang.Object,java.lang.Integer> sequence)
Counts the results in a query, given a Connection.protected ObjectStoreInterMineImpl.BagTableToRemove
createTempBagTable(java.sql.Connection c, ConstraintWithBag bagConstraint, boolean log, java.lang.String text)
Creates a temporary bag table for the given BagConstraint.protected ObjectStoreInterMineImpl.BagTableToRemove
createTempBagTable(java.sql.Connection c, QueryClassBag qcb, boolean log, java.lang.String text)
Creates a temporary bag table for the given QueryClassBag.void
createTempBagTable(ConstraintWithBag bagConstraint)
Creates a temporary bag table for the given BagConstraint.protected void
createTempBagTables(java.sql.Connection c, Query q)
Create temporary tables for use with Query that use bags.void
databaseAltered(java.util.Set<java.lang.Object> tablesAltered)
Internal method called by the ObjectStoreWriter, to notify the ObjectStore that some of the data in the database has changed.protected void
dbLog(long optimise, long estimated, long execute, long permitted, long convert, Query q, java.lang.String sql)
Produce an entry in the DB log.void
deregisterRequestId(java.lang.Object id)
This method deregisters a Thread from a request ID.protected void
deregisterStatement(java.sql.Statement s)
This method deregisters a Statement for the request ID of the current thread.protected void
doFinalise()
Finalise this object.ResultsInfo
estimate(Query q)
Explain a Query (give estimate for execution time and number of rows).protected ResultsInfo
estimateWithConnection(java.sql.Connection c, Query q)
Runs an EXPLAIN for the given query.boolean
everOptimise()
Returns whether optimisation should be permitted.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 SingletonResultsprotected java.util.List<ResultsRow<java.lang.Object>>
executeWithConnection(java.sql.Connection c, Query q, int start, int limit, boolean optimise, boolean explain, java.util.Map<java.lang.Object,java.lang.Integer> sequence)
Performs the actual execute, given a Connection.protected java.util.List<ResultsRow<java.lang.Object>>
executeWithConnection(java.sql.Connection c, Query q, int start, int limit, boolean optimise, boolean explain, java.util.Map<java.lang.Object,java.lang.Integer> sequence, java.util.Set<PrecomputedTable> goFasterTables, OptimiserCache goFasterCache)
Performs the actual execute, given a Connection.protected void
finalize()
Overrides Object.finalize - release the DB log connection.void
flushLogTable()
Allows the log table to be flushed, guaranteeing that all log entries are committed to the database.void
flushObjectById()
Completely empties the getObjectById cache.void
flushOldTempBagTables(java.sql.Connection c)
Removes any temporary bag tables that are no longer reachable.protected java.lang.String
generateSql(java.sql.Connection c, Query q, int start, int limit)
Create temporary tables for the bag in the BagConstraints of the given Query, then call SqlGenerator.generate().java.lang.String
generateSql(Query q)
Generate sql from a Queryprotected java.lang.String
generateSqlForCount(java.sql.Connection c, Query q)
Generate SQL only for counting; no need to order by and no need to calculate LIMIT and OFFSET Create temporary tables for the bag in the BagConstraints of the given Query, then call directly SqlGenerator.generate() using as Query type the value QUERY_FOR_COUNTINGjava.util.Set<java.lang.Object>
getComponentsForQuery(Query q)
Returns a Set of independent components that affect the results of the given Query.java.sql.Connection
getConnection()
Returns a Connection.Database
getDatabase()
Returns the Database used by this ObjectStoreboolean
getDisableResultsCache()
Gets the disableResultsCache configuration option.static ObjectStoreInterMineImpl
getInstance(java.lang.String osAlias, java.util.Properties props)
Gets a ObjectStoreInterMineImpl instance for the given underlying propertiesjava.io.Writer
getLog()
Returns the log used by this objectstore.boolean
getLogBeforeExecute()
Gets the logBeforeExecute configuration option.boolean
getLogEverything()
Gets the logEverything configuration option.boolean
getLogExplains()
Gets the logExplains configuration option.int
getMinBagTableSize()
Returns the cutoff value used to decide if a bag should be put in a table.ObjectStoreWriterInterMineImpl
getNewWriter()
Create an ObjectStoreWriter that writes into this ObjectStore.DatabaseSchema
getSchema()
Returns the DatabaseSchema used by this ObjectStore.java.lang.Integer
getSerial()
Gets an ID number which is unique in the database.protected java.lang.Integer
getSerialWithConnection(java.sql.Connection c)
Gets an ID number which is unique in the database, given a Connection.int
getUniqueInteger(java.sql.Connection c)
Return a unique integer from a SEQUENCE in the database.boolean
getVerboseQueryLog()
Gets the verboseQueryLog configuration option.void
goFaster(Query q)
Makes a certain Query go faster, using extra resources.void
goFasterWithConnection(Query q, java.sql.Connection c)
Makes a certain Query go faster, using extra resources.protected InterMineObject
internalGetObjectById(java.lang.Integer id, java.lang.Class<? extends InterMineObject> clazz)
Internal service method for getObjectById.protected InterMineObject
internalGetObjectByIdWithConnection(java.sql.Connection c, java.lang.Integer id, java.lang.Class<?> clazz)
Gets an object by id given a Connection.boolean
isMultiConnection()
Return whether or not this ObjectStore gives a performance improvement when multiple simultaneous are made.boolean
isPrecomputed(Query query, java.lang.String type)
Checks if a query is precomputed or not for the given typeboolean
isPrecomputedWithConnection(java.sql.Connection c, Query query, java.lang.String type)
Checks if a query is precomputed or not for the given type and connection<T> T
performUnsafeOperation(java.lang.String sql, SQLOperation<T> operation)
Convenience wrapper to manage the boilerplate when performing unsafe operations.java.util.List<java.lang.String>
precompute(Query q, boolean allFields, java.lang.String category)
Creates precomputed tables for the given query.java.util.List<java.lang.String>
precompute(Query q, java.lang.String category)
Creates precomputed tables for the given query.java.util.List<java.lang.String>
precompute(Query q, java.util.Collection<? extends QueryNode> indexes, boolean allFields, java.lang.String category)
Creates precomputed tables for the given query.java.util.List<java.lang.String>
precompute(Query q, java.util.Collection<? extends QueryNode> indexes, java.lang.String category)
Creates precomputed tables for the given query.java.util.List<java.lang.String>
precomputeWithConnection(java.sql.Connection c, Query q, java.util.Collection<? extends QueryNode> indexes, boolean allFields, java.lang.String category)
Creates precomputed tables with the given query and connection.void
registerRequestId(java.lang.Object id)
This method registers a Thread with a request ID.protected void
registerStatement(java.sql.Statement s)
This method registers a Statement with the current Thread's request ID, or throws an exception if that request is black-listed, or does nothing if no request ID is present for this Thread.void
releaseConnection(java.sql.Connection c)
Allows one to put a connection back.void
releaseGoFaster(Query q)
Releases the resources used by goFaster().protected void
removeTempBagTable(java.sql.Connection c, ObjectStoreInterMineImpl.BagTableToRemove bttr)
Removes a temporary bag table, given a BagTableToRemove object.void
setDisableResultsCache(boolean disableResultsCache)
Sets the disableResultsCache configuration option.void
setLog(java.io.Writer log)
Set the log writervoid
setLogBeforeExecute(boolean logBeforeExecute)
Sets the logBeforeExecute configuration option.void
setLogEverything(boolean logEverything)
Sets the logEverything configuration option.void
setLogExplains(boolean logExplains)
Sets the logExplains configuration option.void
setLogTableName(java.lang.String tableName)
Allows the log table name to be set in this objectstore.void
setMinBagTableSize(int minBagTableSize)
Set the cutoff value used to decide if a bag should be put in a table.void
setVerboseQueryLog(boolean verboseQueryLog)
Sets the verboseQueryLog configuration option.void
shutdown()
Called by the ShutdownHook on shutdown.java.lang.String
toString()
-
Methods inherited from class org.intermine.objectstore.ObjectStoreAbstractImpl
cacheObjectById, changeSequence, checkSequence, checkStartLimit, createClob, createObjectStoreBag, getMaxLimit, getMaxOffset, getMaxQueryParseTime, getMaxTime, getModel, getModelFromClasspath, getObjectByExample, getObjectById, getObjectById, getObjectsByExample, getObjectsByIds, getSequence, invalidateObjectById, pilferObjectById, prefetchObjectById
-
-
-
-
Field Detail
-
CACHE_LARGEST_OBJECT
protected static final int CACHE_LARGEST_OBJECT
- See Also:
- Constant Field Values
-
instances
protected static java.util.Map<java.lang.String,ObjectStoreInterMineImpl> instances
-
db
protected Database db
-
writers
protected java.util.Set<ObjectStoreWriterInterMineImpl> writers
-
log
protected java.io.Writer log
-
schema
protected DatabaseSchema schema
-
logTableConnection
protected java.sql.Connection logTableConnection
-
logTableBatch
protected Batch logTableBatch
-
logTableName
protected java.lang.String logTableName
-
logEverything
protected boolean logEverything
-
statsBagTableTime
protected long statsBagTableTime
-
statsGenTime
protected long statsGenTime
-
statsOptTime
protected long statsOptTime
-
statsEstTime
protected long statsEstTime
-
statsExeTime
protected long statsExeTime
-
statsConTime
protected long statsConTime
-
limitedContext
protected QueryOptimiserContext limitedContext
-
verboseQueryLog
protected boolean verboseQueryLog
-
logBeforeExecute
protected boolean logBeforeExecute
-
sequenceBase
protected int sequenceBase
-
sequenceOffset
protected int sequenceOffset
-
SEQUENCE_MULTIPLE
protected static final int SEQUENCE_MULTIPLE
- See Also:
- Constant Field Values
-
logExplains
protected boolean logExplains
-
disableResultsCache
protected boolean disableResultsCache
-
minBagTableSize
protected int minBagTableSize
-
bagConstraintTables
protected java.util.Map<java.lang.Object,java.lang.String> bagConstraintTables
-
bagTablesInDatabase
protected java.util.Set<ObjectStoreInterMineImpl.BagTableToRemove> bagTablesInDatabase
-
goFasterMap
protected java.util.Map<Query,java.util.Set<PrecomputedTable>> goFasterMap
-
goFasterCacheMap
protected java.util.Map<Query,OptimiserCache> goFasterCacheMap
-
goFasterCountMap
protected java.util.Map<Query,java.lang.Integer> goFasterCountMap
-
bagTablesToRemove
protected java.lang.ref.ReferenceQueue<java.lang.String> bagTablesToRemove
-
description
protected java.lang.String description
-
resultsCache
protected java.util.Map<java.lang.String,Results> resultsCache
-
singletonResultsCache
protected java.util.Map<java.lang.String,SingletonResults> singletonResultsCache
-
batchesCache
protected java.util.Map<java.lang.String,java.util.Map<java.lang.Integer,ResultsBatches>> batchesCache
-
UNIQUE_INTEGER_SEQUENCE_NAME
public static final java.lang.String UNIQUE_INTEGER_SEQUENCE_NAME
The name of the SEQUENCE in the database to use when generating unique integers in getUniqueInteger().- See Also:
- Constant Field Values
-
INT_BAG_TABLE_NAME
public static final java.lang.String INT_BAG_TABLE_NAME
The name of the table that holds the integer ObjectStoreBag elements.- See Also:
- Constant Field Values
-
BAGID_COLUMN
public static final java.lang.String BAGID_COLUMN
The name of the bagid column in the osbag table.- See Also:
- Constant Field Values
-
BAGVAL_COLUMN
public static final java.lang.String BAGVAL_COLUMN
The name of the value column in the osbag table.- See Also:
- Constant Field Values
-
CLOB_TABLE_NAME
public static final java.lang.String CLOB_TABLE_NAME
The name of the table that stores Clobs.- See Also:
- Constant Field Values
-
CLOBID_COLUMN
public static final java.lang.String CLOBID_COLUMN
The name of the clobid column in the clob table.- See Also:
- Constant Field Values
-
CLOBPAGE_COLUMN
public static final java.lang.String CLOBPAGE_COLUMN
The name of the page number column in the clob table.- See Also:
- Constant Field Values
-
CLOBVAL_COLUMN
public static final java.lang.String CLOBVAL_COLUMN
The name of the value column in the clob table.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ObjectStoreInterMineImpl
protected ObjectStoreInterMineImpl(Model model)
Constructs an ObjectStoreInterMineImpl - for use by the ObjectStoreWriter only!- Parameters:
model
- the model- Throws:
java.lang.NullPointerException
- if model is nulljava.lang.IllegalArgumentException
- if model is invalid
-
ObjectStoreInterMineImpl
protected ObjectStoreInterMineImpl(Database db, DatabaseSchema schema)
Constructs an ObjectStoreInterMineImpl, with a schema.- Parameters:
db
- the database in which the model residesschema
- the schema- Throws:
java.lang.NullPointerException
- if db or model are nulljava.lang.IllegalArgumentException
- if db or model are invalid
-
-
Method Detail
-
getNewWriter
public ObjectStoreWriterInterMineImpl 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
- Overrides:
getNewWriter
in classObjectStoreAbstractImpl
- Returns:
- an ObjectStoreWriter
- Throws:
ObjectStoreException
- if an error occurs
-
getSchema
public DatabaseSchema getSchema()
Returns the DatabaseSchema used by this ObjectStore.- Returns:
- a DatabaseSchema
-
getDatabase
public Database getDatabase()
Returns the Database used by this ObjectStore- Returns:
- the db
-
everOptimise
public boolean everOptimise()
Returns whether optimisation should be permitted. For the ObjectStore, this will always be true, but for the ObjectStoreWriter, it may be false if there is written data that has not been committed yet.- Returns:
- a boolean
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException
Returns a Connection. Please put them back. Whenever you receive a connection from the object-store, you MUST release its resources by calling releaseConnection. Failure to do so KILLS THE OBJECT STORE!- Returns:
- a java.sql.Connection
- Throws:
java.sql.SQLException
- if there is a problem with that
-
performUnsafeOperation
public <T> T performUnsafeOperation(java.lang.String sql, SQLOperation<T> operation) throws java.sql.SQLException
Convenience wrapper to manage the boilerplate when performing unsafe operations.- Type Parameters:
T
- The type of thing to return.- Parameters:
sql
- The sql to perform this operation.operation
- The operation to perform with the prepared statement.- Returns:
- A T of some kind
- Throws:
java.sql.SQLException
- if there is a problem running the query.
-
releaseConnection
public void releaseConnection(java.sql.Connection c)
Allows one to put a connection back.- Parameters:
c
- a Connection
-
getInstance
public static ObjectStoreInterMineImpl getInstance(java.lang.String osAlias, java.util.Properties props) throws ObjectStoreException
Gets a ObjectStoreInterMineImpl instance for the given underlying properties- Parameters:
osAlias
- the alias of this objectstoreprops
- The properties used to configure a InterMine-based objectstore- Returns:
- the ObjectStoreInterMineImpl for this repository
- Throws:
java.lang.IllegalArgumentException
- if props or model are invalidObjectStoreException
- if there is any problem with the instance
-
getLog
public java.io.Writer getLog()
Returns the log used by this objectstore.- Returns:
- the log
-
setLog
public void setLog(java.io.Writer log)
Set the log writer- Parameters:
log
- the log
-
setLogTableName
public void setLogTableName(java.lang.String tableName) throws java.sql.SQLException
Allows the log table name to be set in this objectstore.- Parameters:
tableName
- the table name- Throws:
java.sql.SQLException
- if something goes wrong
-
setLogEverything
public void setLogEverything(boolean logEverything)
Sets the logEverything configuration option.- Parameters:
logEverything
- a boolean
-
getLogEverything
public boolean getLogEverything()
Gets the logEverything configuration option.- Returns:
- a boolean
-
setVerboseQueryLog
public void setVerboseQueryLog(boolean verboseQueryLog)
Sets the verboseQueryLog configuration option.- Parameters:
verboseQueryLog
- a boolean
-
getVerboseQueryLog
public boolean getVerboseQueryLog()
Gets the verboseQueryLog configuration option.- Returns:
- a boolean
-
setLogExplains
public void setLogExplains(boolean logExplains)
Sets the logExplains configuration option.- Parameters:
logExplains
- a boolean
-
getLogExplains
public boolean getLogExplains()
Gets the logExplains configuration option.- Returns:
- a boolean
-
setLogBeforeExecute
public void setLogBeforeExecute(boolean logBeforeExecute)
Sets the logBeforeExecute configuration option.- Parameters:
logBeforeExecute
- a boolean
-
getLogBeforeExecute
public boolean getLogBeforeExecute()
Gets the logBeforeExecute configuration option.- Returns:
- a boolean
-
setDisableResultsCache
public void setDisableResultsCache(boolean disableResultsCache)
Sets the disableResultsCache configuration option.- Parameters:
disableResultsCache
- a boolean
-
getDisableResultsCache
public boolean getDisableResultsCache()
Gets the disableResultsCache configuration option.- Returns:
- a boolean
-
flushLogTable
public void flushLogTable()
Allows the log table to be flushed, guaranteeing that all log entries are committed to the database.
-
dbLog
protected void dbLog(long optimise, long estimated, long execute, long permitted, long convert, Query q, java.lang.String sql)
Produce an entry in the DB log.- Parameters:
optimise
- the number of milliseconds used to optimise the queryestimated
- the estimated number of milliseconds required to run the queryexecute
- the number of milliseconds spent executing the querypermitted
- an acceptable number of milliseconds for the query to takeconvert
- the number of milliseconds spent converting the resultsq
- the Query runsql
- the SQL string executed
-
setMinBagTableSize
public void setMinBagTableSize(int minBagTableSize)
Set the cutoff value used to decide if a bag should be put in a table.- Parameters:
minBagTableSize
- don't use a table to represent bags if the bag is smaller than this value
-
getMinBagTableSize
public int getMinBagTableSize()
Returns the cutoff value used to decide if a bag should be put in a table.- Returns:
- an int
-
execute
public Results execute(Query q)
Execute a Query on this ObjectStore- Specified by:
execute
in interfaceObjectStore
- Overrides:
execute
in classObjectStoreAbstractImpl
- 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
- Overrides:
execute
in classObjectStoreAbstractImpl
- 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
- Overrides:
executeSingleton
in classObjectStoreAbstractImpl
- 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
- Overrides:
executeSingleton
in classObjectStoreAbstractImpl
- 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
-
registerRequestId
public void registerRequestId(java.lang.Object id) throws ObjectStoreException
This method registers a Thread with a request ID.- Parameters:
id
- the request ID- Throws:
ObjectStoreException
- if this Thread is already registered
-
deregisterRequestId
public void deregisterRequestId(java.lang.Object id) throws ObjectStoreException
This method deregisters a Thread from a request ID.- Parameters:
id
- the request ID- Throws:
ObjectStoreException
- if the Thread is not registered with this ID
-
registerStatement
protected void registerStatement(java.sql.Statement s) throws ObjectStoreException
This method registers a Statement with the current Thread's request ID, or throws an exception if that request is black-listed, or does nothing if no request ID is present for this Thread.- Parameters:
s
- a Statement- Throws:
ObjectStoreException
- if the request is black-listed
-
cancelRequest
public void cancelRequest(java.lang.Object id) throws ObjectStoreException
This method cancels any Statement running in a given request ID, and blacklists that ID.- Parameters:
id
- the request ID- Throws:
ObjectStoreException
- if the cancel fails
-
deregisterStatement
protected void deregisterStatement(java.sql.Statement s) throws ObjectStoreException
This method deregisters a Statement for the request ID of the current thread.- Parameters:
s
- a Statement- Throws:
ObjectStoreException
- if this Thread does not have this Statement registered
-
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
-
finalize
protected void finalize() throws java.lang.Throwable
Overrides Object.finalize - release the DB log connection.- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
- never
-
doFinalise
protected void doFinalise()
Finalise this object.
-
close
public void close() throws ObjectStoreException
Closes this ObjectStore's DB log connection.- Throws:
ObjectStoreException
- in subclasses
-
shutdown
public void shutdown()
Called by the ShutdownHook on shutdown.- Specified by:
shutdown
in interfaceShutdownable
-
executeWithConnection
protected java.util.List<ResultsRow<java.lang.Object>> executeWithConnection(java.sql.Connection c, Query q, int start, int limit, boolean optimise, boolean explain, java.util.Map<java.lang.Object,java.lang.Integer> sequence) throws ObjectStoreException
Performs the actual execute, given a Connection.- Parameters:
c
- the Connectionq
- the Querystart
- the start row number (inclusive, from zero)limit
- maximum number of rows to returnoptimise
- booleanexplain
- booleansequence
- object representing database state- Returns:
- a List of ResultRow objects
- Throws:
ObjectStoreException
- sometimes
-
executeWithConnection
protected java.util.List<ResultsRow<java.lang.Object>> executeWithConnection(java.sql.Connection c, Query q, int start, int limit, boolean optimise, boolean explain, java.util.Map<java.lang.Object,java.lang.Integer> sequence, java.util.Set<PrecomputedTable> goFasterTables, OptimiserCache goFasterCache) throws ObjectStoreException
Performs the actual execute, given a Connection.- Parameters:
c
- the Connectionq
- the Querystart
- the start row number (inclusive, from zero)limit
- maximum number of rows to returnoptimise
- booleanexplain
- booleansequence
- object representing database stategoFasterTables
- a Set of PrecomputedTables that can help with the querygoFasterCache
- an OptimiserCache that can help with the query- Returns:
- a List of ResultRow objects
- Throws:
ObjectStoreException
- sometimes
-
generateSql
public java.lang.String generateSql(Query q) throws ObjectStoreException
Generate sql from a Query- Parameters:
q
- the Query- Returns:
- an SQL String
- Throws:
ObjectStoreException
- if something goes wrong
-
generateSql
protected java.lang.String generateSql(java.sql.Connection c, Query q, int start, int limit) throws ObjectStoreException
Create temporary tables for the bag in the BagConstraints of the given Query, then call SqlGenerator.generate().- Parameters:
c
- a Connection to useq
- the Querystart
- the start row number (inclusive, from zero)limit
- maximum number of rows to return- Returns:
- the SQL for the Query
- Throws:
ObjectStoreException
- if an error occurs
-
generateSqlForCount
protected java.lang.String generateSqlForCount(java.sql.Connection c, Query q) throws ObjectStoreException
Generate SQL only for counting; no need to order by and no need to calculate LIMIT and OFFSET Create temporary tables for the bag in the BagConstraints of the given Query, then call directly SqlGenerator.generate() using as Query type the value QUERY_FOR_COUNTING- Parameters:
c
- a Connection to useq
- the Query- Returns:
- the SQL for the Query
- Throws:
ObjectStoreException
- if an error occurs
-
createTempBagTables
protected void createTempBagTables(java.sql.Connection c, Query q) throws ObjectStoreException
Create temporary tables for use with Query that use bags. Each BagConstraint in the Query is examined and a temporary table containing values of the appropriate type from the bag is created. The new table names will be the values of the bagConstraintTables Map and the BagConstraint references will be the keys.- Parameters:
c
- a Connection to useq
- the Query- Throws:
ObjectStoreException
- if there is a error in the ObjectStore
-
createTempBagTable
public void createTempBagTable(ConstraintWithBag bagConstraint) throws ObjectStoreException
Creates a temporary bag table for the given BagConstraint.- Parameters:
bagConstraint
- a BagConstraint- Throws:
ObjectStoreException
- if an error occurs
-
createTempBagTable
protected ObjectStoreInterMineImpl.BagTableToRemove createTempBagTable(java.sql.Connection c, ConstraintWithBag bagConstraint, boolean log, java.lang.String text) throws java.sql.SQLException
Creates a temporary bag table for the given BagConstraint.- Parameters:
c
- a ConnectionbagConstraint
- a BagConstraintlog
- true to log this actiontext
- extra data to place in the log- Returns:
- a BagTableToRemove object
- Throws:
java.sql.SQLException
- if an error occurs
-
createTempBagTable
protected ObjectStoreInterMineImpl.BagTableToRemove createTempBagTable(java.sql.Connection c, QueryClassBag qcb, boolean log, java.lang.String text) throws java.sql.SQLException
Creates a temporary bag table for the given QueryClassBag.- Parameters:
c
- a Connectionqcb
- a QueryClassBaglog
- true to log this actiontext
- extra data to place in the log- Returns:
- a BagTableToRemove object
- Throws:
java.sql.SQLException
- if an error occurs
-
flushOldTempBagTables
public void flushOldTempBagTables(java.sql.Connection c)
Removes any temporary bag tables that are no longer reachable.- Parameters:
c
- the Connection to use
-
removeTempBagTable
protected void removeTempBagTable(java.sql.Connection c, ObjectStoreInterMineImpl.BagTableToRemove bttr)
Removes a temporary bag table, given a BagTableToRemove object.- Parameters:
c
- the Connection to usebttr
- the BagTableToRemove object
-
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
-
estimateWithConnection
protected ResultsInfo estimateWithConnection(java.sql.Connection c, Query q) throws ObjectStoreException
Runs an EXPLAIN for the given query.- Parameters:
c
- the Connectionq
- the Query to explain- 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
-
countWithConnection
protected int countWithConnection(java.sql.Connection c, Query q, java.util.Map<java.lang.Object,java.lang.Integer> sequence) throws ObjectStoreException
Counts the results in a query, given a Connection.- Parameters:
c
- the Connectionq
- the Querysequence
- int- Returns:
- an int
- Throws:
ObjectStoreException
- sometimes
-
databaseAltered
public void databaseAltered(java.util.Set<java.lang.Object> tablesAltered)
Internal method called by the ObjectStoreWriter, to notify the ObjectStore that some of the data in the database has changed.- Parameters:
tablesAltered
- a Set of table names that may have been altered
-
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
- Overrides:
flushObjectById
in classObjectStoreAbstractImpl
-
internalGetObjectById
protected InterMineObject internalGetObjectById(java.lang.Integer id, java.lang.Class<? extends InterMineObject> clazz) throws ObjectStoreException
Internal service method for getObjectById. This method is overridden in order to improve the performance of the operation - this implementation does not bother with the EXPLAIN call to the underlying SQL database.- Overrides:
internalGetObjectById
in classObjectStoreAbstractImpl
- Parameters:
id
- the ID of the object to getclazz
- a class of the object- Returns:
- an object from the database
- Throws:
ObjectStoreException
- if an error occurs during the running of the Query
-
internalGetObjectByIdWithConnection
protected InterMineObject internalGetObjectByIdWithConnection(java.sql.Connection c, java.lang.Integer id, java.lang.Class<?> clazz) throws ObjectStoreException
Gets an object by id given a Connection.- Parameters:
c
- the Connectionid
- the idclazz
- a Class of the object- Returns:
- the object
- Throws:
ObjectStoreException
- if an 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
-
precompute
public java.util.List<java.lang.String> precompute(Query q, java.lang.String category) throws ObjectStoreException
Creates precomputed tables for the given query.- Parameters:
q
- the Query for which to create the precomputed tablescategory
- a String describing the category of the precomputed tables- Returns:
- the names of the new precomputed tables
- Throws:
ObjectStoreException
- if anything goes wrong
-
precompute
public java.util.List<java.lang.String> precompute(Query q, boolean allFields, java.lang.String category) throws ObjectStoreException
Creates precomputed tables for the given query.- Parameters:
q
- the Query for which to create the precomputed tablesallFields
- true if all fields of QueryClasses in the SELECT list should be included in the precomputed table's SELECT list.category
- a String describing the category of the precomputed tables- Returns:
- the names of the new precomputed tables
- Throws:
ObjectStoreException
- if anything goes wrong
-
precompute
public java.util.List<java.lang.String> precompute(Query q, java.util.Collection<? extends QueryNode> indexes, java.lang.String category) throws ObjectStoreException
Creates precomputed tables for the given query.- Parameters:
q
- the Query for which to create the precomputed tablesindexes
- a Collection of QueryNode for which to create indexescategory
- a String describing the category of the precomputed tables- Returns:
- the names of the new precomputed tables
- Throws:
ObjectStoreException
- if anything goes wrong
-
precompute
public java.util.List<java.lang.String> precompute(Query q, java.util.Collection<? extends QueryNode> indexes, boolean allFields, java.lang.String category) throws ObjectStoreException
Creates precomputed tables for the given query.- Parameters:
q
- the Query for which to create the precomputed tablesindexes
- a Collection of QueryNodes for which to create indexesallFields
- true if all fields of QueryClasses in the SELECT list should be included in the precomputed table's SELECT list. If the indexes parameter is null, then indexes will be created for every field as wellcategory
- a String describing the category of the precomputed tables- Returns:
- the names of the new precomputed tables
- Throws:
ObjectStoreException
- if anything goes wrong
-
precomputeWithConnection
public java.util.List<java.lang.String> precomputeWithConnection(java.sql.Connection c, Query q, java.util.Collection<? extends QueryNode> indexes, boolean allFields, java.lang.String category) throws ObjectStoreException
Creates precomputed tables with the given query and connection.- Parameters:
c
- the Connectionq
- the Queryindexes
- a Collection of QueryNodes for which to create indexes - they must all exist in the SELECT list of the queryallFields
- true if all fields of QueryClasses in the SELECT list should be included in the precomputed table's SELECT list. If the indexes parameter is null, then indexes will be created for every field as wellcategory
- a String describing the category of the precomputed tables- Returns:
- the names of the new precomputed tables
- Throws:
ObjectStoreException
- if anything goes wrong
-
isPrecomputed
public boolean isPrecomputed(Query query, java.lang.String type) throws ObjectStoreException
Checks if a query is precomputed or not for the given type- Parameters:
query
- the querytype
- the type- Returns:
- true if and only if the given query is (already) precomputed
- Throws:
ObjectStoreException
- if the is a database problem
-
isPrecomputedWithConnection
public boolean isPrecomputedWithConnection(java.sql.Connection c, Query query, java.lang.String type) throws ObjectStoreException, java.sql.SQLException
Checks if a query is precomputed or not for the given type and connection- Parameters:
c
- the connectionquery
- the querytype
- the type- Returns:
- true if and only if the given query is (already) precomputed
- Throws:
ObjectStoreException
- if there is a database problemjava.sql.SQLException
- if there is a database problem
-
goFaster
public void goFaster(Query q) throws ObjectStoreException
Makes a certain Query go faster, using extra resources. The user should release the resources later by calling releaseGoFaster on the same Query. Failure to release resources may result in an overall degradation in performance.- Parameters:
q
- the Query to speed up- Throws:
ObjectStoreException
- if something is wrong
-
goFasterWithConnection
public void goFasterWithConnection(Query q, java.sql.Connection c) throws ObjectStoreException
Makes a certain Query go faster, using extra resources. The user should release the resources later by calling releaseGoFaster on the same Query. Failure to release resources may result in an overall degradation in performance.- Parameters:
q
- the Query to speed upc
- the Connection to use- Throws:
ObjectStoreException
- if something is wrong
-
releaseGoFaster
public void releaseGoFaster(Query q) throws ObjectStoreException
Releases the resources used by goFaster().- Parameters:
q
- the Query for which to release resources- Throws:
ObjectStoreException
- if something goes wrong
-
getUniqueInteger
public int getUniqueInteger(java.sql.Connection c) throws java.sql.SQLException
Return a unique integer from a SEQUENCE in the database.- Parameters:
c
- a Connection to use- Returns:
- an integer that is unique in this database
- Throws:
java.sql.SQLException
- 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 interfaceObjectStore
- Returns:
- an Integer
- Throws:
ObjectStoreException
- if a problem occurs
-
getSerialWithConnection
protected java.lang.Integer getSerialWithConnection(java.sql.Connection c) throws java.sql.SQLException
Gets an ID number which is unique in the database, given a Connection.- Parameters:
c
- the Connection- Returns:
- an Integer
- Throws:
java.sql.SQLException
- if a problem occurs
-
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
- Specified by:
getComponentsForQuery
in classObjectStoreAbstractImpl
- Parameters:
q
- a Query- Returns:
- a Set of objects
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-