Coverage Report - liquibase.sqlgenerator.core.AddUniqueConstraintGeneratorTDS
 
Classes in this File Line Coverage Branch Coverage Complexity
AddUniqueConstraintGeneratorTDS
50%
5/10
75%
6/8
2
 
 1  
 package liquibase.sqlgenerator.core;
 2  
 
 3  
 import liquibase.database.Database;
 4  
 import liquibase.database.core.MSSQLDatabase;
 5  
 import liquibase.database.core.SybaseASADatabase;
 6  
 import liquibase.database.core.SybaseDatabase;
 7  
 import liquibase.sql.Sql;
 8  
 import liquibase.sql.UnparsedSql;
 9  
 import liquibase.sqlgenerator.SqlGeneratorChain;
 10  
 import liquibase.statement.core.AddUniqueConstraintStatement;
 11  
 
 12  76
 public class AddUniqueConstraintGeneratorTDS extends AddUniqueConstraintGenerator {
 13  
 
 14  13
     public AddUniqueConstraintGeneratorTDS() {
 15  
 
 16  13
     }
 17  
 
 18  
     @Override
 19  
     public int getPriority() {
 20  1
         return PRIORITY_DATABASE;
 21  
     }
 22  
 
 23  
     @Override
 24  
     public boolean supports(AddUniqueConstraintStatement statement, Database database) {
 25  76
         return (database instanceof MSSQLDatabase) || (database instanceof SybaseDatabase)
 26  
                 || (database instanceof SybaseASADatabase);
 27  
     }
 28  
 
 29  
     @Override
 30  
     public Sql[] generateSql(AddUniqueConstraintStatement statement, Database database,
 31  
             SqlGeneratorChain sqlGeneratorChain) {
 32  
 
 33  0
         final String sqlTemplate = "ALTER TABLE %s ADD CONSTRAINT %s UNIQUE (%s)";
 34  0
         final String sqlNoContraintNameTemplate = "ALTER TABLE %s ADD UNIQUE (%s)";
 35  
 
 36  0
         if (statement.getConstraintName() == null) {
 37  0
             return new Sql[] { new UnparsedSql(String.format(sqlNoContraintNameTemplate,
 38  
                     database.escapeTableName(statement.getSchemaName(), statement.getTableName()),
 39  
                     database.escapeColumnNameList(statement.getColumnNames()))) };
 40  
         } else {
 41  0
             return new Sql[] { new UnparsedSql(String.format(sqlTemplate,
 42  
                     database.escapeTableName(statement.getSchemaName(), statement.getTableName()),
 43  
                     database.escapeConstraintName(statement.getConstraintName()),
 44  
                     database.escapeColumnNameList(statement.getColumnNames()))) };
 45  
         }
 46  
     }
 47  
 
 48  
 }