You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2006/12/11 05:05:17 UTC

svn commit: r485486 - in /directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree: BTreePartition.java jdbm/JdbmPartition.java

Author: akarasulu
Date: Sun Dec 10 20:05:16 2006
New Revision: 485486

URL: http://svn.apache.org/viewvc?view=rev&rev=485486
Log:
Changes ...

 o centralized access to attributeTypeRegistry and oidRegistry
   by making them into protected members in BTreePartition
 o added method to reset the registries used
 o cleaned up lookups for objectClass AT and alias AT


Modified:
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java
    directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java?view=diff&rev=485486&r1=485485&r2=485486
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java Sun Dec 10 20:05:16 2006
@@ -41,6 +41,7 @@
 import org.apache.directory.server.core.partition.impl.btree.gui.PartitionViewer;
 import org.apache.directory.server.core.schema.AttributeTypeRegistry;
 import org.apache.directory.server.core.schema.OidRegistry;
+import org.apache.directory.server.core.schema.Registries;
 import org.apache.directory.shared.ldap.exception.LdapContextNotEmptyException;
 import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
 import org.apache.directory.shared.ldap.filter.ExprNode;
@@ -66,7 +67,10 @@
      * the search engine used to search the database
      */
     private SearchEngine searchEngine = null;
-    private AttributeTypeRegistry attributeTypeRegistry = null;
+    private Optimizer optimizer = new NoOpOptimizer();
+    
+    protected AttributeTypeRegistry attributeTypeRegistry = null;
+    protected OidRegistry oidRegistry = null;
 
 
     // ------------------------------------------------------------------------
@@ -80,28 +84,36 @@
     {
     }
 
+    
+    /**
+     * Allows for schema entity registries to be swapped out during runtime.  This is 
+     * primarily here to facilitate the swap out of a temporary bootstrap registry.  
+     * Registry changes require swapping out the search engine used by a partition 
+     * since the registries are used by elements in the search engine.
+     * 
+     * @param registries the schema entity registries
+     */
+    public void setRegistries( Registries registries )
+    {
+        attributeTypeRegistry = registries.getAttributeTypeRegistry();
+        oidRegistry = registries.getOidRegistry();
+        ExpressionEvaluator evaluator = new ExpressionEvaluator( this, oidRegistry, attributeTypeRegistry );
+        ExpressionEnumerator enumerator = new ExpressionEnumerator( this, attributeTypeRegistry, evaluator );
+        this.searchEngine = new DefaultSearchEngine( this, evaluator, enumerator, optimizer );
+    }
+    
 
     public void init( DirectoryServiceConfiguration factoryCfg, PartitionConfiguration cfg )
         throws NamingException
     {
-        attributeTypeRegistry = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry();
-        OidRegistry oidRegistry = factoryCfg.getGlobalRegistries().getOidRegistry();
-        ExpressionEvaluator evaluator = new ExpressionEvaluator( this, oidRegistry, attributeTypeRegistry );
-        ExpressionEnumerator enumerator = new ExpressionEnumerator( this, attributeTypeRegistry, evaluator );
         BTreePartitionConfiguration btConfig = BTreePartitionConfiguration.convert( cfg );
-        
-        
-        Optimizer optimizer;
         if ( btConfig.isOptimizerEnabled() )
         {
             optimizer = new DefaultOptimizer( this );
         }
-        else
-        {
-            optimizer = new NoOpOptimizer();
-        }
-        
-        this.searchEngine = new DefaultSearchEngine( this, evaluator, enumerator, optimizer );
+
+        // Call this ONLY after trying to override the optimizer default above
+        setRegistries( factoryCfg.getGlobalRegistries() );
 
         Set<String> sysOidSet = new HashSet<String>();
         sysOidSet.add( Oid.EXISTANCE );

Modified: directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java?view=diff&rev=485486&r1=485485&r2=485486
==============================================================================
--- directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java (original)
+++ directory/trunks/apacheds/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java Sun Dec 10 20:05:16 2006
@@ -53,8 +53,6 @@
 import org.apache.directory.server.core.partition.impl.btree.IndexNotFoundException;
 import org.apache.directory.server.core.partition.impl.btree.IndexRecord;
 import org.apache.directory.server.core.partition.impl.btree.MutableBTreePartitionConfiguration;
-import org.apache.directory.server.core.schema.AttributeTypeRegistry;
-import org.apache.directory.server.core.schema.OidRegistry;
 
 import org.apache.directory.shared.ldap.exception.LdapAuthenticationNotSupportedException;
 import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
@@ -114,10 +112,11 @@
     /** a system index on aliasedObjectName attribute */
     private Index aliasIdx;
     
-    private OidRegistry oidRegistry;
-    private AttributeTypeRegistry attrRegistry;
     private BTreePartitionConfiguration cfg;
 
+    private static AttributeType OBJECT_CLASS_AT;
+    private static AttributeType ALIAS_AT;
+    
 
     // ------------------------------------------------------------------------
     // C O N S T R U C T O R S
@@ -144,9 +143,13 @@
         }
         
         oidRegistry = factoryCfg.getGlobalRegistries().getOidRegistry();
-        attrRegistry = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry();
+        attributeTypeRegistry = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry();
+
+        OBJECT_CLASS_AT = attributeTypeRegistry.lookup( "objectClass" );
+        ALIAS_AT = attributeTypeRegistry.lookup( Partition.ALIAS_ATTRIBUTE );
+        
         this.upSuffix = new LdapDN( cfg.getSuffix() );
-        this.normSuffix = LdapDN.normalize( upSuffix, attrRegistry.getNormalizerMapping() );
+        this.normSuffix = LdapDN.normalize( upSuffix, attributeTypeRegistry.getNormalizerMapping() );
 
         File workingDirectory = new File( factoryCfg.getStartupConfiguration().getWorkingDirectory().getPath()
             + File.separator + cfg.getName() );
@@ -674,7 +677,7 @@
 
         // Access aliasedObjectName, normalize it and generate the Name 
         normalizedAliasTargetDn = new LdapDN( aliasTarget );
-        normalizedAliasTargetDn.normalize( attrRegistry.getNormalizerMapping() );
+        normalizedAliasTargetDn.normalize( attributeTypeRegistry.getNormalizerMapping() );
 
         /*
          * Check For Cycles
@@ -749,8 +752,6 @@
         }
 
         // Add the alias to the simple alias index
-        // TODO should we be adding aliasTarget which is not normalized or 
-        //      should we be adding targetDn.toNormName()
         aliasIdx.add( normalizedAliasTargetDn.getNormName(), aliasId );
 
         /*
@@ -823,8 +824,7 @@
             throw new LdapNameNotFoundException( "Id for parent '" + parentDn + "' not found!" );
         }
 
-        AttributeType octype = attrRegistry.lookup( "objectClass" );
-        Attribute objectClass = ServerUtils.getAttribute( octype, entry );
+        Attribute objectClass = ServerUtils.getAttribute( OBJECT_CLASS_AT, entry );
 
         if ( objectClass == null )
         {
@@ -837,8 +837,7 @@
 
         if ( objectClass.contains( Partition.ALIAS_OBJECT ) )
         {
-            AttributeType aliasType = attrRegistry.lookup( Partition.ALIAS_ATTRIBUTE );
-            Attribute aliasAttr = ServerUtils.getAttribute( aliasType, entry );
+            Attribute aliasAttr = ServerUtils.getAttribute( ALIAS_AT, entry );
             addAliasIndices( id, normName, ( String ) aliasAttr.get() );
         }
 
@@ -892,8 +891,7 @@
         BigInteger parentId = getParentId( id );
         NamingEnumeration attrs = entry.getIDs();
 
-        AttributeType octype = attrRegistry.lookup( "objectClass" );
-        Attribute objectClass = ServerUtils.getAttribute( octype, entry );
+        Attribute objectClass = ServerUtils.getAttribute( OBJECT_CLASS_AT, entry );
         if ( objectClass.contains( Partition.ALIAS_OBJECT ) )
         {
             dropAliasIndices( id );
@@ -1083,7 +1081,7 @@
         }
 
         // add all the values in mods to the same attribute in the entry
-        AttributeType type = attrRegistry.lookup( modsOid );
+        AttributeType type = attributeTypeRegistry.lookup( modsOid );
         Attribute entryAttrToAddTo = ServerUtils.getAttribute( type, entry );
 
         if ( entryAttrToAddTo == null )
@@ -1138,7 +1136,7 @@
             }
         }
 
-        AttributeType attrType = attrRegistry.lookup( modsOid );
+        AttributeType attrType = attributeTypeRegistry.lookup( modsOid );
         /*
          * If there are no attribute values in the modifications then this 
          * implies the compelete removal of the attribute from the entry. Else
@@ -1354,7 +1352,7 @@
          */
 
         String newRdnAttrOid = oidRegistry.getOid( newRdnAttr );
-        AttributeType newRdnAttrType = attrRegistry.lookup( newRdnAttrOid );
+        AttributeType newRdnAttrType = attributeTypeRegistry.lookup( newRdnAttrOid );
         Attribute rdnAttr = ServerUtils.getAttribute( newRdnAttrType, entry );
         if ( rdnAttr == null )
         {
@@ -1401,7 +1399,7 @@
             String oldRdnAttr = NamespaceTools.getRdnAttribute( oldRdn );
             String oldRdnAttrOid = oidRegistry.getOid( oldRdnAttr );
             String oldRdnValue = NamespaceTools.getRdnValue( oldRdn );
-            AttributeType oldRdnAttrType = attrRegistry.lookup( oldRdnAttrOid );
+            AttributeType oldRdnAttrType = attributeTypeRegistry.lookup( oldRdnAttrOid );
             
             ServerUtils.getAttribute( oldRdnAttrType, entry ).remove( oldRdnValue );
 
@@ -1468,7 +1466,7 @@
         // Now we can handle the appropriate name indices for all cases
         ndnIdx.drop( id );
         
-        LdapDN normalizedDn = LdapDN.normalize( updn, attrRegistry.getNormalizerMapping() );
+        LdapDN normalizedDn = LdapDN.normalize( updn, attributeTypeRegistry.getNormalizerMapping() );
         ndnIdx.add( ndnIdx.getNormalized( normalizedDn.toNormName() ), id );
 
         updnIdx.drop( id );