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: CandidateKey.java,v 1.2 2002/10/17 21:00:54 pierreg0 Exp $
09: */
10:
11: package com.triactive.jdo.store;
12:
13: import javax.jdo.JDOFatalInternalException;
14:
15: class CandidateKey extends Key {
16: public CandidateKey(BaseTable table) {
17: super (table);
18: }
19:
20: public void setColumn(int seq, Column col) {
21: assertSameTable(col);
22:
23: setMinSize(columns, seq + 1);
24:
25: if (columns.get(seq) != null)
26: throw new JDOFatalInternalException("Key part #" + seq
27: + " for " + table + " already set");
28:
29: columns.set(seq, col);
30: }
31:
32: public void addColumn(Column col) {
33: assertSameTable(col);
34:
35: columns.add(col);
36: }
37:
38: public int size() {
39: return columns.size();
40: }
41:
42: public int hashCode() {
43: return columns.hashCode();
44: }
45:
46: public boolean equals(Object o) {
47: if (o == this )
48: return true;
49:
50: if (!(o instanceof CandidateKey))
51: return false;
52:
53: CandidateKey pk = (CandidateKey) o;
54:
55: return columns.equals(pk.columns);
56: }
57:
58: public String toString() {
59: StringBuffer s = new StringBuffer("UNIQUE ")
60: .append(getColumnList(columns));
61:
62: return s.toString();
63: }
64: }
|