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.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 ViewExistsPrecondition implements Precondition { |
15 | |
private String schemaName; |
16 | |
private String viewName; |
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 getViewName() { |
27 | 0 | return viewName; |
28 | |
} |
29 | |
|
30 | |
public void setViewName(String viewName) { |
31 | 0 | this.viewName = viewName; |
32 | 0 | } |
33 | |
|
34 | |
@Override |
35 | |
public Warnings warn(Database database) { |
36 | 0 | return new Warnings(); |
37 | |
} |
38 | |
|
39 | |
@Override |
40 | |
public ValidationErrors validate(Database database) { |
41 | 0 | return new ValidationErrors(); |
42 | |
} |
43 | |
|
44 | |
@Override |
45 | |
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) |
46 | |
throws PreconditionFailedException, PreconditionErrorException { |
47 | |
try { |
48 | 0 | if (!DatabaseSnapshotGeneratorFactory.getInstance().getGenerator(database) |
49 | |
.hasView(getSchemaName(), getViewName(), database)) { |
50 | 0 | throw new PreconditionFailedException("View " |
51 | |
+ database.escapeTableName(getSchemaName(), getViewName()) + " does not exist", changeLog, this); |
52 | |
} |
53 | 0 | } catch (PreconditionFailedException e) { |
54 | 0 | throw e; |
55 | 0 | } catch (Exception e) { |
56 | 0 | throw new PreconditionErrorException(e, changeLog, this); |
57 | 0 | } |
58 | 0 | } |
59 | |
|
60 | |
@Override |
61 | |
public String getName() { |
62 | 8 | return "viewExists"; |
63 | |
} |
64 | |
} |