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.avl.AvlPartition;
30  import org.apache.directory.server.xdbm.Index;
31  import org.apache.directory.server.xdbm.impl.avl.AvlIndex;
32  
33  
34  /**
35   * A factory used to generate {@link AvlPartition}s.
36   *
37   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
38   */
39  public class AvlPartitionFactory implements PartitionFactory
40  {
41  
42      /**
43       * {@inheritDoc}
44       */
45      public AvlPartition createPartition( SchemaManager schemaManager, DnFactory dnFactory, String id, String suffix,
46          int cacheSize,
47          File workingDirectory )
48          throws Exception
49      {
50          AvlPartitione/partition/impl/avl/AvlPartition.html#AvlPartition">AvlPartition partition = new AvlPartition( schemaManager, dnFactory );
51          partition.setId( id );
52          partition.setSuffixDn( new Dn( suffix ) );
53          partition.setCacheSize( 500 );
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 AvlPartition ) )
66          {
67              throw new IllegalArgumentException( "Partition must be a AvlPartition" );
68          }
69  
70          AvlPartition./../org/apache/directory/server/core/partition/impl/avl/AvlPartition.html#AvlPartition">AvlPartition avlPartition = ( AvlPartition ) partition;
71          Set<Index<?, String>> indexedAttributes = avlPartition.getIndexedAttributes();
72  
73          AvlIndex<Object> index = new AvlIndex<>( attributeId, false );
74  
75          indexedAttributes.add( index );
76          avlPartition.setIndexedAttributes( indexedAttributes );
77      }
78  
79  }