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  package org.apache.directory.server.core.factory;
20  
21  
22  import java.io.File;
23  import java.util.Set;
24  
25  import org.apache.directory.api.ldap.model.name.Dn;
26  import org.apache.directory.api.ldap.model.schema.SchemaManager;
27  import org.apache.directory.server.core.api.DnFactory;
28  import org.apache.directory.server.core.api.partition.Partition;
29  import org.apache.directory.server.core.partition.impl.btree.mavibot.MavibotIndex;
30  import org.apache.directory.server.core.partition.impl.btree.mavibot.MavibotPartition;
31  import org.apache.directory.server.xdbm.Index;
32  
33  
34  /**
35   * A factory used to generate {@link MavibotPartition}s.
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   */
39  public class MavibotPartitionFactory implements PartitionFactory
40  {
41  
42      /**
43       * {@inheritDoc}
44       */
45      public MavibotPartition createPartition( SchemaManager schemaManager, DnFactory dnFactory, String id,
46          String suffix, int cacheSize,
47          File workingDirectory )
48          throws Exception
49      {
50          MavibotPartitionrtition/impl/btree/mavibot/MavibotPartition.html#MavibotPartition">MavibotPartition partition = new MavibotPartition( schemaManager, dnFactory );
51          partition.setId( id );
52          partition.setSuffixDn( new Dn( suffix ) );
53          partition.setCacheSize( cacheSize );
54          partition.setPartitionPath( workingDirectory.toURI() );
55  
56          return partition;
57      }
58  
59  
60      /**
61       * {@inheritDoc}
62       */
63      public void addIndex( Partition partition, String attributeId, int cacheSize ) throws Exception
64      {
65          if ( !( partition instanceof MavibotPartition ) )
66          {
67              throw new IllegalArgumentException( "Partition must be a MavibotPartition" );
68          }
69  
70          MavibotPartition/apache/directory/server/core/partition/impl/btree/mavibot/MavibotPartition.html#MavibotPartition">MavibotPartition mavibotPartition = ( MavibotPartition ) partition;
71          Set<Index<?, String>> indexedAttributes = mavibotPartition.getIndexedAttributes();
72  
73          MavibotIndex<Object> index = new MavibotIndex<>( attributeId, false );
74          index.setCacheSize( cacheSize );
75  
76          indexedAttributes.add( index );
77          mavibotPartition.setIndexedAttributes( indexedAttributes );
78      }
79  }