1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.server.core.partition.impl.btree.jdbm;
22
23
24 import java.io.IOException;
25
26 import jdbm.RecordManager;
27
28 import org.apache.directory.api.ldap.model.exception.LdapException;
29 import org.apache.directory.api.ldap.model.schema.AttributeType;
30 import org.apache.directory.api.ldap.model.schema.MatchingRule;
31 import org.apache.directory.api.ldap.model.schema.SchemaManager;
32 import org.apache.directory.api.ldap.model.schema.comparators.UuidComparator;
33 import org.apache.directory.server.constants.ApacheSchemaConstants;
34 import org.apache.directory.server.i18n.I18n;
35 import org.apache.directory.server.xdbm.ParentIdAndRdn;
36 import org.apache.directory.server.xdbm.ParentIdAndRdnComparator;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40
41
42
43
44
45
46 public class JdbmRdnIndex extends JdbmIndex<ParentIdAndRdn>
47 {
48
49
50 private static final Logger LOG = LoggerFactory.getLogger( JdbmRdnIndex.class );
51
52
53 public JdbmRdnIndex()
54 {
55 super( ApacheSchemaConstants.APACHE_RDN_AT_OID, true );
56 initialized = false;
57 }
58
59
60
61
62
63 @Override
64 public void init( RecordManager recMan, SchemaManager schemaManager, AttributeType attributeType ) throws LdapException, IOException
65 {
66 LOG.debug( "Initializing an Index for attribute '{}'", attributeType.getName() );
67
68 this.attributeType = attributeType;
69
70 if ( attributeId == null )
71 {
72 setAttributeId( attributeType.getName() );
73 }
74
75 if ( this.wkDirPath == null )
76 {
77 throw new NullPointerException( "The index working directory has not be set" );
78 }
79
80
81 this.recMan = recMan;
82
83 try
84 {
85 initTables( schemaManager );
86 }
87 catch ( IOException e )
88 {
89
90 close( null );
91 throw e;
92 }
93
94 initialized = true;
95 }
96
97
98
99
100
101
102
103
104
105
106 private void initTables( SchemaManager schemaManager ) throws IOException
107 {
108 MatchingRule mr = attributeType.getEquality();
109
110 if ( mr == null )
111 {
112 throw new IOException( I18n.err( I18n.ERR_574, attributeType.getName() ) );
113 }
114
115 ParentIdAndRdnComparator<String> comp = new ParentIdAndRdnComparator<>( mr.getOid() );
116
117 UuidComparator.INSTANCE.setSchemaManager( schemaManager );
118
119 ParentIdAndRdnSerializerl/btree/jdbm/ParentIdAndRdnSerializer.html#ParentIdAndRdnSerializer">ParentIdAndRdnSerializer parentIdAndSerializer = new ParentIdAndRdnSerializer( schemaManager );
120
121 forward = new JdbmTable<ParentIdAndRdn, String>( schemaManager, attributeType.getOid() + FORWARD_BTREE,
122 recMan, comp, parentIdAndSerializer, UuidSerializer.INSTANCE );
123 reverse = new JdbmTable<String, ParentIdAndRdn>( schemaManager, attributeType.getOid() + REVERSE_BTREE,
124 recMan, UuidComparator.INSTANCE, UuidSerializer.INSTANCE, parentIdAndSerializer );
125 }
126 }