Coverage Report - liquibase.sqlgenerator.core.AddAutoIncrementGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
AddAutoIncrementGenerator
77%
7/9
100%
10/10
2
 
 1  
 package liquibase.sqlgenerator.core;
 2  
 
 3  
 import liquibase.database.Database;
 4  
 import liquibase.database.typeconversion.TypeConverterFactory;
 5  
 import liquibase.database.core.DerbyDatabase;
 6  
 import liquibase.database.core.HsqlDatabase;
 7  
 import liquibase.database.core.MSSQLDatabase;
 8  
 import liquibase.database.core.H2Database;
 9  
 import liquibase.database.structure.Column;
 10  
 import liquibase.database.structure.Table;
 11  
 import liquibase.exception.ValidationErrors;
 12  
 import liquibase.sql.Sql;
 13  
 import liquibase.sql.UnparsedSql;
 14  
 import liquibase.sqlgenerator.SqlGenerator;
 15  
 import liquibase.sqlgenerator.SqlGeneratorChain;
 16  
 import liquibase.statement.core.AddAutoIncrementStatement;
 17  
 
 18  149
 public class AddAutoIncrementGenerator extends AbstractSqlGenerator<AddAutoIncrementStatement> {
 19  
 
 20  
     @Override
 21  
     public int getPriority() {
 22  10
         return PRIORITY_DEFAULT;
 23  
     }
 24  
 
 25  
     @Override
 26  
     public boolean supports(AddAutoIncrementStatement statement, Database database) {
 27  61
         return (database.supportsAutoIncrement() && !(database instanceof DerbyDatabase)
 28  
                 && !(database instanceof MSSQLDatabase) && !(database instanceof HsqlDatabase) && !(database instanceof H2Database));
 29  
     }
 30  
 
 31  
     public ValidationErrors validate(AddAutoIncrementStatement statement, Database database,
 32  
             SqlGeneratorChain sqlGeneratorChain) {
 33  20
         ValidationErrors validationErrors = new ValidationErrors();
 34  
 
 35  20
         validationErrors.checkRequiredField("columnName", statement.getColumnName());
 36  20
         validationErrors.checkRequiredField("tableName", statement.getTableName());
 37  
 
 38  20
         return validationErrors;
 39  
     }
 40  
 
 41  
     public Sql[] generateSql(AddAutoIncrementStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
 42  0
         String sql = "ALTER TABLE "
 43  
                 + database.escapeTableName(statement.getSchemaName(), statement.getTableName())
 44  
                 + " MODIFY "
 45  
                 + database.escapeColumnName(statement.getSchemaName(), statement.getTableName(),
 46  
                         statement.getColumnName())
 47  
                 + " "
 48  
                 + TypeConverterFactory.getInstance().findTypeConverter(database)
 49  
                         .getDataType(statement.getColumnDataType(), true) + " AUTO_INCREMENT";
 50  
 
 51  0
         return new Sql[] { new UnparsedSql(sql, new Column().setTable(
 52  
                 new Table(statement.getTableName()).setSchema(statement.getSchemaName())).setName(
 53  
                 statement.getColumnName())) };
 54  
     }
 55  
 }