Class 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
    • Field Summary

      • Fields inherited from class org.apache.tools.ant.Task

        description, location, target, taskName, taskType, wrapper
      • Fields inherited from class org.apache.tools.ant.ProjectComponent

        project
    • 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 errors
      void 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 ClassDescriptor
      void 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
      • Methods inherited from class org.apache.tools.ant.ProjectComponent

        getProject, setProject
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CreateIndexesTask

        public CreateIndexesTask()
    • 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 class org.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 ClassDescriptor
        statements - 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 ClassDescriptor
        statements - 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 name
        threadNo - 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 Connection
        indexName - the index name
        indexStatement - the IndexStatement
        threadNo - 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 Connection
        sql - the sql string for the statement to execute
        Throws:
        java.sql.SQLException - if an error occurs