KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ldap > server > db > IndexRecord


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17 package org.apache.ldap.server.db;
18
19
20 import javax.naming.directory.Attributes JavaDoc;
21 import java.math.BigInteger JavaDoc;
22
23
24 /**
25  * An index key value pair based on a tuple which can optionally reference the
26  * indexed entry if one has been resusitated.
27  *
28  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
29  * @version $Rev: 169198 $
30  */

31 public class IndexRecord
32 {
33     /** The underlying BTree Tuple */
34     private final Tuple tuple = new Tuple();
35     /** The referenced entry if resusitated */
36     private Attributes JavaDoc entry = null;
37
38
39     /**
40      * Sets the key value tuple represented by this IndexRecord optionally
41      * setting the entry if one was resusitated from the master table.
42      *
43      * @param tuple the tuple for the IndexRecord
44      * @param entry the resusitated entry if any
45      */

46     public void setTuple( Tuple tuple, Attributes JavaDoc entry )
47     {
48         this.tuple.setKey( tuple.getKey() );
49         this.tuple.setValue( tuple.getValue() );
50         this.entry = entry;
51     }
52
53
54     /**
55      * Sets the key value tuple but swapping the key and the value and
56      * optionally adding the entry if one was resusitated.
57      *
58      * @param tuple the tuple for the IndexRecord
59      * @param entry the resusitated entry if any
60      */

61     public void setSwapped( Tuple tuple, Attributes JavaDoc entry )
62     {
63         this.tuple.setKey( tuple.getValue() );
64         this.tuple.setValue( tuple.getKey() );
65         this.entry = entry;
66     }
67
68
69     /**
70      * Gets the entry id for this IndexRecord.
71      *
72      * @return the id of the entry indexed
73      */

74     public BigInteger JavaDoc getEntryId()
75     {
76         return ( BigInteger JavaDoc ) tuple.getValue();
77     }
78
79
80     /**
81      * Gets the index key ( the attribute's value ) for this IndexRecord.
82      *
83      * @return the key of the entry indexed
84      */

85     public Object JavaDoc getIndexKey()
86     {
87         return tuple.getKey();
88     }
89
90
91     /**
92      * Sets the entry id.
93      *
94      * @param id the id of the entry
95      */

96     public void setEntryId( BigInteger JavaDoc id )
97     {
98         tuple.setValue( id );
99     }
100
101
102     /**
103      * Sets the index key.
104      *
105      * @param key the key of the IndexRecord
106      */

107     public void setIndexKey( Object JavaDoc key )
108     {
109         tuple.setKey( key );
110     }
111
112
113     /**
114      * Gets the entry of this IndexRecord if one was resusitated form the master
115      * table.
116      *
117      * @return the entry's attributes
118      */

119     public Attributes JavaDoc getAttributes()
120     {
121         return entry;
122     }
123
124
125     /**
126      * Sets the entry's attributes.
127      *
128      * @param entry the entry's attributes
129      */

130     public void setAttributes( Attributes JavaDoc entry )
131     {
132         this.entry = entry;
133     }
134
135
136     /**
137      * Clears the tuple key, the tuple value and the entry fields.
138      */

139     public void clear()
140     {
141         entry = null;
142         tuple.setKey( null );
143         tuple.setValue( null );
144     }
145     
146  
147     /**
148      * Utility method used to copy the contents of one IndexRecord into this
149      * IndexRecord.
150      *
151      * @param record the record whose contents we copy
152      */

153     public void copy( IndexRecord record )
154     {
155         entry = record.getAttributes();
156         tuple.setKey( record.getIndexKey() );
157         tuple.setValue( record.getEntryId() );
158     }
159 }
160
Popular Tags