1 10 11 package com.triactive.jdo.store; 12 13 import javax.jdo.JDOFatalInternalException; 14 15 16 class Index extends Key 17 { 18 private final boolean isUnique; 19 20 21 public Index(BaseTable table, boolean isUnique) 22 { 23 super(table); 24 25 this.isUnique = isUnique; 26 } 27 28 29 public Index(CandidateKey ck) 30 { 31 super(ck.getTable()); 32 33 isUnique = true; 34 columns.addAll(ck.getColumns()); 35 } 36 37 38 public Index(ForeignKey fk) 39 { 40 super(fk.getTable()); 41 42 isUnique = false; 43 columns.addAll(fk.getColumns()); 44 } 45 46 47 public boolean getUnique() 48 { 49 return isUnique; 50 } 51 52 53 public void setColumn(int seq, Column col) 54 { 55 assertSameTable(col); 56 57 setMinSize(columns, seq + 1); 58 59 if (columns.get(seq) != null) 60 throw new JDOFatalInternalException("Index part #" + seq + " for " + table + " already set"); 61 62 columns.set(seq, col); 63 } 64 65 66 public void addColumn(Column col) 67 { 68 assertSameTable(col); 69 70 columns.add(col); 71 } 72 73 74 public int size() 75 { 76 return columns.size(); 77 } 78 79 80 public int hashCode() 81 { 82 return (isUnique ? 0 : 1) ^ columns.hashCode(); 83 } 84 85 86 public boolean equals(Object o) 87 { 88 if (o == this) 89 return true; 90 91 if (!(o instanceof Index)) 92 return false; 93 94 Index idx = (Index)o; 95 96 return isUnique == idx.isUnique && columns.equals(idx.columns); 97 } 98 99 100 public String toString() 101 { 102 return getColumnList(); 103 } 104 } 105 | Popular Tags |