Coverage Report - liquibase.sqlgenerator.SqlGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
SqlGenerator
N/A
N/A
1
 
 1  
 package liquibase.sqlgenerator;
 2  
 
 3  
 import liquibase.database.Database;
 4  
 import liquibase.exception.ValidationErrors;
 5  
 import liquibase.exception.Warnings;
 6  
 import liquibase.servicelocator.PrioritizedService;
 7  
 import liquibase.sql.Sql;
 8  
 import liquibase.statement.SqlStatement;
 9  
 
 10  
 /**
 11  
  * SqlGenerator implementations take a database-independent SqlStatement interface and create a database-specific Sql
 12  
  * object. SqlGenerators are registered with the SqlGeneratorFactory, which is used to determine the correct generator
 13  
  * to use for a given statment/database combination.
 14  
  * <p>
 15  
  * The SqlGenerator implementations are responsible for determining whether the data contained in the SqlStatement
 16  
  * method is valid using the validate method.
 17  
  * <p>
 18  
  * <b>Naming Conventions:</b><br>
 19  
  * Default SqlGenerators for a particular SqlStatement use the same name as the SqlStatement class, replacing
 20  
  * "Statement" with "Generator" (e.g.: CreateTableStatement -> CreateTableGenerator). Database-specific or alternate
 21  
  * SqlGenerators append a descrition of what makes them different appended (e.g. CreateTableStatement ->
 22  
  * CreateTableGeneratorOracle)
 23  
  * <p>
 24  
  * <b>NOTE:</b> There is only one instance of each SqlGenerator implementation created, and they must be thread safe.
 25  
  * <p>
 26  
  * <b>Lifecycle:</b><br>
 27  
  * <ol>
 28  
  * <li>Instance of SqlGenerator subclass is created when registered with SqlGeneratorFactory</li>
 29  
  * <li>For each SqlStatement to execute, SqlGeneratorFactory calls supports() to determine if the given SqlGenerator
 30  
  * will work for the current SqlStatement/Database combination</li>
 31  
  * <li>SqlGeneratorFactory calls getPriority to determine which of all the SqlGenerators that support a given
 32  
  * SqlStatement/Database combination is the best to use.</li>
 33  
  * <li>Liquibase calls validate() on the best SqlGenerator to determine if the data contained in the SqlStatement is
 34  
  * correct and complete for the given Database</li>
 35  
  * <li>If validate returns a no-error ValidationErrors object, Liquibase will call the generateSql() method and execute
 36  
  * the resuling SQL against the database.</li>
 37  
  * </ol>
 38  
  * 
 39  
  * @param <StatementType>
 40  
  *            Used to specify which type of SqlStatement this generator supports. If it supports multiple SqlStatement
 41  
  *            types, pass SqlStatement. The SqlGeneratorFactory will use this paramter to augment the response from the
 42  
  *            supports() method
 43  
  * 
 44  
  * @see SqlGeneratorFactory
 45  
  * @see liquibase.statement.SqlStatement
 46  
  * @see liquibase.sql.Sql
 47  
  */
 48  
 public interface SqlGenerator<StatementType extends SqlStatement> extends PrioritizedService {
 49  
 
 50  
     public static final int PRIORITY_DEFAULT = 1;
 51  
     public static final int PRIORITY_DATABASE = 5;
 52  
 
 53  
     /**
 54  
      * Of all the SqlGenerators that "support" a given SqlStatement/Database, SqlGeneratorFactory will return the one
 55  
      * with the highest priority.
 56  
      * 
 57  
      * @return
 58  
      */
 59  
     public int getPriority();
 60  
 
 61  
     /**
 62  
      * Does this generator support the given statement/database combination? Do not validate the statement with this
 63  
      * method, only return if it <i>can</i> suppot it.
 64  
      */
 65  
     public boolean supports(StatementType statement, Database database);
 66  
 
 67  
     /**
 68  
      * Does this change require access to the database metadata? If true, the change cannot be used in an
 69  
      * updateSql-style command.
 70  
      */
 71  
     public boolean requiresUpdatedDatabaseMetadata(Database database);
 72  
 
 73  
     /**
 74  
      * Validate the data contained in the SqlStatement. If there are no errors, return an empty ValidationErrors object,
 75  
      * not a null value. Liquibase will inspect the ValidationErrors result before attempting to call generateSql.
 76  
      */
 77  
     public ValidationErrors validate(StatementType statement, Database database, SqlGeneratorChain sqlGeneratorChain);
 78  
 
 79  
     public Warnings warn(StatementType statementType, Database database, SqlGeneratorChain sqlGeneratorChain);
 80  
 
 81  
     /**
 82  
      * Generate the actual Sql for the given statement and database.
 83  
      */
 84  
     public Sql[] generateSql(StatementType statement, Database database, SqlGeneratorChain sqlGeneratorChain);
 85  
 }