1 |
|
package liquibase.change.core; |
2 |
|
|
3 |
|
import liquibase.change.AbstractChange; |
4 |
|
import liquibase.change.Change; |
5 |
|
import liquibase.change.ChangeMetaData; |
6 |
|
import liquibase.change.ColumnConfig; |
7 |
|
import liquibase.database.Database; |
8 |
|
import liquibase.database.core.SQLiteDatabase; |
9 |
|
import liquibase.database.core.SQLiteDatabase.AlterTableVisitor; |
10 |
|
import liquibase.database.structure.Index; |
11 |
|
import liquibase.statement.SqlStatement; |
12 |
|
import liquibase.statement.core.RenameColumnStatement; |
13 |
|
import liquibase.util.StringUtils; |
14 |
|
|
15 |
|
import java.util.ArrayList; |
16 |
|
import java.util.List; |
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
|
|
| 42.6% |
Uncovered Elements: 35 (61) |
Complexity: 23 |
Complexity Density: 0.64 |
|
21 |
|
public class RenameColumnChange extends AbstractChange { |
22 |
|
|
23 |
|
private String schemaName; |
24 |
|
private String tableName; |
25 |
|
private String oldColumnName; |
26 |
|
private String newColumnName; |
27 |
|
private String columnDataType; |
28 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
29 |
20
|
public RenameColumnChange() {... |
30 |
20
|
super("renameColumn", "Rename Column", ChangeMetaData.PRIORITY_DEFAULT); |
31 |
|
} |
32 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
33 |
45
|
public String getSchemaName() {... |
34 |
45
|
return schemaName; |
35 |
|
} |
36 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
37 |
7
|
public void setSchemaName(String schemaName) {... |
38 |
7
|
this.schemaName = StringUtils.trimToNull(schemaName); |
39 |
|
} |
40 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
41 |
44
|
public String getTableName() {... |
42 |
44
|
return tableName; |
43 |
|
} |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
7
|
public void setTableName(String tableName) {... |
46 |
7
|
this.tableName = tableName; |
47 |
|
} |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
44
|
public String getOldColumnName() {... |
50 |
44
|
return oldColumnName; |
51 |
|
} |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
53 |
7
|
public void setOldColumnName(String oldColumnName) {... |
54 |
7
|
this.oldColumnName = oldColumnName; |
55 |
|
} |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
44
|
public String getNewColumnName() {... |
58 |
44
|
return newColumnName; |
59 |
|
} |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
7
|
public void setNewColumnName(String newColumnName) {... |
62 |
7
|
this.newColumnName = newColumnName; |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
44
|
public String getColumnDataType() {... |
66 |
44
|
return columnDataType; |
67 |
|
} |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
0
|
public void setColumnDataType(String columnDataType) {... |
70 |
0
|
this.columnDataType = columnDataType; |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
73 |
44
|
public SqlStatement[] generateStatements(Database database) {... |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
44
|
return new SqlStatement[] { new RenameColumnStatement(getSchemaName() == null ? database.getDefaultSchemaName() |
80 |
|
: getSchemaName(), getTableName(), getOldColumnName(), getNewColumnName(), getColumnDataType()) }; |
81 |
|
} |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
83 |
0
|
private SqlStatement[] generateStatementsForSQLiteDatabase(Database database) {... |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
0
|
List<SqlStatement> statements = new ArrayList<SqlStatement>(); |
90 |
|
|
91 |
|
|
92 |
0
|
AlterTableVisitor rename_alter_visitor = new AlterTableVisitor() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
0
|
public ColumnConfig[] getColumnsToAdd() {... |
94 |
0
|
return new ColumnConfig[0]; |
95 |
|
} |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
0
|
public boolean copyThisColumn(ColumnConfig column) {... |
98 |
0
|
return true; |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
101 |
0
|
public boolean createThisColumn(ColumnConfig column) {... |
102 |
0
|
if (column.getName().equals(getOldColumnName())) { |
103 |
0
|
column.setName(getNewColumnName()); |
104 |
|
} |
105 |
0
|
return true; |
106 |
|
} |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
108 |
0
|
public boolean createThisIndex(Index index) {... |
109 |
0
|
if (index.getColumns().contains(getOldColumnName())) { |
110 |
0
|
index.getColumns().remove(getOldColumnName()); |
111 |
0
|
index.getColumns().add(getNewColumnName()); |
112 |
|
} |
113 |
0
|
return true; |
114 |
|
} |
115 |
|
}; |
116 |
|
|
117 |
0
|
try { |
118 |
|
|
119 |
0
|
statements.addAll(SQLiteDatabase.getAlterTableStatements(rename_alter_visitor, database, getSchemaName(), |
120 |
|
getTableName())); |
121 |
|
} catch (Exception e) { |
122 |
0
|
System.err.println(e); |
123 |
0
|
e.printStackTrace(); |
124 |
|
} |
125 |
|
|
126 |
0
|
return statements.toArray(new SqlStatement[statements.size()]); |
127 |
|
} |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
129 |
0
|
@Override... |
130 |
|
protected Change[] createInverses() { |
131 |
0
|
RenameColumnChange inverse = new RenameColumnChange(); |
132 |
0
|
inverse.setSchemaName(getSchemaName()); |
133 |
0
|
inverse.setTableName(getTableName()); |
134 |
0
|
inverse.setOldColumnName(getNewColumnName()); |
135 |
0
|
inverse.setNewColumnName(getOldColumnName()); |
136 |
0
|
inverse.setColumnDataType(getColumnDataType()); |
137 |
|
|
138 |
0
|
return new Change[] { inverse }; |
139 |
|
} |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
141 |
1
|
public String getConfirmationMessage() {... |
142 |
1
|
return "Column " + tableName + "." + oldColumnName + " renamed to " + newColumnName; |
143 |
|
} |
144 |
|
|
145 |
|
} |