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.core.partition.impl.btree;
21
22
23 import org.apache.directory.server.core.entry.ClonedServerEntry;
24 import org.apache.directory.server.core.entry.ServerEntry;
25 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
26 import org.apache.directory.server.core.filtering.BaseEntryFilteringCursor;
27 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
28 import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
29 import org.apache.directory.server.core.interceptor.context.EntryOperationContext;
30 import org.apache.directory.server.core.interceptor.context.ListOperationContext;
31 import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
32 import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
33 import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
34 import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
35 import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
36 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
37 import org.apache.directory.server.core.partition.Partition;
38 import org.apache.directory.server.core.partition.impl.btree.gui.PartitionViewer;
39 import org.apache.directory.server.schema.registries.Registries;
40 import org.apache.directory.server.xdbm.*;
41 import org.apache.directory.server.xdbm.search.Optimizer;
42 import org.apache.directory.server.xdbm.search.SearchEngine;
43 import org.apache.directory.shared.ldap.exception.LdapContextNotEmptyException;
44 import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
45 import org.apache.directory.shared.ldap.name.LdapDN;
46 import org.apache.directory.shared.ldap.schema.AttributeType;
47
48 import javax.naming.directory.SearchControls;
49 import java.util.Collections;
50 import java.util.HashSet;
51 import java.util.Iterator;
52 import java.util.Set;
53
54
55
56
57
58
59
60
61
62 public abstract class BTreePartition implements Partition
63 {
64 protected static final Set<String> SYS_INDEX_OIDS;
65
66 static
67 {
68 Set<String> set = new HashSet<String>();
69 set.add( Store.ALIAS );
70 set.add( Store.PRESENCE );
71 set.add( Store.ONELEVEL );
72 set.add( Store.NDN );
73 set.add( Store.ONEALIAS );
74 set.add( Store.SUBALIAS );
75 set.add( Store.UPDN );
76 SYS_INDEX_OIDS = Collections.unmodifiableSet( set );
77 }
78
79
80 protected SearchEngine<ServerEntry> searchEngine;
81 protected Optimizer optimizer;
82
83 protected Registries registries;
84
85 protected String id;
86 protected int cacheSize = -1;
87 protected LdapDN suffixDn;
88 protected String suffix;
89
90
91 protected ServerEntry contextEntry;
92
93
94
95
96
97
98
99
100
101
102 protected BTreePartition()
103 {
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 public void setCacheSize( int cacheSize )
120 {
121 this.cacheSize = cacheSize;
122 }
123
124
125
126
127
128
129
130 public int getCacheSize()
131 {
132 return cacheSize;
133 }
134
135
136
137
138
139
140
141 public String getId()
142 {
143 return id;
144 }
145
146
147
148
149
150
151
152 public void setId( String id )
153 {
154 this.id = id;
155 }
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172 public abstract void setRegistries( Registries registries ) throws Exception;
173
174
175
176
177
178
179
180
181
182
183
184
185 public SearchEngine<ServerEntry> getSearchEngine()
186 {
187 return searchEngine;
188 }
189
190
191
192
193
194
195
196 public void delete( DeleteOperationContext opContext ) throws Exception
197 {
198 LdapDN dn = opContext.getDn();
199
200 Long id = getEntryId( dn.getNormName() );
201
202
203 if ( id == null )
204 {
205 throw new LdapNameNotFoundException( "Could not find entry at '" + dn + "' to delete it!" );
206 }
207
208 if ( getChildCount( id ) > 0 )
209 {
210 LdapContextNotEmptyException cnee = new LdapContextNotEmptyException( "[66] Cannot delete entry " + dn
211 + " it has children!" );
212 cnee.setRemainingName( dn );
213 throw cnee;
214 }
215
216 delete( id );
217 }
218
219
220 public abstract void add( AddOperationContext opContext ) throws Exception;
221
222
223 public abstract void modify( ModifyOperationContext opContext ) throws Exception;
224
225
226 public EntryFilteringCursor list( ListOperationContext opContext ) throws Exception
227 {
228 return new BaseEntryFilteringCursor( new ServerEntryCursorAdaptor( this,
229 list( getEntryId( opContext.getDn().getNormName() ) ) ), opContext );
230 }
231
232
233 public EntryFilteringCursor search( SearchOperationContext opContext ) throws Exception
234 {
235 SearchControls searchCtls = opContext.getSearchControls();
236 IndexCursor<Long,ServerEntry> underlying;
237
238 underlying = searchEngine.cursor(
239 opContext.getDn(),
240 opContext.getAliasDerefMode(),
241 opContext.getFilter(),
242 searchCtls );
243
244 return new BaseEntryFilteringCursor( new ServerEntryCursorAdaptor( this, underlying ), opContext );
245 }
246
247
248 public ClonedServerEntry lookup( LookupOperationContext opContext ) throws Exception
249 {
250 Long id = getEntryId( opContext.getDn().getNormName() );
251
252 if ( id == null )
253 {
254 return null;
255 }
256
257 ClonedServerEntry entry = lookup( id );
258
259 if ( ( opContext.getAttrsId() == null ) || ( opContext.getAttrsId().size() == 0 ) )
260 {
261 return entry;
262 }
263
264 for ( AttributeType attributeType : ((ServerEntry)entry.getOriginalEntry()).getAttributeTypes() )
265 {
266 if ( ! opContext.getAttrsId().contains( attributeType.getOid() ) )
267 {
268 entry.removeAttributes( attributeType );
269 }
270 }
271
272 return entry;
273 }
274
275
276 public boolean hasEntry( EntryOperationContext opContext ) throws Exception
277 {
278 return null != getEntryId( opContext.getDn().getNormName() );
279 }
280
281
282 public abstract void rename( RenameOperationContext opContext ) throws Exception;
283
284
285 public abstract void move( MoveOperationContext opContext ) throws Exception;
286
287
288 public abstract void moveAndRename( MoveAndRenameOperationContext opContext ) throws Exception;
289
290
291 public abstract void sync() throws Exception;
292
293
294 public abstract void destroy() throws Exception;
295
296
297 public abstract boolean isInitialized();
298
299
300 public void inspect() throws Exception
301 {
302 PartitionViewer viewer = new PartitionViewer( this, registries );
303 viewer.execute();
304 }
305
306
307
308
309
310
311
312
313
314 public abstract void addIndexOn( Index<Long,ServerEntry> index ) throws Exception;
315
316
317 public abstract boolean hasUserIndexOn( String attribute ) throws Exception;
318
319
320 public abstract boolean hasSystemIndexOn( String attribute ) throws Exception;
321
322
323 public abstract Index<String,ServerEntry> getPresenceIndex();
324
325
326
327
328
329
330
331
332 public abstract Index<Long,ServerEntry> getOneLevelIndex();
333
334
335
336
337
338
339
340
341 public abstract Index<Long,ServerEntry> getSubLevelIndex();
342
343
344
345
346
347
348
349
350 public abstract Index<String,ServerEntry> getUpdnIndex();
351
352
353
354
355
356
357
358
359 public abstract Index<String,ServerEntry> getNdnIndex();
360
361
362
363
364
365
366
367
368
369 public abstract Index<Long,ServerEntry> getOneAliasIndex();
370
371
372
373
374
375
376
377
378
379 public abstract Index<Long,ServerEntry> getSubAliasIndex();
380
381
382
383
384
385
386
387
388 public abstract Index<String,ServerEntry> getAliasIndex();
389
390
391
392
393
394
395
396
397
398 public abstract void setAliasIndexOn( Index<String,ServerEntry> index ) throws Exception;
399
400
401
402
403
404
405
406
407 public abstract void setPresenceIndexOn( Index<String,ServerEntry> index ) throws Exception;
408
409
410
411
412
413
414
415
416 public abstract void setOneLevelIndexOn( Index<Long,ServerEntry> index ) throws Exception;
417
418
419
420
421
422
423
424
425
426 public abstract void setUpdnIndexOn( Index<String,ServerEntry> index ) throws Exception;
427
428
429
430
431
432
433
434
435 public abstract void setNdnIndexOn( Index<String,ServerEntry> index ) throws Exception;
436
437
438
439
440
441
442
443
444
445
446 public abstract void setOneAliasIndexOn( Index<Long,ServerEntry> index ) throws Exception;
447
448
449
450
451
452
453
454
455
456
457 public abstract void setSubAliasIndexOn( Index<Long,ServerEntry> index ) throws Exception;
458
459
460 public abstract Index<?,ServerEntry> getUserIndex( String attribute ) throws Exception;
461
462
463 public abstract Index<?,ServerEntry> getSystemIndex( String attribute ) throws Exception;
464
465
466 public abstract Long getEntryId( String dn ) throws Exception;
467
468
469 public abstract String getEntryDn( Long id ) throws Exception;
470
471
472 public abstract Long getParentId( String dn ) throws Exception;
473
474
475 public abstract Long getParentId( Long childId ) throws Exception;
476
477
478
479
480
481
482
483
484
485 public abstract String getEntryUpdn( Long id ) throws Exception;
486
487
488
489
490
491
492
493
494
495 public abstract String getEntryUpdn( String dn ) throws Exception;
496
497
498 public abstract ClonedServerEntry lookup( Long id ) throws Exception;
499
500
501 public abstract void delete( Long id ) throws Exception;
502
503
504 public abstract IndexCursor<Long,ServerEntry> list( Long id ) throws Exception;
505
506
507 public abstract int getChildCount( Long id ) throws Exception;
508
509
510 public abstract void setProperty( String key, String value ) throws Exception;
511
512
513 public abstract String getProperty( String key ) throws Exception;
514
515
516 public abstract Iterator<String> getUserIndices();
517
518
519 public abstract Iterator<String> getSystemIndices();
520
521
522
523
524
525
526
527
528
529
530 public abstract int count() throws Exception;
531 }