org.intermine.objectstore.intermine
Class ObjectStoreWriterInterMineImpl

java.lang.Object
  extended by org.intermine.objectstore.ObjectStoreAbstractImpl
      extended by org.intermine.objectstore.intermine.ObjectStoreInterMineImpl
          extended by org.intermine.objectstore.intermine.ObjectStoreWriterInterMineImpl
All Implemented Interfaces:
ObjectStore, ObjectStoreWriter, Shutdownable

public class ObjectStoreWriterInterMineImpl
extends ObjectStoreInterMineImpl
implements ObjectStoreWriter, Shutdownable

An SQL-backed implementation of the ObjectStoreWriter interface, backed by ObjectStoreInterMineImpl.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.intermine.objectstore.intermine.ObjectStoreInterMineImpl
ObjectStoreInterMineImpl.BagTableToRemove
 
Field Summary
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, maxTime, model, rand, sequenceKeys, sequenceNumber
 
Fields inherited from interface org.intermine.objectstore.ObjectStore
SEQUENCE_IGNORE
 
Constructor Summary
ObjectStoreWriterInterMineImpl(ObjectStore os)
          Constructor for this ObjectStoreWriter.
 
Method Summary
 void abortTransaction()
          Request that the ObjectStoreWriter aborts and closes the transaction
 void 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 connection
 void batchCommitTransaction()
          Request that the ObjectStoreWriter commits and closes the transaction and then opens a new one, without guaranteeing that the operation is finished before this method returns.
 void 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 transaction
protected  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 transaction
protected  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 produce
 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 delete(InterMineObject o)
          Delete an object from this ObjectStore
 void 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 ObjectStore
 java.util.List<ResultsRow<java.lang.Object>> execute(Query q, int start, int limit, boolean optimise, boolean explain, java.util.Map<java.lang.Object,java.lang.Integer> sequence)
          Execute a Query on this ObjectStore, asking for a certain range of rows to be returned.
 SingletonResults executeSingleton(Query q, int batchSize, boolean optimise, boolean explain, boolean prefetch)
          Execute a Query on this ObjectStore, returning a SingletonResults
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.sql.Connection getConnection()
          Returns a Connection.
 boolean getDisableResultsCache()
          Gets the disableResultsCache configuration option.
 java.io.Writer getLog()
          Returns the log used by this objctstore.
 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 transaction
protected  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 shutdown
 void 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, getComponentsForQuery, getDatabase, getInstance, getSchema, getSerial, getUniqueInteger, goFaster, goFasterWithConnection, internalGetObjectByIdWithConnection, isPrecomputed, isPrecomputedWithConnection, precompute, precompute, precompute, precompute, precomputeWithConnection, registerRequestId, registerStatement, releaseGoFaster, removeTempBagTable
 
Methods inherited from class org.intermine.objectstore.ObjectStoreAbstractImpl
cacheObjectById, changeSequence, checkStartLimit, createClob, createObjectStoreBag, getMaxLimit, getMaxOffset, getMaxTime, getModel, getModelFromClasspath, getObjectByExample, getObjectById, getObjectById, 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, 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 interface ObjectStore
Overrides:
getNewWriter in class ObjectStoreInterMineImpl
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 interface ObjectStore
Overrides:
execute in class ObjectStoreInterMineImpl
Parameters:
q - the Query to execute
batchSize - the batch size to initialise the Results object with
optimise - whether to optimise queries
explain - whether to explain queries
prefetch - whether to use the PrefetchManager
Returns:
the results of the Query

executeSingleton

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

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

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 class ObjectStoreInterMineImpl
Returns:
a boolean

getLog

public java.io.Writer getLog()
Returns the log used by this objctstore.

Overrides:
getLog in class ObjectStoreInterMineImpl
Returns:
the log

setLog

public void setLog(java.io.Writer log)
Not implemented.

Overrides:
setLog in class ObjectStoreInterMineImpl
Parameters:
log - ignored

setLogTableName

public void setLogTableName(java.lang.String tableName)
Not implemented.

Overrides:
setLogTableName in class ObjectStoreInterMineImpl
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 class ObjectStoreInterMineImpl
Parameters:
optimise - the number of milliseconds used to optimise the query
estimated - the estimated number of milliseconds required to run the query
execute - the number of milliseconds spent executing the query
permitted - an acceptable number of milliseconds for the query to take
convert - the number of milliseconds spent converting the results
q - the Query run
sql - the SQL string executed

setLogEverything

public void setLogEverything(boolean logEverything)
Sets the logEverything configuration option.

Overrides:
setLogEverything in class ObjectStoreInterMineImpl
Parameters:
logEverything - a boolean

getLogEverything

public boolean getLogEverything()
Gets the logEverything configuration option.

Overrides:
getLogEverything in class ObjectStoreInterMineImpl
Returns:
a boolean

setVerboseQueryLog

public void setVerboseQueryLog(boolean verboseQueryLog)
Sets the verboseQueryLog configuration option.

Overrides:
setVerboseQueryLog in class ObjectStoreInterMineImpl
Parameters:
verboseQueryLog - a boolean

getVerboseQueryLog

public boolean getVerboseQueryLog()
Gets the verboseQueryLog configuration option.

Overrides:
getVerboseQueryLog in class ObjectStoreInterMineImpl
Returns:
a boolean

setLogExplains

public void setLogExplains(boolean logExplains)
Sets the logExplains configuration option.

Overrides:
setLogExplains in class ObjectStoreInterMineImpl
Parameters:
logExplains - a boolean

getLogExplains

public boolean getLogExplains()
Gets the logExplains configuration option.

Overrides:
getLogExplains in class ObjectStoreInterMineImpl
Returns:
a boolean

setLogBeforeExecute

public void setLogBeforeExecute(boolean logBeforeExecute)
Sets the logBeforeExecute configuration option.

Overrides:
setLogBeforeExecute in class ObjectStoreInterMineImpl
Parameters:
logBeforeExecute - a boolean

getLogBeforeExecute

public boolean getLogBeforeExecute()
Gets the logBeforeExecute configuration option.

Overrides:
getLogBeforeExecute in class ObjectStoreInterMineImpl
Returns:
a boolean

setDisableResultsCache

public void setDisableResultsCache(boolean disableResultsCache)
Sets the disableResultsCache configuration option.

Overrides:
setDisableResultsCache in class ObjectStoreInterMineImpl
Parameters:
disableResultsCache - a boolean

getDisableResultsCache

public boolean getDisableResultsCache()
Gets the disableResultsCache configuration option.

Overrides:
getDisableResultsCache in class ObjectStoreInterMineImpl
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 class ObjectStoreInterMineImpl
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 class ObjectStoreInterMineImpl
Returns:
an int

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Returns a Connection. Please put them back.

Overrides:
getConnection in class ObjectStoreInterMineImpl
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 class ObjectStoreInterMineImpl
Parameters:
c - a Connection

doFinalise

protected void doFinalise()
Overrides Object.finalize - release the connection back to the objectstore.

Overrides:
doFinalise in class ObjectStoreInterMineImpl

close

public void close()
           throws ObjectStoreException
Closes this ObjectStore's DB log connection.

Specified by:
close in interface ObjectStoreWriter
Overrides:
close in class ObjectStoreInterMineImpl
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 interface ObjectStoreWriter
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 interface ObjectStoreWriter
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 Connection
o - 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 interface ObjectStoreWriter
Parameters:
hasId - the ID of the object that has the collection
clazz - the class of the object that has the collection
fieldName - the name of the collection
hadId - 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 Connection
hasId - the ID of the object that has the collection
clazz - the class of the object that has the collection
fieldName - the name of the collection
hadId - 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 IDs
o - 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 ID
java.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 connection
o - the object to transform
Throws:
ObjectStoreException - if something goes wrong
java.sql.SQLException - if something goes wrong
java.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 interface ObjectStoreWriter
Parameters:
osb - an ObjectStoreBag
element - an Integer to add to the bag
Throws:
ObjectStoreException - if an error occurs

addAllToBag

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

Specified by:
addAllToBag in interface ObjectStoreWriter
Parameters:
osb - an ObjectStoreBag
coll - 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 Connection
osb - an ObjectStoreBag
coll - 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 interface ObjectStoreWriter
Parameters:
osb - an ObjectStoreBag
element - an Integer to add to the bag
Throws:
ObjectStoreException - if an error occurs

removeAllFromBag

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

Specified by:
removeAllFromBag in interface ObjectStoreWriter
Parameters:
osb - an ObjectStoreBag
coll - 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 Connection
osb - an ObjectStoreBag
coll - 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 interface ObjectStoreWriter
Parameters:
osb - an ObjectStoreBag
query - 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 Connection
osb - an ObjectStoreBag
query - 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 interface ObjectStoreWriter
Parameters:
clob - the Clob to write to
text - 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 Connection
clob - the Clob to write to
text - 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 interface ObjectStoreWriter
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 Connection
o - 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 interface ObjectStoreWriter
Parameters:
qc - a QueryClass for the class of objects to delete
c - a Constraint based on the QueryClass to filter the objects to delete, or null to delete all objects
Throws:
ObjectStoreException - if an error occurs while deleting the objects

deleteWithConnection

public void deleteWithConnection(java.sql.Connection con,
                                 QueryClass qc,
                                 Constraint c)
                          throws ObjectStoreException
Performs a delete, with a connection.

Parameters:
con - the Connection
qc - the QueryClass in which to delete - note that this must currently be a Simple Object class
c - 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 interface ObjectStoreWriter
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 interface ObjectStoreWriter
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 interface ObjectStoreWriter
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 interface ObjectStoreWriter
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 interface ObjectStoreWriter
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> tablesAltered)
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 class ObjectStoreInterMineImpl
Parameters:
tablesAltered - 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 interface ObjectStore
Overrides:
getSequence in class ObjectStoreAbstractImpl
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 class ObjectStoreAbstractImpl
Parameters:
sequence - a Map representing a database state
q - the Query that is to be run
message - 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 from execute(Query q). This method is overridden in order to flush batches properly before the read.

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

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(). Entries are placed in the bagConstraintTables Map, which is a WeakHashMap from BagConstraint -> table name. When the BagConstraint is garbage- collected, or when the JVM exits, the table associated with the table name is dropped from the database. Delegates to the parent ObjectStore

Overrides:
generateSql in class ObjectStoreInterMineImpl
Parameters:
c - a Connection to use
q - the Query
start - 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 interface ObjectStore
Overrides:
count in class ObjectStoreInterMineImpl
Parameters:
q - InterMine Query on which to count rows
sequence - an object representing the state of the database corresponding to when the action that resulted in this execute was started. This number must match the ObjectStore's internal sequence number or a DataChangedException is thrown. The sequence number is incremented each time the data in the objectstore is changed
Returns:
the number of rows that will be produced by query
Throws:
ObjectStoreException - if an error occurs counting the query

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 class ObjectStoreInterMineImpl
Parameters:
id - the ID of the object to get
clazz - 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 interface Shutdownable
Overrides:
shutdown in class ObjectStoreInterMineImpl

isMultiConnection

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

Specified by:
isMultiConnection in interface ObjectStore
Overrides:
isMultiConnection in class ObjectStoreInterMineImpl
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 class ObjectStoreInterMineImpl
Parameters:
c - the Connection
Returns:
an Integer
Throws:
java.sql.SQLException - if an error occurs

toString

public java.lang.String toString()

Overrides:
toString in class ObjectStoreInterMineImpl