001: package liquibase.database.structure;
002:
003: import liquibase.util.StringUtils;
004:
005: import java.util.ArrayList;
006: import java.util.List;
007:
008: public class Index implements DatabaseObject, Comparable<Index> {
009: private String name;
010: private Table table;
011: private List<String> columns = new ArrayList<String>();
012: private String filterCondition;
013:
014: public String getName() {
015: return name;
016: }
017:
018: public void setName(String name) {
019: this .name = name;
020: }
021:
022: public Table getTable() {
023: return table;
024: }
025:
026: public void setTable(Table table) {
027: this .table = table;
028: }
029:
030: public List<String> getColumns() {
031: return columns;
032: }
033:
034: public String getColumnNames() {
035: return StringUtils.join(columns, ", ");
036: }
037:
038: public String getFilterCondition() {
039: return filterCondition;
040: }
041:
042: public void setFilterCondition(String filterCondition) {
043: this .filterCondition = filterCondition;
044: }
045:
046: public boolean equals(Object o) {
047: if (this == o)
048: return true;
049: if (o == null || getClass() != o.getClass())
050: return false;
051:
052: Index index = (Index) o;
053: boolean equals = true;
054: for (String column : index.getColumns()) {
055: if (!columns.contains(column)) {
056: equals = false;
057: }
058: }
059:
060: return equals
061: && table.getName().equalsIgnoreCase(
062: index.table.getName());
063:
064: }
065:
066: public int hashCode() {
067: int result;
068: result = table.getName().toUpperCase().hashCode();
069: result = 31 * result + columns.hashCode();
070: return result;
071: }
072:
073: public int compareTo(Index o) {
074: int returnValue = this .table.getName().compareTo(
075: o.table.getName());
076:
077: if (returnValue == 0) {
078: returnValue = this .getName().compareTo(o.getName());
079: }
080:
081: //We should not have two indexes that have the same name and tablename
082: /*if (returnValue == 0) {
083: returnValue = this.getColumnName().compareTo(o.getColumnName());
084: }*/
085:
086: return returnValue;
087: }
088:
089: public String toString() {
090: StringBuffer stringBuffer = new StringBuffer();
091: stringBuffer.append(getName()).append(" on ").append(
092: table.getName()).append("(");
093: for (String column : columns) {
094: stringBuffer.append(column).append(", ");
095: }
096: stringBuffer.delete(stringBuffer.length() - 2, stringBuffer
097: .length());
098: stringBuffer.append(")");
099: return stringBuffer.toString();
100: }
101:
102: }
|