Package org.intermine.task
Class CreateIndexesTask
- java.lang.Object
-
- org.apache.tools.ant.ProjectComponent
-
- org.apache.tools.ant.Task
-
- org.intermine.task.CreateIndexesTask
-
public class CreateIndexesTask extends org.apache.tools.ant.Task
Task to create indexes on a database holding objects conforming to a given model by reading that model's primary key configuration information. By default three types of index are created: for the specified primary key fields, for all N-1 relations, and for the indirection table columns of M-N relations. Alternatively, if attributeIndexes is true, indexes are created for all non-primary key attributes instead. Note that all "id" columns are indexed automatically by virtue of InterMineTorqueModelOuput specifying them as primary key columns.- Author:
- Mark Woodbridge, Kim Rutherford
-
-
Constructor Summary
Constructors Constructor Description CreateIndexesTask()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
createIndex(java.sql.Connection conn, java.lang.String indexName, org.intermine.task.IndexStatement indexStatement, int threadNo)
Create an named index on the specified columns of a table.protected void
dropIndex(java.lang.String indexName, int threadNo)
Drop an index by name, ignoring any resulting errorsvoid
execute()
protected void
execute(java.sql.Connection conn, java.lang.String sql)
Execute an sql statement.protected void
getAttributeIndexStatements(ClassDescriptor cld, java.util.Map<java.lang.String,org.intermine.task.IndexStatement> statements)
Add indexes for all fields to the relevant tables for a given ClassDescriptor.protected void
getStandardIndexStatements(ClassDescriptor cld, java.util.Map<java.lang.String,org.intermine.task.IndexStatement> statements)
Add indexes for primary keys, indirection tables and 1-N relations to the relevant tables for a given ClassDescriptorvoid
setAlias(java.lang.String alias)
Set the ObjectStore alias.void
setAttributeIndexes(boolean attributeIndexes)
Set the attributeIndexes flag.void
setExtraThreads(int extraThreads)
Set the number of extra worker threads.void
setObjectStore(ObjectStore objectStore)
Set the ObjectStore to use.void
setUp()
Sets up the instance variables-
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
-
-
-
-
Method Detail
-
setAlias
public void setAlias(java.lang.String alias)
Set the ObjectStore alias. Currently the ObjectStore must be an ObjectStoreInterMineImpl.- Parameters:
alias
- the ObjectStore alias
-
setObjectStore
public void setObjectStore(ObjectStore objectStore)
Set the ObjectStore to use. Can be set instead of alias.- Parameters:
objectStore
- ObjectStore to create indexes on
-
setAttributeIndexes
public void setAttributeIndexes(boolean attributeIndexes)
Set the attributeIndexes flag. Index the attributes that are not part of the primary key if and only if the flag is set.- Parameters:
attributeIndexes
- flag for attribute indexes
-
setExtraThreads
public void setExtraThreads(int extraThreads)
Set the number of extra worker threads. If the database server is multi-CPU, it might help to have multiple threads hitting it.- Parameters:
extraThreads
- number of extra threads apart from the main thread
-
setUp
public void setUp()
Sets up the instance variables- Throws:
org.apache.tools.ant.BuildException
- if something is wrong
-
execute
public void execute()
- Overrides:
execute
in classorg.apache.tools.ant.Task
-
getStandardIndexStatements
protected void getStandardIndexStatements(ClassDescriptor cld, java.util.Map<java.lang.String,org.intermine.task.IndexStatement> statements) throws MetaDataException
Add indexes for primary keys, indirection tables and 1-N relations to the relevant tables for a given ClassDescriptor- Parameters:
cld
- the ClassDescriptorstatements
- the index creation statements for the given cld are added to this Map. The key is the index name, the value is a IndexStatement.- Throws:
MetaDataException
- if a field os not found in model
-
getAttributeIndexStatements
protected void getAttributeIndexStatements(ClassDescriptor cld, java.util.Map<java.lang.String,org.intermine.task.IndexStatement> statements)
Add indexes for all fields to the relevant tables for a given ClassDescriptor. Skip those fields that have indexes created by createStandardIndexes().- Parameters:
cld
- the ClassDescriptorstatements
- the index creation statements for the given cld are added to this Map. The key is the index name, the value is a IndexStatement.
-
dropIndex
protected void dropIndex(java.lang.String indexName, int threadNo)
Drop an index by name, ignoring any resulting errors- Parameters:
indexName
- the index namethreadNo
- the thread number included for logging
-
createIndex
protected void createIndex(java.sql.Connection conn, java.lang.String indexName, org.intermine.task.IndexStatement indexStatement, int threadNo)
Create an named index on the specified columns of a table.- Parameters:
conn
- a ConnectionindexName
- the index nameindexStatement
- the IndexStatementthreadNo
- the number of the calling thread
-
execute
protected void execute(java.sql.Connection conn, java.lang.String sql) throws java.sql.SQLException
Execute an sql statement.- Parameters:
conn
- a Connectionsql
- the sql string for the statement to execute- Throws:
java.sql.SQLException
- if an error occurs
-
-