KickJava   Java API By Example, From Geeks To Geeks.

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


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: Index.java,v 1.3 2003/02/25 06:55:15 jackknifebarber Exp $
9  */

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 JavaDoc 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 JavaDoc toString()
101     {
102         return getColumnList();
103     }
104 }
105
Popular Tags