1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.db;
18
19
20 import javax.naming.directory.Attributes;
21 import java.math.BigInteger;
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: 159259 $
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 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 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 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 getEntryId()
75 {
76 return ( BigInteger ) 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 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 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 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 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 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 }