1 package liquibase.database.structure;
2
3 import liquibase.database.Database;
4
5 import java.util.ArrayList;
6 import java.util.List;
7
8 public class Table implements DatabaseObject, Comparable<Table> {
9
10 private Database database;
11 private String name;
12 private String remarks;
13 private String schema;
14 private List<Column> columns = new ArrayList<Column>();
15
16 private String rawCatalogName;
17 private String rawSchemaName;
18
19 public Table(String name) {
20 this.name = name;
21 }
22
23 public String getName() {
24 return name;
25 }
26
27 public Database getDatabase() {
28 return database;
29 }
30
31 public DatabaseObject[] getContainingObjects() {
32 if (getSchema() == null) {
33 return new DatabaseObject[] { getDatabase() };
34 } else {
35 return new DatabaseObject[] { new Schema(getSchema()) };
36 }
37
38 }
39
40 public Table setDatabase(Database database) {
41 this.database = database;
42
43 return this;
44 }
45
46 public String getRemarks() {
47 return remarks;
48 }
49
50 public Table setRemarks(String remarks) {
51 this.remarks = remarks;
52
53 return this;
54 }
55
56 public List<Column> getColumns() {
57 return columns;
58 }
59
60 @Override
61 public boolean equals(Object o) {
62 if (this == o)
63 return true;
64 if (o == null || getClass() != o.getClass())
65 return false;
66
67 Table that = (Table) o;
68
69 return name.equalsIgnoreCase(that.name);
70
71 }
72
73 @Override
74 public int hashCode() {
75 return name.toUpperCase().hashCode();
76 }
77
78 public int compareTo(Table o) {
79 return this.getName().compareToIgnoreCase(o.getName());
80 }
81
82 @Override
83 public String toString() {
84 return getName();
85 }
86
87
88
89
90 public Column getColumn(String columnName) {
91 for (Column column : getColumns()) {
92 if (column.getName().equalsIgnoreCase(columnName)) {
93 return column;
94 }
95 }
96 return null;
97 }
98
99
100
101
102 public String getSchema() {
103 return schema;
104 }
105
106
107
108
109
110 public Table setSchema(String schema) {
111 this.schema = schema;
112
113 return this;
114 }
115
116 public String getRawCatalogName() {
117 return rawCatalogName;
118 }
119
120 public void setRawCatalogName(String rawCatalogName) {
121 this.rawCatalogName = rawCatalogName;
122 }
123
124 public String getRawSchemaName() {
125 return rawSchemaName;
126 }
127
128 public void setRawSchemaName(String rawSchemaName) {
129 this.rawSchemaName = rawSchemaName;
130 }
131 }