Coverage Report - liquibase.sqlgenerator.core.DropUniqueConstraintGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
DropUniqueConstraintGenerator
33%
5/15
10%
1/10
2.333
 
 1  
 package liquibase.sqlgenerator.core;
 2  
 
 3  
 import liquibase.database.Database;
 4  
 import liquibase.database.core.MaxDBDatabase;
 5  
 import liquibase.database.core.MySQLDatabase;
 6  
 import liquibase.database.core.OracleDatabase;
 7  
 import liquibase.database.core.SQLiteDatabase;
 8  
 import liquibase.database.core.SybaseASADatabase;
 9  
 import liquibase.exception.ValidationErrors;
 10  
 import liquibase.sql.Sql;
 11  
 import liquibase.sql.UnparsedSql;
 12  
 import liquibase.sqlgenerator.SqlGeneratorChain;
 13  
 import liquibase.statement.core.DropUniqueConstraintStatement;
 14  
 
 15  86
 public class DropUniqueConstraintGenerator extends AbstractSqlGenerator<DropUniqueConstraintStatement> {
 16  
 
 17  
     @Override
 18  
     public boolean supports(DropUniqueConstraintStatement statement, Database database) {
 19  61
         return !(database instanceof SQLiteDatabase);
 20  
     }
 21  
 
 22  
     @Override
 23  
     public ValidationErrors validate(DropUniqueConstraintStatement dropUniqueConstraintStatement, Database database,
 24  
             SqlGeneratorChain sqlGeneratorChain) {
 25  15
         ValidationErrors validationErrors = new ValidationErrors();
 26  15
         validationErrors.checkRequiredField("tableName", dropUniqueConstraintStatement.getTableName());
 27  15
         return validationErrors;
 28  
     }
 29  
 
 30  
     @Override
 31  
     public Sql[] generateSql(DropUniqueConstraintStatement statement, Database database,
 32  
             SqlGeneratorChain sqlGeneratorChain) {
 33  
         String sql;
 34  0
         if (database instanceof MySQLDatabase) {
 35  0
             sql = "ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName())
 36  
                     + " DROP KEY " + database.escapeConstraintName(statement.getConstraintName());
 37  0
         } else if (database instanceof MaxDBDatabase) {
 38  0
             sql = "DROP INDEX " + database.escapeConstraintName(statement.getConstraintName()) + " ON "
 39  
                     + database.escapeTableName(statement.getSchemaName(), statement.getTableName());
 40  0
         } else if (database instanceof OracleDatabase) {
 41  0
             sql = "ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName())
 42  
                     + " DROP CONSTRAINT " + database.escapeConstraintName(statement.getConstraintName())
 43  
                     + " DROP INDEX";
 44  0
         } else if (database instanceof SybaseASADatabase) {
 45  0
             sql = "ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName())
 46  
                     + " DROP UNIQUE (" + statement.getUniqueColumns() + ")";
 47  
         } else {
 48  0
             sql = "ALTER TABLE " + database.escapeTableName(statement.getSchemaName(), statement.getTableName())
 49  
                     + " DROP CONSTRAINT " + database.escapeConstraintName(statement.getConstraintName());
 50  
         }
 51  
 
 52  0
         return new Sql[] { new UnparsedSql(sql) };
 53  
     }
 54  
 }