001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.directory.server.core.factory; 020 021 022import java.io.File; 023import java.util.Set; 024 025import org.apache.directory.api.ldap.model.name.Dn; 026import org.apache.directory.api.ldap.model.schema.SchemaManager; 027import org.apache.directory.server.core.api.DnFactory; 028import org.apache.directory.server.core.api.partition.Partition; 029import org.apache.directory.server.core.partition.impl.avl.AvlPartition; 030import org.apache.directory.server.xdbm.Index; 031import org.apache.directory.server.xdbm.impl.avl.AvlIndex; 032 033 034/** 035 * A factory used to generate {@link AvlPartition}s. 036 * 037 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 038 */ 039public class AvlPartitionFactory implements PartitionFactory 040{ 041 042 /** 043 * {@inheritDoc} 044 */ 045 public AvlPartition createPartition( SchemaManager schemaManager, DnFactory dnFactory, String id, String suffix, 046 int cacheSize, 047 File workingDirectory ) 048 throws Exception 049 { 050 AvlPartition partition = new AvlPartition( schemaManager, dnFactory ); 051 partition.setId( id ); 052 partition.setSuffixDn( new Dn( suffix ) ); 053 partition.setCacheSize( 500 ); 054 partition.setPartitionPath( workingDirectory.toURI() ); 055 056 return partition; 057 } 058 059 060 /** 061 * {@inheritDoc} 062 */ 063 public void addIndex( Partition partition, String attributeId, int cacheSize ) throws Exception 064 { 065 if ( !( partition instanceof AvlPartition ) ) 066 { 067 throw new IllegalArgumentException( "Partition must be a AvlPartition" ); 068 } 069 070 AvlPartition avlPartition = ( AvlPartition ) partition; 071 Set<Index<?, String>> indexedAttributes = avlPartition.getIndexedAttributes(); 072 073 AvlIndex<Object> index = new AvlIndex<>( attributeId, false ); 074 075 indexedAttributes.add( index ); 076 avlPartition.setIndexedAttributes( indexedAttributes ); 077 } 078 079}