Coverage Report - liquibase.precondition.core.ColumnExistsPrecondition
 
Classes in this File Line Coverage Branch Coverage Complexity
ColumnExistsPrecondition
10%
2/19
0%
0/2
1.4
 
 1  
 package liquibase.precondition.core;
 2  
 
 3  
 import liquibase.changelog.ChangeSet;
 4  
 import liquibase.changelog.DatabaseChangeLog;
 5  
 import liquibase.database.Database;
 6  
 import liquibase.exception.DatabaseException;
 7  
 import liquibase.exception.PreconditionErrorException;
 8  
 import liquibase.exception.PreconditionFailedException;
 9  
 import liquibase.exception.ValidationErrors;
 10  
 import liquibase.exception.Warnings;
 11  
 import liquibase.precondition.Precondition;
 12  
 import liquibase.snapshot.DatabaseSnapshotGeneratorFactory;
 13  
 import liquibase.util.StringUtils;
 14  
 
 15  8
 public class ColumnExistsPrecondition implements Precondition {
 16  
     private String schemaName;
 17  
     private String tableName;
 18  
     private String columnName;
 19  
 
 20  
     public String getSchemaName() {
 21  0
         return schemaName;
 22  
     }
 23  
 
 24  
     public void setSchemaName(String schemaName) {
 25  0
         this.schemaName = StringUtils.trimToNull(schemaName);
 26  0
     }
 27  
 
 28  
     public String getTableName() {
 29  0
         return tableName;
 30  
     }
 31  
 
 32  
     public void setTableName(String tableName) {
 33  0
         this.tableName = tableName;
 34  0
     }
 35  
 
 36  
     public String getColumnName() {
 37  0
         return columnName;
 38  
     }
 39  
 
 40  
     public void setColumnName(String columnName) {
 41  0
         this.columnName = columnName;
 42  0
     }
 43  
 
 44  
     @Override
 45  
     public Warnings warn(Database database) {
 46  0
         return new Warnings();
 47  
     }
 48  
 
 49  
     @Override
 50  
     public ValidationErrors validate(Database database) {
 51  0
         return new ValidationErrors();
 52  
     }
 53  
 
 54  
     @Override
 55  
     public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet)
 56  
             throws PreconditionFailedException, PreconditionErrorException {
 57  
         try {
 58  0
             if (DatabaseSnapshotGeneratorFactory.getInstance().getGenerator(database)
 59  
                     .getColumn(getSchemaName(), getTableName(), getColumnName(), database) == null) {
 60  0
                 throw new PreconditionFailedException("Column '"
 61  
                         + database.escapeColumnName(getSchemaName(), getTableName(), getColumnName())
 62  
                         + "' does not exist", changeLog, this);
 63  
             }
 64  0
         } catch (DatabaseException e) {
 65  0
             throw new PreconditionErrorException(e, changeLog, this);
 66  0
         }
 67  0
     }
 68  
 
 69  
     @Override
 70  
     public String getName() {
 71  8
         return "columnExists";
 72  
     }
 73  
 }