View Javadoc
1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  package org.apache.directory.server.core.partition.impl.btree.mavibot;
21  
22  
23  import java.io.IOException;
24  
25  import org.apache.directory.api.ldap.model.exception.LdapException;
26  import org.apache.directory.api.ldap.model.name.Dn;
27  import org.apache.directory.api.ldap.model.schema.AttributeType;
28  import org.apache.directory.api.ldap.model.schema.MatchingRule;
29  import org.apache.directory.api.ldap.model.schema.SchemaManager;
30  import org.apache.directory.api.ldap.model.schema.comparators.UuidComparator;
31  import org.apache.directory.mavibot.btree.serializer.StringSerializer;
32  import org.apache.directory.server.i18n.I18n;
33  import org.slf4j.Logger;
34  import org.slf4j.LoggerFactory;
35  
36  
37  /**
38   * A special index which stores DN objects.
39   *
40   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
41   */
42  public class MavibotDnIndex extends MavibotIndex<Dn>
43  {
44  
45      /** A logger for this class */
46      private static final Logger LOG = LoggerFactory.getLogger( MavibotDnIndex.class );
47  
48  
49      public MavibotDnIndex( String oid )
50      {
51          super( oid, true );
52          initialized = false;
53      }
54  
55  
56      /**
57       * {@inheritDoc}
58       */
59      @Override
60      public void init( SchemaManager schemaManager, AttributeType attributeType ) throws LdapException, IOException
61      {
62          LOG.debug( "Initializing an Index for attribute '{}'", attributeType.getName() );
63  
64          this.attributeType = attributeType;
65  
66          if ( attributeId == null )
67          {
68              setAttributeId( attributeType.getName() );
69          }
70  
71          if ( this.wkDirPath == null )
72          {
73              throw new NullPointerException( "The index working directory has not be set" );
74          }
75  
76          try
77          {
78              initTables( schemaManager );
79          }
80          catch ( IOException e )
81          {
82              // clean up
83              close( null );
84              throw e;
85          }
86  
87          initialized = true;
88      }
89  
90  
91      private void initTables( SchemaManager schemaManager ) throws IOException
92      {
93          MatchingRule mr = attributeType.getEquality();
94  
95          if ( mr == null )
96          {
97              throw new IOException( I18n.err( I18n.ERR_574, attributeType.getName() ) );
98          }
99  
100         /*
101          * The forward key/value map stores attribute values to master table
102          * primary keys.  A value for an attribute can occur several times in
103          * different entries so the forward map can have more than one value.
104          */
105         UuidComparator.INSTANCE.setSchemaManager( schemaManager );
106 
107         DnSerializerer/core/partition/impl/btree/mavibot/DnSerializer.html#DnSerializer">DnSerializer dnSerializer = new DnSerializer();
108 
109         String forwardTableName = attributeType.getOid() + FORWARD_BTREE;
110         forward = new MavibotTable<Dn, String>( recordMan, schemaManager, forwardTableName, dnSerializer,
111             StringSerializer.INSTANCE, true );
112 
113         String reverseTableName = attributeType.getOid() + REVERSE_BTREE;
114         reverse = new MavibotTable<String, Dn>( recordMan, schemaManager, reverseTableName, StringSerializer.INSTANCE,
115             dnSerializer, !attributeType.isSingleValued() );
116     }
117 }