1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.xdbm.search.cursor;
21
22
23 import java.io.IOException;
24
25 import org.apache.directory.api.ldap.model.constants.Loggers;
26 import org.apache.directory.api.ldap.model.cursor.Cursor;
27 import org.apache.directory.api.ldap.model.cursor.CursorException;
28 import org.apache.directory.api.ldap.model.exception.LdapException;
29 import org.apache.directory.server.core.api.partition.PartitionTxn;
30 import org.apache.directory.server.core.partition.impl.btree.IndexCursorAdaptor;
31 import org.apache.directory.server.xdbm.AbstractIndexCursor;
32 import org.apache.directory.server.xdbm.IndexEntry;
33 import org.apache.directory.server.xdbm.Store;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37
38
39
40
41
42
43 public class AllEntriesCursor extends AbstractIndexCursor<String>
44 {
45
46 private static final Logger LOG_CURSOR = LoggerFactory.getLogger( Loggers.CURSOR_LOG.getName() );
47
48
49 private static final boolean IS_DEBUG = LOG_CURSOR.isDebugEnabled();
50
51
52 private IndexEntry<String, String> indexEntry = new IndexEntry<>();
53
54
55 private final Cursor<IndexEntry<String, String>> wrapped;
56
57
58
59
60
61 protected String getUnsupportedMessage()
62 {
63 return UNSUPPORTED_MSG;
64 }
65
66
67
68
69
70
71
72
73
74 public AllEntriesCursor( PartitionTxn partitionTxn, Store store ) throws LdapException
75 {
76 if ( IS_DEBUG )
77 {
78 LOG_CURSOR.debug( "Creating AllEntriesCursor {}", this );
79 }
80
81 this.partitionTxn = partitionTxn;
82
83
84 wrapped = new IndexCursorAdaptor( partitionTxn, store.getMasterTable().cursor(), true );
85 }
86
87
88
89
90
91 @Override
92 public void after( IndexEntry<String, String> indexEntry ) throws LdapException, CursorException
93 {
94 checkNotClosed();
95 }
96
97
98
99
100
101 public void afterLast() throws LdapException, CursorException
102 {
103 checkNotClosed();
104
105 wrapped.afterLast();
106 }
107
108
109
110
111
112 @Override
113 public boolean available()
114 {
115 return wrapped.available();
116 }
117
118
119
120
121
122 @Override
123 public void before( IndexEntry<String, String> indexEntry ) throws LdapException, CursorException
124 {
125 checkNotClosed();
126 }
127
128
129
130
131
132 public void beforeFirst() throws LdapException, CursorException
133 {
134 checkNotClosed();
135
136 wrapped.beforeFirst();
137 }
138
139
140
141
142
143 public boolean first() throws LdapException, CursorException
144 {
145 checkNotClosed();
146
147 return wrapped.first();
148 }
149
150
151
152
153
154 public IndexEntry<String, String> get() throws CursorException
155 {
156 checkNotClosed();
157
158
159
160
161 IndexEntry<?, String> wrappedEntry = wrapped.get();
162 indexEntry.setId( ( String ) wrappedEntry.getKey() );
163 indexEntry.setKey( ( String ) wrappedEntry.getKey() );
164 indexEntry.setEntry( null );
165
166 return indexEntry;
167 }
168
169
170
171
172
173 public boolean last() throws LdapException, CursorException
174 {
175 checkNotClosed();
176
177 return wrapped.last();
178 }
179
180
181
182
183
184 @Override
185 public boolean next() throws LdapException, CursorException
186 {
187 checkNotClosed();
188
189 return wrapped.next();
190 }
191
192
193
194
195
196 @Override
197 public boolean previous() throws LdapException, CursorException
198 {
199 checkNotClosed();
200
201 return wrapped.previous();
202 }
203
204
205
206
207
208 @Override
209 public void close() throws IOException
210 {
211 if ( IS_DEBUG )
212 {
213 LOG_CURSOR.debug( "Closing AllEntriesCursor {}", this );
214 }
215
216 wrapped.close();
217 }
218
219
220
221
222
223 @Override
224 public void close( Exception cause ) throws IOException
225 {
226 if ( IS_DEBUG )
227 {
228 LOG_CURSOR.debug( "Closing AllEntriesCursor {}", this );
229 }
230
231 wrapped.close( cause );
232 }
233
234
235
236
237
238 @Override
239 public String toString( String tabs )
240 {
241 StringBuilder sb = new StringBuilder();
242
243 sb.append( tabs ).append( "AllEntriesCursor (" );
244
245 if ( available() )
246 {
247 sb.append( "available)" );
248 }
249 else
250 {
251 sb.append( "absent)" );
252 }
253
254 sb.append( " :\n" );
255
256 sb.append( wrapped.toString( tabs + " " ) );
257
258 return sb.toString();
259 }
260
261
262
263
264
265 public String toString()
266 {
267 return toString( "" );
268 }
269 }