1 2 12 package com.versant.core.jdbc.metadata; 13 14 import java.io.Serializable ; 15 16 19 public class JdbcIndex implements Serializable { 20 21 public String name; 22 public JdbcColumn[] cols; 23 public boolean unique; 24 public boolean clustered; 25 public String comment; 26 27 public JdbcIndex() { 28 } 29 30 public String toString() { 31 StringBuffer s = new StringBuffer (); 32 s.append(name); 33 s.append('('); 34 s.append(cols[0]); 35 for (int i = 1; i < cols.length; i++) { 36 s.append(','); 37 s.append(' '); 38 s.append(cols[i]); 39 } 40 s.append(')'); 41 if (unique) s.append(" unique"); 42 if (clustered) s.append(" clustered"); 43 if (cols[0].table != null) s.append(" to table " + cols[0].table.name); 44 return s.toString(); 45 } 46 47 51 public void setCols(JdbcColumn[] cols) { 52 this.cols = cols; 53 for (int i = cols.length - 1; i >= 0; i--) { 54 cols[i].partOfIndex = true; 55 } 56 } 57 58 61 public boolean hasSameColumns(JdbcIndex x) { 62 int n = cols.length; 63 if (n != x.cols.length) return false; 64 for (int i = 0; i < n; i++) { 65 if (!cols[i].equals(x.cols[i])) return false; 66 } 67 return true; 68 } 69 70 73 public boolean equals(Object o) { 74 return o instanceof JdbcIndex && hasSameColumns((JdbcIndex)o); 75 } 76 77 80 public int hashCode() { 81 int ans = 0; 82 for (int i = cols.length - 1; i >= 0; i--) { 83 if (cols[i].name != null) { 84 ans += cols[i].name.hashCode() * 29; 85 } 86 } 87 return ans; 88 } 89 90 } 91 92 93 | Popular Tags |