1 |
|
package liquibase.change.core; |
2 |
|
|
3 |
|
import liquibase.change.AbstractChange; |
4 |
|
import liquibase.change.Change; |
5 |
|
import liquibase.change.ChangeMetaData; |
6 |
|
import liquibase.database.Database; |
7 |
|
import liquibase.database.structure.ForeignKeyConstraintType; |
8 |
|
import liquibase.exception.UnexpectedLiquibaseException; |
9 |
|
import liquibase.statement.SqlStatement; |
10 |
|
import liquibase.statement.core.AddForeignKeyConstraintStatement; |
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
|
|
| 55.8% |
Uncovered Elements: 57 (129) |
Complexity: 49 |
Complexity Density: 0.77 |
|
15 |
|
public class AddForeignKeyConstraintChange extends AbstractChange { |
16 |
|
private String baseTableSchemaName; |
17 |
|
private String baseTableName; |
18 |
|
private String baseColumnNames; |
19 |
|
|
20 |
|
private String referencedTableSchemaName; |
21 |
|
private String referencedTableName; |
22 |
|
private String referencedColumnNames; |
23 |
|
|
24 |
|
private String constraintName; |
25 |
|
|
26 |
|
private Boolean deferrable; |
27 |
|
private Boolean initiallyDeferred; |
28 |
|
|
29 |
|
private String onUpdate; |
30 |
|
private String onDelete; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
private Boolean referencesUniqueColumn; |
35 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
36 |
77
|
public AddForeignKeyConstraintChange() {... |
37 |
77
|
super("addForeignKeyConstraint", "Add Foreign Key Constraint", ChangeMetaData.PRIORITY_DEFAULT); |
38 |
|
} |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
40 |
124
|
public String getBaseTableSchemaName() {... |
41 |
124
|
return baseTableSchemaName; |
42 |
|
} |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
44 |
63
|
public void setBaseTableSchemaName(String baseTableSchemaName) {... |
45 |
63
|
this.baseTableSchemaName = baseTableSchemaName; |
46 |
|
} |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
106
|
public String getBaseTableName() {... |
49 |
106
|
return baseTableName; |
50 |
|
} |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
52 |
63
|
public void setBaseTableName(String baseTableName) {... |
53 |
63
|
this.baseTableName = baseTableName; |
54 |
|
} |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
106
|
public String getBaseColumnNames() {... |
57 |
106
|
return baseColumnNames; |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
63
|
public void setBaseColumnNames(String baseColumnNames) {... |
61 |
63
|
this.baseColumnNames = baseColumnNames; |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
124
|
public String getReferencedTableSchemaName() {... |
65 |
124
|
return referencedTableSchemaName; |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
62
|
public void setReferencedTableSchemaName(String referencedTableSchemaName) {... |
69 |
62
|
this.referencedTableSchemaName = referencedTableSchemaName; |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
105
|
public String getReferencedTableName() {... |
73 |
105
|
return referencedTableName; |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
62
|
public void setReferencedTableName(String referencedTableName) {... |
77 |
62
|
this.referencedTableName = referencedTableName; |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
80 |
105
|
public String getReferencedColumnNames() {... |
81 |
105
|
return referencedColumnNames; |
82 |
|
} |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
62
|
public void setReferencedColumnNames(String referencedColumnNames) {... |
85 |
62
|
this.referencedColumnNames = referencedColumnNames; |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
105
|
public String getConstraintName() {... |
89 |
105
|
return constraintName; |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
63
|
public void setConstraintName(String constraintName) {... |
93 |
63
|
this.constraintName = constraintName; |
94 |
|
} |
95 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
106
|
public Boolean getDeferrable() {... |
97 |
106
|
return deferrable; |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
3
|
public void setDeferrable(Boolean deferrable) {... |
101 |
3
|
this.deferrable = deferrable; |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
106
|
public Boolean getInitiallyDeferred() {... |
105 |
106
|
return initiallyDeferred; |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
3
|
public void setInitiallyDeferred(Boolean initiallyDeferred) {... |
109 |
3
|
this.initiallyDeferred = initiallyDeferred; |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 3 |
Complexity Density: 1.5 |
|
116 |
2
|
public void setDeleteCascade(Boolean deleteCascade) {... |
117 |
2
|
if (deleteCascade != null && deleteCascade) { |
118 |
2
|
setOnDelete("CASCADE"); |
119 |
|
} |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
2
|
public void setOnUpdate(String rule) {... |
123 |
2
|
this.onUpdate = rule; |
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
105
|
public String getOnUpdate() {... |
127 |
105
|
return onUpdate; |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
4
|
public void setOnDelete(String onDelete) {... |
131 |
4
|
this.onDelete = onDelete; |
132 |
|
} |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
134 |
105
|
public String getOnDelete() {... |
135 |
105
|
return this.onDelete; |
136 |
|
} |
137 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
105
|
public Boolean getReferencesUniqueColumn() {... |
139 |
105
|
return referencesUniqueColumn; |
140 |
|
} |
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
3
|
public void setReferencesUniqueColumn(Boolean referencesUniqueColumn) {... |
143 |
3
|
this.referencesUniqueColumn = referencesUniqueColumn; |
144 |
|
} |
145 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 7 |
Complexity Density: 0.58 |
|
146 |
0
|
public void setOnDelete(ForeignKeyConstraintType rule) {... |
147 |
0
|
if (rule == null) { |
148 |
|
|
149 |
0
|
} else if (rule == ForeignKeyConstraintType.importedKeyCascade) { |
150 |
0
|
setOnDelete("CASCADE"); |
151 |
0
|
} else if (rule == ForeignKeyConstraintType.importedKeySetNull) { |
152 |
0
|
setOnDelete("SET NULL"); |
153 |
0
|
} else if (rule == ForeignKeyConstraintType.importedKeySetDefault) { |
154 |
0
|
setOnDelete("SET DEFAULT"); |
155 |
0
|
} else if (rule == ForeignKeyConstraintType.importedKeyRestrict) { |
156 |
0
|
setOnDelete("RESTRICT"); |
157 |
0
|
} else if (rule == ForeignKeyConstraintType.importedKeyNoAction) { |
158 |
0
|
setOnDelete("NO ACTION"); |
159 |
|
} else { |
160 |
0
|
throw new UnexpectedLiquibaseException("Unknown onDelete action: " + rule); |
161 |
|
} |
162 |
|
} |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 7 |
Complexity Density: 0.58 |
|
164 |
0
|
public void setOnUpdate(ForeignKeyConstraintType rule) {... |
165 |
0
|
if (rule == null) { |
166 |
|
|
167 |
0
|
} else if (rule == ForeignKeyConstraintType.importedKeyCascade) { |
168 |
0
|
setOnUpdate("CASCADE"); |
169 |
0
|
} else if (rule == ForeignKeyConstraintType.importedKeySetNull) { |
170 |
0
|
setOnUpdate("SET NULL"); |
171 |
0
|
} else if (rule == ForeignKeyConstraintType.importedKeySetDefault) { |
172 |
0
|
setOnUpdate("SET DEFAULT"); |
173 |
0
|
} else if (rule == ForeignKeyConstraintType.importedKeyRestrict) { |
174 |
0
|
setOnUpdate("RESTRICT"); |
175 |
0
|
} else if (rule == ForeignKeyConstraintType.importedKeyNoAction) { |
176 |
0
|
setOnUpdate("NO ACTION"); |
177 |
|
} else { |
178 |
0
|
throw new UnexpectedLiquibaseException("Unknown onUpdate action: " + onUpdate); |
179 |
|
} |
180 |
|
} |
181 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 5 |
Complexity Density: 0.71 |
|
182 |
105
|
public SqlStatement[] generateStatements(Database database) {... |
183 |
|
|
184 |
105
|
boolean deferrable = false; |
185 |
105
|
if (getDeferrable() != null) { |
186 |
1
|
deferrable = getDeferrable(); |
187 |
|
} |
188 |
|
|
189 |
105
|
boolean initiallyDeferred = false; |
190 |
105
|
if (getInitiallyDeferred() != null) { |
191 |
1
|
initiallyDeferred = getInitiallyDeferred(); |
192 |
|
} |
193 |
|
|
194 |
105
|
return new SqlStatement[] { new AddForeignKeyConstraintStatement(getConstraintName(), |
195 |
105
|
getBaseTableSchemaName() == null ? database.getDefaultSchemaName() : getBaseTableSchemaName(), |
196 |
|
getBaseTableName(), getBaseColumnNames(), |
197 |
105
|
getReferencedTableSchemaName() == null ? database.getDefaultSchemaName() |
198 |
|
: getReferencedTableSchemaName(), getReferencedTableName(), getReferencedColumnNames()) |
199 |
|
.setDeferrable(deferrable).setInitiallyDeferred(initiallyDeferred).setOnUpdate(getOnUpdate()) |
200 |
|
.setOnDelete(getOnDelete()).setReferencesUniqueColumn(getReferencesUniqueColumn()) }; |
201 |
|
} |
202 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
203 |
0
|
@Override... |
204 |
|
protected Change[] createInverses() { |
205 |
0
|
DropForeignKeyConstraintChange inverse = new DropForeignKeyConstraintChange(); |
206 |
0
|
inverse.setBaseTableSchemaName(getBaseTableSchemaName()); |
207 |
0
|
inverse.setBaseTableName(getBaseTableName()); |
208 |
0
|
inverse.setConstraintName(getConstraintName()); |
209 |
|
|
210 |
0
|
return new Change[] { inverse }; |
211 |
|
} |
212 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
213 |
1
|
public String getConfirmationMessage() {... |
214 |
1
|
return "Foreign key contraint added to " + getBaseTableName() + " (" + getBaseColumnNames() + ")"; |
215 |
|
} |
216 |
|
} |