|  1 |     | 
   package liquibase.changelog;  | 
  |  2 |     | 
     | 
  |  3 |     | 
   import liquibase.changelog.filter.ContextChangeSetFilter;  | 
  |  4 |     | 
   import liquibase.changelog.filter.DbmsChangeSetFilter;  | 
  |  5 |     | 
   import liquibase.changelog.visitor.ValidatingVisitor;  | 
  |  6 |     | 
   import liquibase.database.Database;  | 
  |  7 |     | 
   import liquibase.exception.LiquibaseException;  | 
  |  8 |     | 
   import liquibase.exception.ValidationFailedException;  | 
  |  9 |     | 
   import liquibase.logging.LogFactory;  | 
  |  10 |     | 
   import liquibase.precondition.Conditional;  | 
  |  11 |     | 
   import liquibase.precondition.core.PreconditionContainer;  | 
  |  12 |     | 
     | 
  |  13 |     | 
   import java.util.ArrayList;  | 
  |  14 |     | 
   import java.util.List;  | 
  |  15 |     | 
     | 
  |  16 |     | 
     | 
  |  17 |     | 
     | 
  |  18 |     | 
     | 
  |  19 |    0 |    public class DatabaseChangeLog implements Comparable<DatabaseChangeLog>, Conditional { | 
  |  20 |    36 |        private PreconditionContainer preconditionContainer = new PreconditionContainer();  | 
  |  21 |     | 
       private String physicalFilePath;  | 
  |  22 |     | 
       private String logicalFilePath;  | 
  |  23 |     | 
     | 
  |  24 |    36 |        private List<ChangeSet> changeSets = new ArrayList<ChangeSet>();  | 
  |  25 |     | 
       private ChangeLogParameters changeLogParameters;  | 
  |  26 |     | 
     | 
  |  27 |    34 |        public DatabaseChangeLog() { | 
  |  28 |    34 |        }  | 
  |  29 |     | 
     | 
  |  30 |    2 |        public DatabaseChangeLog(String physicalFilePath) { | 
  |  31 |    2 |            this.physicalFilePath = physicalFilePath;  | 
  |  32 |    2 |        }  | 
  |  33 |     | 
     | 
  |  34 |     | 
       public PreconditionContainer getPreconditions() { | 
  |  35 |    38 |            return preconditionContainer;  | 
  |  36 |     | 
       }  | 
  |  37 |     | 
     | 
  |  38 |     | 
       public void setPreconditions(PreconditionContainer precond) { | 
  |  39 |    2 |            preconditionContainer = precond;  | 
  |  40 |    2 |        }  | 
  |  41 |     | 
     | 
  |  42 |     | 
       public ChangeLogParameters getChangeLogParameters() { | 
  |  43 |    0 |            return changeLogParameters;  | 
  |  44 |     | 
       }  | 
  |  45 |     | 
     | 
  |  46 |     | 
       public void setChangeLogParameters(ChangeLogParameters changeLogParameters) { | 
  |  47 |    16 |            this.changeLogParameters = changeLogParameters;  | 
  |  48 |    16 |        }  | 
  |  49 |     | 
     | 
  |  50 |     | 
       public String getPhysicalFilePath() { | 
  |  51 |    31 |            return physicalFilePath;  | 
  |  52 |     | 
       }  | 
  |  53 |     | 
     | 
  |  54 |     | 
       public void setPhysicalFilePath(String physicalFilePath) { | 
  |  55 |    17 |            this.physicalFilePath = physicalFilePath;  | 
  |  56 |    17 |        }  | 
  |  57 |     | 
     | 
  |  58 |     | 
       public String getLogicalFilePath() { | 
  |  59 |    10 |            String returnPath = logicalFilePath;  | 
  |  60 |    10 |            if (logicalFilePath == null) { | 
  |  61 |    9 |                returnPath = physicalFilePath;  | 
  |  62 |     | 
           }  | 
  |  63 |    10 |            return returnPath.replaceAll("\\\\", "/"); | 
  |  64 |     | 
       }  | 
  |  65 |     | 
     | 
  |  66 |     | 
       public void setLogicalFilePath(String logicalFilePath) { | 
  |  67 |    16 |            this.logicalFilePath = logicalFilePath;  | 
  |  68 |    16 |        }  | 
  |  69 |     | 
     | 
  |  70 |     | 
       public String getFilePath() { | 
  |  71 |    29 |            if (logicalFilePath == null) { | 
  |  72 |    28 |                return physicalFilePath;  | 
  |  73 |     | 
           } else { | 
  |  74 |    1 |                return logicalFilePath;  | 
  |  75 |     | 
           }  | 
  |  76 |     | 
       }  | 
  |  77 |     | 
     | 
  |  78 |     | 
       @Override  | 
  |  79 |     | 
       public String toString() { | 
  |  80 |    4 |            return getFilePath();  | 
  |  81 |     | 
       }  | 
  |  82 |     | 
     | 
  |  83 |     | 
       public int compareTo(DatabaseChangeLog o) { | 
  |  84 |    0 |            return getFilePath().compareTo(o.getFilePath());  | 
  |  85 |     | 
       }  | 
  |  86 |     | 
     | 
  |  87 |     | 
       public ChangeSet getChangeSet(String path, String author, String id) { | 
  |  88 |    0 |            for (ChangeSet changeSet : changeSets) { | 
  |  89 |    0 |                if (changeSet.getFilePath().equalsIgnoreCase(path) && changeSet.getAuthor().equalsIgnoreCase(author)  | 
  |  90 |     | 
                       && changeSet.getId().equalsIgnoreCase(id)) { | 
  |  91 |    0 |                    return changeSet;  | 
  |  92 |     | 
               }  | 
  |  93 |     | 
           }  | 
  |  94 |     | 
     | 
  |  95 |    0 |            return null;  | 
  |  96 |     | 
       }  | 
  |  97 |     | 
     | 
  |  98 |     | 
       public List<ChangeSet> getChangeSets() { | 
  |  99 |    90 |            return changeSets;  | 
  |  100 |     | 
       }  | 
  |  101 |     | 
     | 
  |  102 |     | 
       public void addChangeSet(ChangeSet changeSet) { | 
  |  103 |    64 |            this.changeSets.add(changeSet);  | 
  |  104 |    64 |        }  | 
  |  105 |     | 
     | 
  |  106 |     | 
       @Override  | 
  |  107 |     | 
       public boolean equals(Object o) { | 
  |  108 |    1 |            if (this == o)  | 
  |  109 |    0 |                return true;  | 
  |  110 |    1 |            if (o == null || getClass() != o.getClass())  | 
  |  111 |    0 |                return false;  | 
  |  112 |     | 
     | 
  |  113 |    1 |            DatabaseChangeLog that = (DatabaseChangeLog) o;  | 
  |  114 |     | 
     | 
  |  115 |    1 |            return getFilePath().equals(that.getFilePath());  | 
  |  116 |     | 
     | 
  |  117 |     | 
       }  | 
  |  118 |     | 
     | 
  |  119 |     | 
       @Override  | 
  |  120 |     | 
       public int hashCode() { | 
  |  121 |    0 |            return getFilePath().hashCode();  | 
  |  122 |     | 
       }  | 
  |  123 |     | 
     | 
  |  124 |     | 
       public void validate(Database database, String... contexts) throws LiquibaseException { | 
  |  125 |     | 
     | 
  |  126 |    2 |            ChangeLogIterator logIterator = new ChangeLogIterator(this, new DbmsChangeSetFilter(database),  | 
  |  127 |     | 
                   new ContextChangeSetFilter(contexts));  | 
  |  128 |     | 
     | 
  |  129 |    2 |            ValidatingVisitor validatingVisitor = new ValidatingVisitor(database.getRanChangeSetList());  | 
  |  130 |    2 |            validatingVisitor.validate(database, this);  | 
  |  131 |    2 |            logIterator.run(validatingVisitor, database);  | 
  |  132 |     | 
     | 
  |  133 |    2 |            for (String message : validatingVisitor.getWarnings().getMessages()) { | 
  |  134 |    0 |                LogFactory.getLogger().warning(message);  | 
  |  135 |     | 
           }  | 
  |  136 |     | 
     | 
  |  137 |    2 |            if (!validatingVisitor.validationPassed()) { | 
  |  138 |    0 |                throw new ValidationFailedException(validatingVisitor);  | 
  |  139 |     | 
           }  | 
  |  140 |    2 |        }  | 
  |  141 |     | 
     | 
  |  142 |     | 
       public ChangeSet getChangeSet(RanChangeSet ranChangeSet) { | 
  |  143 |    0 |            return getChangeSet(ranChangeSet.getChangeLog(), ranChangeSet.getAuthor(), ranChangeSet.getId());  | 
  |  144 |     | 
       }  | 
  |  145 |     | 
   }  |