Class ObjectStoreWriterInterMineImpl
- java.lang.Object
-
- org.intermine.objectstore.ObjectStoreAbstractImpl
-
- org.intermine.objectstore.intermine.ObjectStoreInterMineImpl
-
- org.intermine.objectstore.intermine.ObjectStoreWriterInterMineImpl
-
- All Implemented Interfaces:
ObjectStore
,ObjectStoreWriter
,Shutdownable
public class ObjectStoreWriterInterMineImpl extends ObjectStoreInterMineImpl implements ObjectStoreWriter
An SQL-backed implementation of the ObjectStoreWriter interface, backed by ObjectStoreInterMineImpl.- Author:
- Matthew Wakeling, Andrew Varley
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.intermine.objectstore.intermine.ObjectStoreInterMineImpl
ObjectStoreInterMineImpl.BagTableToRemove
-
-
Field Summary
Fields Modifier and Type Field Description protected Batch
batch
protected java.lang.String
closeSituation
protected java.sql.Connection
conn
protected java.lang.String
connectionTakenBy
protected boolean
connInUse
protected java.lang.String
createSituation
protected ObjectStoreInterMineImpl
os
protected java.util.Map<java.lang.Integer,java.lang.Boolean>
recentSequences
protected java.util.Set<java.lang.Object>
tablesAltered
protected java.util.Map<java.lang.String,java.util.Set<CollectionDescriptor>>
tableToCollections
protected java.util.Map<java.lang.String,java.lang.String[]>
tableToColNameArray
protected java.util.Map<java.lang.String,org.intermine.objectstore.intermine.ObjectStoreWriterInterMineImpl.TableInfo>
tableToInfo
-
Fields inherited from class org.intermine.objectstore.intermine.ObjectStoreInterMineImpl
bagConstraintTables, BAGID_COLUMN, bagTablesInDatabase, bagTablesToRemove, BAGVAL_COLUMN, batchesCache, CACHE_LARGEST_OBJECT, CLOB_TABLE_NAME, CLOBID_COLUMN, CLOBPAGE_COLUMN, CLOBVAL_COLUMN, db, description, disableResultsCache, goFasterCacheMap, goFasterCountMap, goFasterMap, instances, INT_BAG_TABLE_NAME, limitedContext, log, logBeforeExecute, logEverything, logExplains, logTableBatch, logTableConnection, logTableName, minBagTableSize, resultsCache, schema, SEQUENCE_MULTIPLE, sequenceBase, sequenceOffset, singletonResultsCache, statsBagTableTime, statsConTime, statsEstTime, statsExeTime, statsGenTime, statsOptTime, UNIQUE_INTEGER_SEQUENCE_NAME, verboseQueryLog, 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 Constructor Description ObjectStoreWriterInterMineImpl(ObjectStore os)
Constructor for this ObjectStoreWriter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abortTransaction()
Request that the ObjectStoreWriter aborts and closes the transactionvoid
abortTransactionWithConnection(java.sql.Connection c)
Aborts a transaction.void
addAllToBag(ObjectStoreBag osb, java.util.Collection<java.lang.Integer> coll)
Adds a collection of elements to an ObjectStoreBag.protected void
addAllToBagWithConnection(java.sql.Connection c, ObjectStoreBag osb, java.util.Collection<java.lang.Integer> coll)
Adds elements to the given bag.void
addToBag(ObjectStoreBag osb, java.lang.Integer element)
Adds an element to an ObjectStoreBag.void
addToBagFromQuery(ObjectStoreBag osb, Query query)
Adds elements to an ObjectStoreBag from the results of a Query.protected void
addToBagFromQueryWithConnection(java.sql.Connection c, ObjectStoreBag osb, Query query)
Adds elements to a bag from the results of a query.void
addToCollection(java.lang.Integer hasId, java.lang.Class<?> clazz, java.lang.String fieldName, java.lang.Integer hadId)
Place an object in a many-to-many collection of another object.protected void
addToCollectionWithConnection(java.sql.Connection c, java.lang.Integer hasId, java.lang.Class<?> clazz, java.lang.String fieldName, java.lang.Integer hadId)
Performs addToCollection with given connectionvoid
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
batchCommitTransactionWithConnection(java.sql.Connection c)
Commits a transaction and opens a new one, without guaranteeing the operation is finished before this method returns.void
beginTransaction()
Request that the ObjectStoreWriter begins a transactionprotected void
beginTransactionWithConnection(java.sql.Connection c)
Begins a transaction.void
checkSequence(java.util.Map<java.lang.Object,java.lang.Integer> sequence, Query q, java.lang.String message)
Checks a number against the sequence number, and throws an exception if they do not match.void
close()
Closes this ObjectStore's DB log connection.void
commitTransaction()
Request that the ObjectStoreWriter commits and closes the transactionprotected void
commitTransactionWithConnection(java.sql.Connection c)
Commits a transaction.int
count(Query q, java.util.Map<java.lang.Object,java.lang.Integer> sequence)
Counts the number of rows the query will producevoid
databaseAltered(java.util.Set<java.lang.Object> tablesChanged)
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
delete(InterMineObject o)
Delete an object from this ObjectStorevoid
delete(QueryClass qc, Constraint c)
Deletes a set of objects from this ObjectStore.protected void
deleteWithConnection(java.sql.Connection c, InterMineObject o)
Performs a delete, with a connection.void
deleteWithConnection(java.sql.Connection con, QueryClass qc, Constraint c)
Performs a delete, with a connection.protected void
doFinalise()
Overrides Object.finalize - release the connection back to the objectstore.boolean
everOptimise()
Returns whether optimisation should be permitted.Results
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, int batchSize, boolean optimise, boolean explain, boolean prefetch)
Execute a Query on this ObjectStore, returning a SingletonResultsprotected 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.sql.Connection
getConnection()
Returns a Connection.boolean
getDisableResultsCache()
Gets the disableResultsCache configuration option.java.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.ObjectStore
getObjectStore()
Retrieve this Writer's ObjectStore.java.util.Map<java.lang.Object,java.lang.Integer>
getSequence(java.util.Set<java.lang.Object> tables)
Returns an object representing the current state of the database, for fail-fast concurrency control.protected java.lang.Integer
getSerialWithConnection(java.sql.Connection c)
Overrides, in order to store recentSequences.protected org.intermine.objectstore.intermine.ObjectStoreWriterInterMineImpl.TableInfo
getTableInfo(ClassDescriptor tableMaster)
Produces metadata for a given table, caching it to save time.boolean
getVerboseQueryLog()
Gets the verboseQueryLog configuration option.protected InterMineObject
internalGetObjectById(java.lang.Integer id, java.lang.Class<? extends InterMineObject> clazz)
Internal service method for getObjectById.boolean
isInTransaction()
Check whether the ObjectStoreWriter is performing a transactionprotected boolean
isInTransactionWithConnection(java.sql.Connection c)
Finds if we are in a transaction.boolean
isMultiConnection()
Return whether or not this ObjectStore gives a performance improvement when multiple simultaneous are made.protected boolean
populateIds(java.sql.Connection c, InterMineObject o)
Populates the object o with IDs.void
releaseConnection(java.sql.Connection c)
Allows one to put a connection back.void
removeAllFromBag(ObjectStoreBag osb, java.util.Collection<java.lang.Integer> coll)
Removes a collection of elements from an ObjectStoreBag.protected void
removeAllFromBagWithConnection(java.sql.Connection c, ObjectStoreBag osb, java.util.Collection<java.lang.Integer> coll)
Removes elements from the given bag.void
removeFromBag(ObjectStoreBag osb, java.lang.Integer element)
Removes an element from an ObjectStoreBag.void
replaceClob(Clob clob, java.lang.String text)
Replaces the contents of the given Clob with the given String.void
replaceClobWithConnection(java.sql.Connection c, Clob clob, java.lang.String text)
Replaces the contents of the given Clob with the given String.void
setBatchWriter(BatchWriter batchWriter)
Allows the changing of the BatchWriter that this ObjectStoreWriter uses.void
setDisableResultsCache(boolean disableResultsCache)
Sets the disableResultsCache configuration option.void
setLog(java.io.Writer log)
Not implemented.void
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)
Not implemented.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 StatsShutdownHook on shutdownvoid
store(java.lang.Object o)
Store an object in this ObjectStore.protected void
storeWithConnection(java.sql.Connection c, java.lang.Object o)
Performs store with a given Connection.java.lang.String
toString()
protected void
writePendingClobs(java.sql.Connection c, java.lang.Object o)
Writes the contents of any pending Clobs to the database, and replaces them in the objects with a real ClobAccess object.-
Methods inherited from class org.intermine.objectstore.intermine.ObjectStoreInterMineImpl
cancelRequest, countWithConnection, createTempBagTable, createTempBagTable, createTempBagTable, createTempBagTables, deregisterRequestId, deregisterStatement, estimate, estimateWithConnection, execute, executeSingleton, executeWithConnection, executeWithConnection, finalize, flushLogTable, flushObjectById, flushOldTempBagTables, generateSql, generateSqlForCount, getComponentsForQuery, getDatabase, getInstance, getSchema, getSerial, getUniqueInteger, goFaster, goFasterWithConnection, internalGetObjectByIdWithConnection, isPrecomputed, isPrecomputedWithConnection, performUnsafeOperation, precompute, precompute, precompute, precompute, precomputeWithConnection, registerRequestId, registerStatement, releaseGoFaster, removeTempBagTable
-
Methods inherited from class org.intermine.objectstore.ObjectStoreAbstractImpl
cacheObjectById, changeSequence, checkStartLimit, createClob, createObjectStoreBag, getMaxLimit, getMaxOffset, getMaxQueryParseTime, getMaxTime, getModel, getModelFromClasspath, getObjectByExample, getObjectById, getObjectById, getObjectsByExample, getObjectsByIds, invalidateObjectById, pilferObjectById, prefetchObjectById
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.intermine.objectstore.ObjectStore
cacheObjectById, createClob, createObjectStoreBag, estimate, execute, executeSingleton, flushObjectById, getComponentsForQuery, getMaxLimit, getMaxOffset, getMaxTime, getModel, getObjectByExample, getObjectById, getObjectById, getObjectsByExample, getObjectsByIds, getSerial, invalidateObjectById, pilferObjectById, prefetchObjectById
-
-
-
-
Field Detail
-
conn
protected java.sql.Connection conn
-
connInUse
protected boolean connInUse
-
os
protected ObjectStoreInterMineImpl os
-
batch
protected Batch batch
-
createSituation
protected java.lang.String createSituation
-
closeSituation
protected java.lang.String closeSituation
-
recentSequences
protected java.util.Map<java.lang.Integer,java.lang.Boolean> recentSequences
-
tableToInfo
protected java.util.Map<java.lang.String,org.intermine.objectstore.intermine.ObjectStoreWriterInterMineImpl.TableInfo> tableToInfo
-
tableToColNameArray
protected java.util.Map<java.lang.String,java.lang.String[]> tableToColNameArray
-
tableToCollections
protected java.util.Map<java.lang.String,java.util.Set<CollectionDescriptor>> tableToCollections
-
connectionTakenBy
protected java.lang.String connectionTakenBy
-
tablesAltered
protected java.util.Set<java.lang.Object> tablesAltered
-
-
Constructor Detail
-
ObjectStoreWriterInterMineImpl
public ObjectStoreWriterInterMineImpl(ObjectStore os) throws ObjectStoreException
Constructor for this ObjectStoreWriter. This ObjectStoreWriter is bound to a single SQL Connection, grabbed from the provided ObjectStore.- Parameters:
os
- an ObjectStoreInterMineImpl- Throws:
ObjectStoreException
- if a problem occurs
-
-
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 classObjectStoreInterMineImpl
- Returns:
- an ObjectStoreWriter
- Throws:
ObjectStoreException
- if an error occurs
-
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 classObjectStoreInterMineImpl
- 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, 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 classObjectStoreInterMineImpl
- 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
-
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.- Overrides:
everOptimise
in classObjectStoreInterMineImpl
- Returns:
- a boolean
-
getLog
public java.io.Writer getLog()
Returns the log used by this objectstore.- Overrides:
getLog
in classObjectStoreInterMineImpl
- Returns:
- the log
-
setLog
public void setLog(java.io.Writer log)
Not implemented.- Overrides:
setLog
in classObjectStoreInterMineImpl
- Parameters:
log
- ignored
-
setLogTableName
public void setLogTableName(java.lang.String tableName)
Not implemented.- Overrides:
setLogTableName
in classObjectStoreInterMineImpl
- Parameters:
tableName
- ignored
-
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.- Overrides:
dbLog
in classObjectStoreInterMineImpl
- 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
-
setLogEverything
public void setLogEverything(boolean logEverything)
Sets the logEverything configuration option.- Overrides:
setLogEverything
in classObjectStoreInterMineImpl
- Parameters:
logEverything
- a boolean
-
getLogEverything
public boolean getLogEverything()
Gets the logEverything configuration option.- Overrides:
getLogEverything
in classObjectStoreInterMineImpl
- Returns:
- a boolean
-
setVerboseQueryLog
public void setVerboseQueryLog(boolean verboseQueryLog)
Sets the verboseQueryLog configuration option.- Overrides:
setVerboseQueryLog
in classObjectStoreInterMineImpl
- Parameters:
verboseQueryLog
- a boolean
-
getVerboseQueryLog
public boolean getVerboseQueryLog()
Gets the verboseQueryLog configuration option.- Overrides:
getVerboseQueryLog
in classObjectStoreInterMineImpl
- Returns:
- a boolean
-
setLogExplains
public void setLogExplains(boolean logExplains)
Sets the logExplains configuration option.- Overrides:
setLogExplains
in classObjectStoreInterMineImpl
- Parameters:
logExplains
- a boolean
-
getLogExplains
public boolean getLogExplains()
Gets the logExplains configuration option.- Overrides:
getLogExplains
in classObjectStoreInterMineImpl
- Returns:
- a boolean
-
setLogBeforeExecute
public void setLogBeforeExecute(boolean logBeforeExecute)
Sets the logBeforeExecute configuration option.- Overrides:
setLogBeforeExecute
in classObjectStoreInterMineImpl
- Parameters:
logBeforeExecute
- a boolean
-
getLogBeforeExecute
public boolean getLogBeforeExecute()
Gets the logBeforeExecute configuration option.- Overrides:
getLogBeforeExecute
in classObjectStoreInterMineImpl
- Returns:
- a boolean
-
setDisableResultsCache
public void setDisableResultsCache(boolean disableResultsCache)
Sets the disableResultsCache configuration option.- Overrides:
setDisableResultsCache
in classObjectStoreInterMineImpl
- Parameters:
disableResultsCache
- a boolean
-
getDisableResultsCache
public boolean getDisableResultsCache()
Gets the disableResultsCache configuration option.- Overrides:
getDisableResultsCache
in classObjectStoreInterMineImpl
- Returns:
- a boolean
-
setBatchWriter
public void setBatchWriter(BatchWriter batchWriter) throws ObjectStoreException
Allows the changing of the BatchWriter that this ObjectStoreWriter uses.- Parameters:
batchWriter
- the new BatchWriter - use BatchWriterSimpleImpl for writers likely to see small batches, and optimised (eg BatchWriterPostgresCopyImpl) implementations for bulk-write writers.- Throws:
ObjectStoreException
- if something goes wrong
-
setMinBagTableSize
public void setMinBagTableSize(int minBagTableSize)
Set the cutoff value used to decide if a bag should be put in a table.- Overrides:
setMinBagTableSize
in classObjectStoreInterMineImpl
- 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.- Overrides:
getMinBagTableSize
in classObjectStoreInterMineImpl
- Returns:
- an int
-
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!- Overrides:
getConnection
in classObjectStoreInterMineImpl
- Returns:
- a java.sql.Connection
- Throws:
java.sql.SQLException
- if there is a problem with that
-
releaseConnection
public void releaseConnection(java.sql.Connection c)
Allows one to put a connection back.- Overrides:
releaseConnection
in classObjectStoreInterMineImpl
- Parameters:
c
- a Connection
-
doFinalise
protected void doFinalise()
Overrides Object.finalize - release the connection back to the objectstore.- Overrides:
doFinalise
in classObjectStoreInterMineImpl
-
close
public void close() throws ObjectStoreException
Closes this ObjectStore's DB log connection.- Specified by:
close
in interfaceObjectStoreWriter
- Overrides:
close
in classObjectStoreInterMineImpl
- Throws:
ObjectStoreException
- in subclasses
-
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 interfaceObjectStoreWriter
- Returns:
- the ObjectStore
-
store
public void store(java.lang.Object o) throws ObjectStoreException
Store an object in this ObjectStore. If the ID of this object is not set, it will be set to a previously unused value. If the ID matches the ID of an object already in the objectstore, then an update operation is performed - otherwise a store operation is performed.
Attributes and references of the stored object will be set to those of the provided object. Collections of the stored object will contain the union of the contents of any pre-existing stored object, and the contents of the provided object. There is currently no way to remove entries from a collection of a stored object.
Any objects referred to by this object will have their ID set in a similar way to this object. This object will be stored with references and collections using those IDs, however those objects will not be stored themselves. Therefore, the objectstore will be inconsistent until those objects are also stored.
If bidirectional relationships are not consistent in the objects being stored, then the behaviour of the store method is not defined. Specifically, one-to-one relationships must be stored on both sides. For example, if A has a relationship with B1 in the database, and we store a new A that has a relationship with B2, then we must also store B2 with a relationship back to A (to complete the relationship), and store B1 (to completely break the old relationship),- Specified by:
store
in interfaceObjectStoreWriter
- Parameters:
o
- the object to store- Throws:
ObjectStoreException
- if an error occurs during storage of the object
-
storeWithConnection
protected void storeWithConnection(java.sql.Connection c, java.lang.Object o) throws ObjectStoreException
Performs store with a given Connection.- Parameters:
c
- the Connectiono
- the object to store- Throws:
ObjectStoreException
- sometimes
-
addToCollection
public void addToCollection(java.lang.Integer hasId, java.lang.Class<?> clazz, java.lang.String fieldName, java.lang.Integer hadId) throws ObjectStoreException
Place an object in a many-to-many collection of another object. This method provides a way to place an object into a collection in another object without having either object loaded in memory. Only the IDs of the two objects are required, along with the name of the collection.- Specified by:
addToCollection
in interfaceObjectStoreWriter
- Parameters:
hasId
- the ID of the object that has the collectionclazz
- the class of the object that has the collectionfieldName
- the name of the collectionhadId
- the ID of the object to place in the collection- Throws:
ObjectStoreException
- if a problem occurs
-
addToCollectionWithConnection
protected void addToCollectionWithConnection(java.sql.Connection c, java.lang.Integer hasId, java.lang.Class<?> clazz, java.lang.String fieldName, java.lang.Integer hadId) throws ObjectStoreException
Performs addToCollection with given connection- Parameters:
c
- the ConnectionhasId
- the ID of the object that has the collectionclazz
- the class of the object that has the collectionfieldName
- the name of the collectionhadId
- the ID of the object to place in the collection- Throws:
ObjectStoreException
- if an error occurs
-
getTableInfo
protected org.intermine.objectstore.intermine.ObjectStoreWriterInterMineImpl.TableInfo getTableInfo(ClassDescriptor tableMaster) throws ObjectStoreException
Produces metadata for a given table, caching it to save time.- Parameters:
tableMaster
- the ClassDescriptor describing the table- Returns:
- a TableInfo object
- Throws:
ObjectStoreException
- if something goes wrong
-
populateIds
protected boolean populateIds(java.sql.Connection c, InterMineObject o) throws java.sql.SQLException, java.lang.IllegalAccessException
Populates the object o with IDs.- Parameters:
c
- a Connection with which to fetch more IDso
- the InterMineObject- Returns:
- true if the object will need to be deleted from the DB before a store
- Throws:
java.sql.SQLException
- if the database cannot produce a new IDjava.lang.IllegalAccessException
- if the ID field cannot be set
-
writePendingClobs
protected void writePendingClobs(java.sql.Connection c, java.lang.Object o) throws ObjectStoreException, java.sql.SQLException, java.lang.IllegalAccessException
Writes the contents of any pending Clobs to the database, and replaces them in the objects with a real ClobAccess object.- Parameters:
c
- a connectiono
- the object to transform- Throws:
ObjectStoreException
- if something goes wrongjava.sql.SQLException
- if something goes wrongjava.lang.IllegalAccessException
- if something goes wrong
-
addToBag
public void addToBag(ObjectStoreBag osb, java.lang.Integer element) throws ObjectStoreException
Adds an element to an ObjectStoreBag.- Specified by:
addToBag
in interfaceObjectStoreWriter
- Parameters:
osb
- an ObjectStoreBagelement
- 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.- Specified by:
addAllToBag
in interfaceObjectStoreWriter
- Parameters:
osb
- an ObjectStoreBagcoll
- a Collection of Integers- Throws:
ObjectStoreException
- if an error occurs
-
addAllToBagWithConnection
protected void addAllToBagWithConnection(java.sql.Connection c, ObjectStoreBag osb, java.util.Collection<java.lang.Integer> coll) throws ObjectStoreException
Adds elements to the given bag.- Parameters:
c
- a Connectionosb
- an ObjectStoreBagcoll
- a Collection of Integers- Throws:
ObjectStoreException
- if there is an error in the underlying database
-
removeFromBag
public void removeFromBag(ObjectStoreBag osb, java.lang.Integer element) throws ObjectStoreException
Removes an element from an ObjectStoreBag.- Specified by:
removeFromBag
in interfaceObjectStoreWriter
- Parameters:
osb
- an ObjectStoreBagelement
- 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.- Specified by:
removeAllFromBag
in interfaceObjectStoreWriter
- Parameters:
osb
- an ObjectStoreBagcoll
- a Collection of Integers- Throws:
ObjectStoreException
- if an error occurs
-
removeAllFromBagWithConnection
protected void removeAllFromBagWithConnection(java.sql.Connection c, ObjectStoreBag osb, java.util.Collection<java.lang.Integer> coll) throws ObjectStoreException
Removes elements from the given bag.- Parameters:
c
- a Connectionosb
- an ObjectStoreBagcoll
- a Collection of Integers- Throws:
ObjectStoreException
- if there is an error in the underlying database
-
addToBagFromQuery
public void addToBagFromQuery(ObjectStoreBag osb, Query query) throws ObjectStoreException
Adds elements to an ObjectStoreBag from the results of a Query. The data may not be loaded into Java, so this is a performance improvement method. For example, in SQL this method may issue a command like "INSERT INTO bag SELECT ...".- Specified by:
addToBagFromQuery
in interfaceObjectStoreWriter
- Parameters:
osb
- an ObjectStoreBagquery
- an objectstore Query, which contains only one result column, which is a suitable type for insertion into the given bag- Throws:
ObjectStoreException
- if something goes wrong
-
addToBagFromQueryWithConnection
protected void addToBagFromQueryWithConnection(java.sql.Connection c, ObjectStoreBag osb, Query query) throws ObjectStoreException
Adds elements to a bag from the results of a query.- Parameters:
c
- a Connectionosb
- an ObjectStoreBagquery
- a Query with only one column- Throws:
ObjectStoreException
- if there is an error in the underlying database
-
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 interfaceObjectStoreWriter
- Parameters:
clob
- the Clob to write totext
- the text to write to the Clob- Throws:
ObjectStoreException
- if something goes wrong
-
replaceClobWithConnection
public void replaceClobWithConnection(java.sql.Connection c, Clob clob, java.lang.String text) throws ObjectStoreException
Replaces the contents of the given Clob with the given String.- Parameters:
c
- a Connectionclob
- the Clob to write totext
- the text to write to the Clob- Throws:
ObjectStoreException
- if something goes wrong
-
delete
public void delete(InterMineObject o) throws ObjectStoreException
Delete an object from this ObjectStore- Specified by:
delete
in interfaceObjectStoreWriter
- Parameters:
o
- the object to delete- Throws:
ObjectStoreException
- if an error occurs during deletion of the object
-
deleteWithConnection
protected void deleteWithConnection(java.sql.Connection c, InterMineObject o) throws ObjectStoreException
Performs a delete, with a connection.- Parameters:
c
- the Connectiono
- the object to delete- Throws:
ObjectStoreException
- sometimes
-
delete
public void delete(QueryClass qc, Constraint c) throws ObjectStoreException
Deletes a set of objects from this ObjectStore.- Specified by:
delete
in interfaceObjectStoreWriter
- Parameters:
qc
- a QueryClass for the class of objects to delete. The class given in the query class must not inherit from org.intermine.model.InterMineObject.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
-
deleteWithConnection
public void deleteWithConnection(java.sql.Connection con, QueryClass qc, Constraint c) throws ObjectStoreException
Performs a delete, with a connection.- Parameters:
con
- the Connectionqc
- the QueryClass in which to delete - note that this must currently be a Simple Object classc
- the Constraint to limit the deletes, or null to delete everything- Throws:
ObjectStoreException
- if something goes wrong
-
isInTransaction
public boolean isInTransaction() throws ObjectStoreException
Check whether the ObjectStoreWriter is performing a transaction- Specified by:
isInTransaction
in interfaceObjectStoreWriter
- Returns:
- true if in a transaction, false otherwise
- Throws:
ObjectStoreException
- if an error occurs
-
isInTransactionWithConnection
protected boolean isInTransactionWithConnection(java.sql.Connection c) throws ObjectStoreException
Finds if we are in a transaction.- Parameters:
c
- the Connection- Returns:
- true or false
- Throws:
ObjectStoreException
- sometimes
-
beginTransaction
public void beginTransaction() throws ObjectStoreException
Request that the ObjectStoreWriter begins a transaction- Specified by:
beginTransaction
in interfaceObjectStoreWriter
- Throws:
ObjectStoreException
- if a transaction is in progress, or is aborted
-
beginTransactionWithConnection
protected void beginTransactionWithConnection(java.sql.Connection c) throws ObjectStoreException
Begins a transaction.- Parameters:
c
- the Connection- Throws:
ObjectStoreException
- if we are already in a transaction
-
commitTransaction
public void commitTransaction() throws ObjectStoreException
Request that the ObjectStoreWriter commits and closes the transaction- Specified by:
commitTransaction
in interfaceObjectStoreWriter
- Throws:
ObjectStoreException
- if a transaction is not in progress, or is aborted
-
commitTransactionWithConnection
protected void commitTransactionWithConnection(java.sql.Connection c) throws ObjectStoreException
Commits a transaction.- Parameters:
c
- the Connection- Throws:
ObjectStoreException
- if we are not in a transaction
-
abortTransaction
public void abortTransaction() throws ObjectStoreException
Request that the ObjectStoreWriter aborts and closes the transaction- Specified by:
abortTransaction
in interfaceObjectStoreWriter
- Throws:
ObjectStoreException
- if a transaction is not in progress
-
abortTransactionWithConnection
public void abortTransactionWithConnection(java.sql.Connection c) throws ObjectStoreException
Aborts a transaction.- Parameters:
c
- the Connection- Throws:
ObjectStoreException
- if we are not in a transaction
-
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 interfaceObjectStoreWriter
- Throws:
ObjectStoreException
- if an error occurs
-
batchCommitTransactionWithConnection
public void batchCommitTransactionWithConnection(java.sql.Connection c) throws ObjectStoreException
Commits a transaction and opens a new one, without guaranteeing the operation is finished before this method returns.- Parameters:
c
- the Connection- Throws:
ObjectStoreException
- if an error occurs
-
databaseAltered
public void databaseAltered(java.util.Set<java.lang.Object> tablesChanged)
Internal method called by the ObjectStoreWriter, to notify the ObjectStore that some of the data in the database has changed. This method should never be called on an ObjectStoreWriter.- Overrides:
databaseAltered
in classObjectStoreInterMineImpl
- Parameters:
tablesChanged
- a Set of table names that may have been altered
-
getSequence
public java.util.Map<java.lang.Object,java.lang.Integer> getSequence(java.util.Set<java.lang.Object> tables)
Returns an object representing the current state of the database, for fail-fast concurrency control. Delegate to the parent ObjectStore.- Specified by:
getSequence
in interfaceObjectStore
- Overrides:
getSequence
in classObjectStoreAbstractImpl
- Parameters:
tables
- a Set of objects representing independent components of the database- Returns:
- a Map containing sequence data
-
checkSequence
public void checkSequence(java.util.Map<java.lang.Object,java.lang.Integer> sequence, Query q, java.lang.String message) throws DataChangedException
Checks a number against the sequence number, and throws an exception if they do not match. Delegate to the parent ObjectStore.- Overrides:
checkSequence
in classObjectStoreAbstractImpl
- Parameters:
sequence
- a Map representing a database stateq
- the Query that is to be runmessage
- some description of the operation that is about to happen- Throws:
DataChangedException
- if the sequence numbers do not match
-
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)
. This method is overridden in order to flush batches properly before the read.- Specified by:
execute
in interfaceObjectStore
- Overrides:
execute
in classObjectStoreInterMineImpl
- 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
-
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(). Delegates to the parent ObjectStore- Overrides:
generateSql
in classObjectStoreInterMineImpl
- 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
-
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 This method is overridden in order to flush batches properly before the read.- Specified by:
count
in interfaceObjectStore
- Overrides:
count
in classObjectStoreInterMineImpl
- 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
-
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. This method is overridden in order to flush matches properly before the read.- Overrides:
internalGetObjectById
in classObjectStoreInterMineImpl
- 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
-
shutdown
public void shutdown()
Called by the StatsShutdownHook on shutdown- Specified by:
shutdown
in interfaceShutdownable
- Overrides:
shutdown
in classObjectStoreInterMineImpl
-
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
- Overrides:
isMultiConnection
in classObjectStoreInterMineImpl
- Returns:
- true if one should do multiple simultaneous operations
-
getSerialWithConnection
protected java.lang.Integer getSerialWithConnection(java.sql.Connection c) throws java.sql.SQLException
Overrides, in order to store recentSequences.- Overrides:
getSerialWithConnection
in classObjectStoreInterMineImpl
- Parameters:
c
- the Connection- Returns:
- an Integer
- Throws:
java.sql.SQLException
- if an error occurs
-
toString
public java.lang.String toString()
- Overrides:
toString
in classObjectStoreInterMineImpl
-
-