Coverage Report - liquibase.sqlgenerator.core.DropForeignKeyConstraintGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
DropForeignKeyConstraintGenerator
66%
6/9
12%
1/8
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.SQLiteDatabase;
 7  
 import liquibase.database.core.SybaseASADatabase;
 8  
 import liquibase.exception.ValidationErrors;
 9  
 import liquibase.sql.Sql;
 10  
 import liquibase.sql.UnparsedSql;
 11  
 import liquibase.sqlgenerator.SqlGenerator;
 12  
 import liquibase.sqlgenerator.SqlGeneratorChain;
 13  
 import liquibase.statement.core.DropForeignKeyConstraintStatement;
 14  
 
 15  86
 public class DropForeignKeyConstraintGenerator extends AbstractSqlGenerator<DropForeignKeyConstraintStatement> {
 16  
 
 17  
     @Override
 18  
     public boolean supports(DropForeignKeyConstraintStatement statement, Database database) {
 19  61
         return (!(database instanceof SQLiteDatabase));
 20  
     }
 21  
 
 22  
     public ValidationErrors validate(DropForeignKeyConstraintStatement dropForeignKeyConstraintStatement,
 23  
             Database database, SqlGeneratorChain sqlGeneratorChain) {
 24  15
         ValidationErrors validationErrors = new ValidationErrors();
 25  15
         validationErrors.checkRequiredField("baseTableName", dropForeignKeyConstraintStatement.getBaseTableName());
 26  15
         validationErrors.checkRequiredField("constraintName", dropForeignKeyConstraintStatement.getConstraintName());
 27  15
         return validationErrors;
 28  
     }
 29  
 
 30  
     public Sql[] generateSql(DropForeignKeyConstraintStatement statement, Database database,
 31  
             SqlGeneratorChain sqlGeneratorChain) {
 32  0
         if (database instanceof MySQLDatabase || database instanceof MaxDBDatabase
 33  
                 || database instanceof SybaseASADatabase) {
 34  0
             return new Sql[] { new UnparsedSql("ALTER TABLE "
 35  
                     + database.escapeTableName(statement.getBaseTableSchemaName(), statement.getBaseTableName())
 36  
                     + " DROP FOREIGN KEY " + database.escapeConstraintName(statement.getConstraintName())) };
 37  
         } else {
 38  0
             return new Sql[] { new UnparsedSql("ALTER TABLE "
 39  
                     + database.escapeTableName(statement.getBaseTableSchemaName(), statement.getBaseTableName())
 40  
                     + " DROP CONSTRAINT " + database.escapeConstraintName(statement.getConstraintName())) };
 41  
         }
 42  
 
 43  
     }
 44  
 }