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.File;
25 import java.io.IOException;
26
27 import jdbm.RecordManager;
28
29 import org.apache.directory.api.ldap.model.exception.LdapException;
30 import org.apache.directory.api.ldap.model.name.Dn;
31 import org.apache.directory.api.ldap.model.schema.AttributeType;
32 import org.apache.directory.api.ldap.model.schema.MatchingRule;
33 import org.apache.directory.api.ldap.model.schema.SchemaManager;
34 import org.apache.directory.api.ldap.model.schema.comparators.UuidComparator;
35 import org.apache.directory.server.i18n.I18n;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39
40
41
42
43
44
45 public class JdbmDnIndex extends JdbmIndex<Dn>
46 {
47
48
49 private static final Logger LOG = LoggerFactory.getLogger( JdbmDnIndex.class );
50
51
52 public JdbmDnIndex( String oid )
53 {
54 super( oid, true );
55 initialized = false;
56 }
57
58
59
60
61
62 @Override
63 public void init( RecordManager recMan, SchemaManager schemaManager, AttributeType attributeType ) throws LdapException, IOException
64 {
65 LOG.debug( "Initializing an Index for attribute '{}'", attributeType.getName() );
66
67 this.attributeType = attributeType;
68
69 if ( attributeId == null )
70 {
71 setAttributeId( attributeType.getName() );
72 }
73
74 if ( this.wkDirPath == null )
75 {
76 throw new NullPointerException( "The index working directory has not be set" );
77 }
78
79 String path = new File( this.wkDirPath, attributeType.getOid() ).getAbsolutePath();
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 DnSerializerComparator/core/partition/impl/btree/jdbm/DnSerializerComparator.html#DnSerializerComparator">DnSerializerComparator comp = new DnSerializerComparator( mr.getOid() );
116
117 UuidComparator.INSTANCE.setSchemaManager( schemaManager );
118
119 DnSerializerer/core/partition/impl/btree/jdbm/DnSerializer.html#DnSerializer">DnSerializer dnSerializer = new DnSerializer( schemaManager );
120
121 forward = new JdbmTable<Dn, String>( schemaManager, attributeType.getOid() + FORWARD_BTREE,
122 recMan, comp, dnSerializer, UuidSerializer.INSTANCE );
123 reverse = new JdbmTable<String, Dn>( schemaManager, attributeType.getOid() + REVERSE_BTREE,
124 recMan, UuidComparator.INSTANCE, UuidSerializer.INSTANCE, dnSerializer );
125 }
126 }