| 1 |  |  package liquibase.precondition.core; | 
  | 2 |  |   | 
  | 3 |  |  import liquibase.changelog.DatabaseChangeLog; | 
  | 4 |  |  import liquibase.changelog.ChangeSet; | 
  | 5 |  |  import liquibase.database.Database; | 
  | 6 |  |  import liquibase.exception.PreconditionErrorException; | 
  | 7 |  |  import liquibase.exception.PreconditionFailedException; | 
  | 8 |  |  import liquibase.exception.ValidationErrors; | 
  | 9 |  |  import liquibase.exception.Warnings; | 
  | 10 |  |  import liquibase.precondition.Precondition; | 
  | 11 |  |  import liquibase.snapshot.DatabaseSnapshotGeneratorFactory; | 
  | 12 |  |  import liquibase.util.StringUtils; | 
  | 13 |  |   | 
  | 14 | 8 |  public class TableExistsPrecondition implements Precondition { | 
  | 15 |  |      private String schemaName; | 
  | 16 |  |      private String tableName; | 
  | 17 |  |   | 
  | 18 |  |      public String getSchemaName() { | 
  | 19 | 0 |          return schemaName; | 
  | 20 |  |      } | 
  | 21 |  |   | 
  | 22 |  |      public void setSchemaName(String schemaName) { | 
  | 23 | 0 |          this.schemaName = StringUtils.trimToNull(schemaName); | 
  | 24 | 0 |      } | 
  | 25 |  |   | 
  | 26 |  |      public String getTableName() { | 
  | 27 | 0 |          return tableName; | 
  | 28 |  |      } | 
  | 29 |  |   | 
  | 30 |  |      public void setTableName(String tableName) { | 
  | 31 | 0 |          this.tableName = tableName; | 
  | 32 | 0 |      } | 
  | 33 |  |   | 
  | 34 |  |      public Warnings warn(Database database) { | 
  | 35 | 0 |          return new Warnings(); | 
  | 36 |  |      } | 
  | 37 |  |   | 
  | 38 |  |      public ValidationErrors validate(Database database) { | 
  | 39 | 0 |          return new ValidationErrors(); | 
  | 40 |  |      } | 
  | 41 |  |   | 
  | 42 |  |      public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) | 
  | 43 |  |              throws PreconditionFailedException, PreconditionErrorException { | 
  | 44 |  |          try { | 
  | 45 | 0 |              if (!DatabaseSnapshotGeneratorFactory.getInstance().getGenerator(database) | 
  | 46 |  |                      .hasTable(getSchemaName(), getTableName(), database)) { | 
  | 47 | 0 |                  throw new PreconditionFailedException("Table " | 
  | 48 |  |                          + database.escapeTableName(getSchemaName(), getTableName()) + " does not exist", changeLog, | 
  | 49 |  |                          this); | 
  | 50 |  |              } | 
  | 51 | 0 |          } catch (PreconditionFailedException e) { | 
  | 52 | 0 |              throw e; | 
  | 53 | 0 |          } catch (Exception e) { | 
  | 54 | 0 |              throw new PreconditionErrorException(e, changeLog, this); | 
  | 55 | 0 |          } | 
  | 56 | 0 |      } | 
  | 57 |  |   | 
  | 58 |  |      public String getName() { | 
  | 59 | 8 |          return "tableExists"; | 
  | 60 |  |      } | 
  | 61 |  |  } |