01: /*
02: * Copyright 2002 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: Index.java,v 1.3 2003/02/25 06:55:15 jackknifebarber Exp $
09: */
10:
11: package com.triactive.jdo.store;
12:
13: import javax.jdo.JDOFatalInternalException;
14:
15: class Index extends Key {
16: private final boolean isUnique;
17:
18: public Index(BaseTable table, boolean isUnique) {
19: super (table);
20:
21: this .isUnique = isUnique;
22: }
23:
24: public Index(CandidateKey ck) {
25: super (ck.getTable());
26:
27: isUnique = true;
28: columns.addAll(ck.getColumns());
29: }
30:
31: public Index(ForeignKey fk) {
32: super (fk.getTable());
33:
34: isUnique = false;
35: columns.addAll(fk.getColumns());
36: }
37:
38: public boolean getUnique() {
39: return isUnique;
40: }
41:
42: public void setColumn(int seq, Column col) {
43: assertSameTable(col);
44:
45: setMinSize(columns, seq + 1);
46:
47: if (columns.get(seq) != null)
48: throw new JDOFatalInternalException("Index part #" + seq
49: + " for " + table + " already set");
50:
51: columns.set(seq, col);
52: }
53:
54: public void addColumn(Column col) {
55: assertSameTable(col);
56:
57: columns.add(col);
58: }
59:
60: public int size() {
61: return columns.size();
62: }
63:
64: public int hashCode() {
65: return (isUnique ? 0 : 1) ^ columns.hashCode();
66: }
67:
68: public boolean equals(Object o) {
69: if (o == this )
70: return true;
71:
72: if (!(o instanceof Index))
73: return false;
74:
75: Index idx = (Index) o;
76:
77: return isUnique == idx.isUnique && columns.equals(idx.columns);
78: }
79:
80: public String toString() {
81: return getColumnList();
82: }
83: }
|