KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > CandidateKey


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: CandidateKey.java,v 1.2 2002/10/17 21:00:54 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import javax.jdo.JDOFatalInternalException;
14
15
16 class CandidateKey extends Key
17 {
18     public CandidateKey(BaseTable table)
19     {
20         super(table);
21     }
22
23
24     public void setColumn(int seq, Column col)
25     {
26         assertSameTable(col);
27
28         setMinSize(columns, seq + 1);
29
30         if (columns.get(seq) != null)
31             throw new JDOFatalInternalException("Key part #" + seq + " for " + table + " already set");
32
33         columns.set(seq, col);
34     }
35
36
37     public void addColumn(Column col)
38     {
39         assertSameTable(col);
40
41         columns.add(col);
42     }
43
44
45     public int size()
46     {
47         return columns.size();
48     }
49
50
51     public int hashCode()
52     {
53         return columns.hashCode();
54     }
55
56
57     public boolean equals(Object JavaDoc o)
58     {
59         if (o == this)
60             return true;
61
62         if (!(o instanceof CandidateKey))
63             return false;
64
65         CandidateKey pk = (CandidateKey)o;
66
67         return columns.equals(pk.columns);
68     }
69
70
71     public String JavaDoc toString()
72     {
73         StringBuffer JavaDoc s = new StringBuffer JavaDoc("UNIQUE ").append(getColumnList(columns));
74
75         return s.toString();
76     }
77 }
78
Popular Tags