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