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 * 019 */ 020 package org.apache.directory.server.core.partition.impl.btree.jdbm; 021 022 023 import java.util.HashSet; 024 import java.util.Set; 025 026 import org.apache.directory.server.constants.ApacheSchemaConstants; 027 import org.apache.directory.server.core.partition.Partition; 028 import org.apache.directory.server.xdbm.Index; 029 import org.apache.directory.server.xdbm.AbstractXdbmPartition; 030 import org.apache.directory.server.xdbm.search.impl.CursorBuilder; 031 import org.apache.directory.server.xdbm.search.impl.DefaultOptimizer; 032 import org.apache.directory.server.xdbm.search.impl.DefaultSearchEngine; 033 import org.apache.directory.server.xdbm.search.impl.EvaluatorBuilder; 034 import org.apache.directory.server.xdbm.search.impl.NoOpOptimizer; 035 import org.apache.directory.shared.ldap.constants.SchemaConstants; 036 import org.apache.directory.shared.ldap.entry.ServerEntry; 037 038 039 /** 040 * A {@link Partition} that stores entries in 041 * <a href="http://jdbm.sourceforge.net/">JDBM</a> database. 042 * 043 * @org.apache.xbean.XBean 044 * 045 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 046 * @version $Rev: 927146 $ 047 */ 048 public class JdbmPartition extends AbstractXdbmPartition<Long> 049 { 050 051 /** 052 * Creates a store based on JDBM B+Trees. 053 */ 054 public JdbmPartition() 055 { 056 super( new JdbmStore<ServerEntry>() ); 057 } 058 059 060 @SuppressWarnings("unchecked") 061 protected void doInit() throws Exception 062 { 063 store.setWorkingDirectory( getPartitionDir() ); 064 065 EvaluatorBuilder<Long> evaluatorBuilder = new EvaluatorBuilder<Long>( store, schemaManager ); 066 CursorBuilder<Long> cursorBuilder = new CursorBuilder<Long>( store, evaluatorBuilder ); 067 068 // setup optimizer and registries for parent 069 if ( !optimizerEnabled ) 070 { 071 optimizer = new NoOpOptimizer(); 072 } 073 else 074 { 075 optimizer = new DefaultOptimizer<ServerEntry, Long>( store ); 076 } 077 078 searchEngine = new DefaultSearchEngine<Long>( store, cursorBuilder, evaluatorBuilder, optimizer ); 079 080 // initialize the store 081 store.setCacheSize( cacheSize ); 082 store.setName( id ); 083 084 // Normalize the suffix 085 suffix.normalize( schemaManager.getNormalizerMapping() ); 086 store.setSuffixDn( suffix.getNormName() ); 087 store.setWorkingDirectory( getPartitionDir() ); 088 089 Set<Index<?, ServerEntry, Long>> userIndices = new HashSet<Index<?, ServerEntry, Long>>(); 090 091 for ( Index<?, ServerEntry, Long> obj : getIndexedAttributes() ) 092 { 093 Index<?, ServerEntry, Long> index; 094 095 if ( obj instanceof JdbmIndex<?, ?> ) 096 { 097 index = ( JdbmIndex<?, ServerEntry> ) obj; 098 } 099 else 100 { 101 index = new JdbmIndex<Object, ServerEntry>(); 102 index.setAttributeId( obj.getAttributeId() ); 103 index.setCacheSize( obj.getCacheSize() ); 104 index.setWkDirPath( obj.getWkDirPath() ); 105 } 106 107 String oid = schemaManager.getAttributeTypeRegistry().getOidByName( index.getAttributeId() ); 108 109 if ( SYS_INDEX_OIDS.contains( oid ) ) 110 { 111 if ( oid.equals( ApacheSchemaConstants.APACHE_ALIAS_AT_OID ) ) 112 { 113 store.setAliasIndex( ( Index<String, ServerEntry, Long> ) index ); 114 } 115 else if ( oid.equals( ApacheSchemaConstants.APACHE_EXISTENCE_AT_OID ) ) 116 { 117 store.setPresenceIndex( ( Index<String, ServerEntry, Long> ) index ); 118 } 119 else if ( oid.equals( ApacheSchemaConstants.APACHE_ONE_LEVEL_AT_OID ) ) 120 { 121 store.setOneLevelIndex( ( Index<Long, ServerEntry, Long> ) index ); 122 } 123 else if ( oid.equals( ApacheSchemaConstants.APACHE_N_DN_AT_OID ) ) 124 { 125 store.setNdnIndex( ( Index<String, ServerEntry, Long> ) index ); 126 } 127 else if ( oid.equals( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID ) ) 128 { 129 store.setOneAliasIndex( ( Index<Long, ServerEntry, Long> ) index ); 130 } 131 else if ( oid.equals( ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID ) ) 132 { 133 store.setSubAliasIndex( ( Index<Long, ServerEntry, Long> ) index ); 134 } 135 else if ( oid.equals( ApacheSchemaConstants.APACHE_UP_DN_AT_OID ) ) 136 { 137 store.setUpdnIndex( ( Index<String, ServerEntry, Long> ) index ); 138 } 139 else if ( oid.equals( SchemaConstants.OBJECT_CLASS_AT_OID ) ) 140 { 141 store.setObjectClassIndex( ( Index<String, ServerEntry, Long> ) index ); 142 } 143 else if ( oid.equals( SchemaConstants.ENTRY_CSN_AT_OID ) ) 144 { 145 store.setEntryCsnIndex( ( Index<String, ServerEntry, Long> ) index ); 146 } 147 else if ( oid.equals( SchemaConstants.ENTRY_UUID_AT_OID ) ) 148 { 149 store.setEntryUuidIndex( ( Index<String, ServerEntry, Long> ) index ); 150 } 151 else 152 { 153 throw new IllegalStateException( "Unrecognized system index " + oid ); 154 } 155 } 156 else 157 { 158 userIndices.add( index ); 159 } 160 161 store.setUserIndices( userIndices ); 162 } 163 164 store.init( schemaManager ); 165 } 166 167 168 public Index<String, ServerEntry, Long> getObjectClassIndex() 169 { 170 return store.getObjectClassIndex(); 171 } 172 173 174 public Index<String, ServerEntry, Long> getEntryCsnIndex() 175 { 176 return store.getEntryCsnIndex(); 177 } 178 179 180 public Index<String, ServerEntry, Long> getEntryUuidIndex() 181 { 182 return store.getEntryUuidIndex(); 183 } 184 185 }