1 | |
package liquibase.database.structure; |
2 | |
|
3 | |
import liquibase.util.StringUtils; |
4 | |
|
5 | |
import java.util.ArrayList; |
6 | |
import java.util.List; |
7 | |
|
8 | 3 | public class PrimaryKey implements DatabaseObject, Comparable<PrimaryKey> { |
9 | |
private String name; |
10 | 3 | private List<String> columnNames = new ArrayList<String>(); |
11 | |
private Table table; |
12 | 3 | private boolean certainName = true; |
13 | |
private String tablespace; |
14 | |
|
15 | |
public DatabaseObject[] getContainingObjects() { |
16 | 0 | return new DatabaseObject[] { table }; |
17 | |
} |
18 | |
|
19 | |
public String getName() { |
20 | 0 | return name; |
21 | |
} |
22 | |
|
23 | |
public void setName(String name) { |
24 | 0 | this.name = name; |
25 | 0 | } |
26 | |
|
27 | |
public String getColumnNames() { |
28 | 0 | return StringUtils.join(columnNames, ", "); |
29 | |
} |
30 | |
|
31 | |
public void addColumnName(int position, String columnName) { |
32 | 5 | if (position >= columnNames.size()) { |
33 | 9 | for (int i = columnNames.size() - 1; i < position; i++) { |
34 | 5 | this.columnNames.add(null); |
35 | |
} |
36 | |
} |
37 | 5 | this.columnNames.set(position, columnName); |
38 | 5 | } |
39 | |
|
40 | |
public Table getTable() { |
41 | 0 | return table; |
42 | |
} |
43 | |
|
44 | |
public void setTable(Table table) { |
45 | 0 | this.table = table; |
46 | 0 | } |
47 | |
|
48 | |
public int compareTo(PrimaryKey o) { |
49 | 0 | int returnValue = this.getTable().getName().compareTo(o.getTable().getName()); |
50 | 0 | if (returnValue == 0) { |
51 | 0 | returnValue = this.getColumnNames().compareTo(o.getColumnNames()); |
52 | |
} |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | 0 | return returnValue; |
58 | |
} |
59 | |
|
60 | |
@Override |
61 | |
public boolean equals(Object o) { |
62 | 0 | if (this == o) |
63 | 0 | return true; |
64 | 0 | if (o == null || getClass() != o.getClass()) |
65 | 0 | return false; |
66 | |
|
67 | 0 | PrimaryKey that = (PrimaryKey) o; |
68 | |
|
69 | 0 | return !(getColumnNames() != null ? !getColumnNames().equalsIgnoreCase(that.getColumnNames()) : that |
70 | |
.getColumnNames() != null) |
71 | |
&& !(getTable().getName() != null ? !getTable().getName().equalsIgnoreCase(that.getTable().getName()) |
72 | |
: that.getTable().getName() != null); |
73 | |
|
74 | |
} |
75 | |
|
76 | |
@Override |
77 | |
public int hashCode() { |
78 | |
int result; |
79 | 0 | result = (getColumnNames() != null ? getColumnNames().toUpperCase().hashCode() : 0); |
80 | 0 | result = 31 * result + (table.getName() != null ? table.getName().toUpperCase().hashCode() : 0); |
81 | 0 | return result; |
82 | |
} |
83 | |
|
84 | |
@Override |
85 | |
public String toString() { |
86 | 0 | return getName() + " on " + getTable().getName() + "(" + getColumnNames() + ")"; |
87 | |
} |
88 | |
|
89 | |
public List<String> getColumnNamesAsList() { |
90 | 7 | return columnNames; |
91 | |
} |
92 | |
|
93 | |
public boolean isCertainName() { |
94 | 0 | return certainName; |
95 | |
} |
96 | |
|
97 | |
public void setCertainName(boolean certainName) { |
98 | 0 | this.certainName = certainName; |
99 | 0 | } |
100 | |
|
101 | |
public String getTablespace() { |
102 | 0 | return tablespace; |
103 | |
} |
104 | |
|
105 | |
public void setTablespace(String tablespace) { |
106 | 0 | this.tablespace = tablespace; |
107 | 0 | } |
108 | |
} |