directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r412916 - in /directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core: ./ event/ partition/impl/btree/ partition/impl/btree/gui/ partition/impl/btree/jdbm/
Date Fri, 09 Jun 2006 03:54:26 GMT
Author: akarasulu
Date: Thu Jun  8 20:54:25 2006
New Revision: 412916

URL: http://svn.apache.org/viewvc?rev=412916&view=rev
Log:
fixing some systemic issues with using OID now in JDBM partition

Added:
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/ServerUtils.java
Modified:
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/DirectoryServiceListener.java
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeDirectoryPartition.java
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/EntryDialog.java
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/IndexDialog.java
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDirectoryPartition.java
    directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java

Modified: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/DirectoryServiceListener.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/DirectoryServiceListener.java?rev=412916&r1=412915&r2=412916&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/DirectoryServiceListener.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/DirectoryServiceListener.java
Thu Jun  8 20:54:25 2006
@@ -24,7 +24,7 @@
  * An event handler that listens to the changes occurs to
  * {@link DirectoryService}.
  * 
- * @author The Apache Directory Project
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
 public interface DirectoryServiceListener

Added: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/ServerUtils.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/ServerUtils.java?rev=412916&view=auto
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/ServerUtils.java
(added)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/ServerUtils.java
Thu Jun  8 20:54:25 2006
@@ -0,0 +1,91 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.directory.server.core;
+
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+
+import org.apache.directory.shared.ldap.schema.AttributeType;
+
+
+/**
+ * A central place to aggregate functionality used throughout the server
+ * in various subsystems yet the code here is server specific hence why 
+ * it's not placed in shared-ldap.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ServerUtils
+{
+    /**
+     * Efficient server side means to perform a lookup of an attribute
+     * within an entry.  Simple lookups by name may fail if the user provided 
+     * the attribute identifier in any way other than the common alias for 
+     * the attribute.  We need to check for all aliases and the OID.
+     * 
+     * @param type the attributeType containing the OID and aliases we need
+     * @param entry the entry with user provided attribute IDENTIFIERS 
+     * @return the attribute if it is present
+     * @throws NamingException if there are failures while accessing the 
+     * attributes object
+     */
+    public static Attribute getAttribute( AttributeType type, Attributes entry ) throws NamingException
+    {
+        Attribute attr = entry.get( type.getOid() );
+        if ( attr == null )
+        {
+            String[] aliases = type.getNames();
+            for ( int ii = 0; ii < aliases.length; ii++ )
+            {
+                attr = entry.get( aliases[ii] );
+                if ( attr != null )
+                {
+                    return attr;
+                }
+            }
+        }
+        return attr;
+    }
+
+
+    public static Attribute removeAttribute( AttributeType type, Attributes entry ) throws
NamingException
+    {
+        Attribute attr = entry.get( type.getOid() );
+        if ( attr == null )
+        {
+            String[] aliases = type.getNames();
+            for ( int ii = 0; ii < aliases.length; ii++ )
+            {
+                attr = entry.get( aliases[ii] );
+                if ( attr != null )
+                {
+                    return entry.remove( attr.getID() );
+                }
+            }
+        }
+        
+        if ( attr == null )
+        {
+            return null;
+        }
+        
+        return entry.remove( attr.getID() );
+    }
+}

Modified: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java?rev=412916&r1=412915&r2=412916&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/event/LeafEvaluator.java
Thu Jun  8 20:54:25 2006
@@ -24,6 +24,7 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 
+import org.apache.directory.server.core.ServerUtils;
 import org.apache.directory.server.core.schema.AttributeTypeRegistry;
 import org.apache.directory.server.core.schema.OidRegistry;
 import org.apache.directory.shared.ldap.NotImplementedException;
@@ -138,7 +139,8 @@
         String attrId = node.getAttribute();
 
         // get the attribute associated with the node
-        Attribute attr = getAttributeByOid( attrId, entry );
+        AttributeType type = attributeTypeRegistry.lookup( oidRegistry.getOid( attrId ) );
+        Attribute attr = ServerUtils.getAttribute( type, entry );
 
         // If we do not have the attribute just return false
         if ( null == attr )
@@ -206,37 +208,12 @@
             return false;
         }
 
-        return null != getAttributeByOid( attrId, entry );
+        AttributeType type = attributeTypeRegistry.lookup( oidRegistry.getOid( attrId ) );
+        return null != ServerUtils.getAttribute( type, entry );
     }
 
 
     /**
-     * Iterates through all attributes checking to see if the id corresponds to 
-     * the attribute's OID.  Once a match is found it is returned shorting the 
-     * loop.
-     * 
-     * @param attributeOid the OID of the attribute
-     * @param entry the attributes of the entry
-     * @return the Attribute corresponding to the OID
-     * @throws NamingException 
-     */
-    private Attribute getAttributeByOid( String attributeOid, Attributes entry ) throws NamingException
-    {
-        String matchForOid = this.oidRegistry.getOid( attributeOid );
-        for ( NamingEnumeration ii = entry.getIDs(); ii.hasMore(); /**/ )
-        {
-            String id = ( String ) ii.next();
-            String oid = oidRegistry.getOid( id );
-            if ( oid.equals( matchForOid     ) )
-            {
-                return entry.get( id );
-            }
-        }
-        return null;
-    }
-    
-
-    /**
      * Evaluates a simple equality attribute value assertion on a perspective
      * candidate.
      *
@@ -251,7 +228,8 @@
         Comparator comparator = getComparator( node.getAttribute() );
 
         // get the attribute associated with the node
-        Attribute attr = getAttributeByOid( node.getAttribute(), entry );
+        AttributeType type = attributeTypeRegistry.lookup( oidRegistry.getOid( node.getAttribute()
) );
+        Attribute attr = ServerUtils.getAttribute( type, entry );
 
         // If we do not have the attribute just return false
         if ( null == attr )

Modified: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeDirectoryPartition.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeDirectoryPartition.java?rev=412916&r1=412915&r2=412916&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeDirectoryPartition.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreeDirectoryPartition.java
Thu Jun  8 20:54:25 2006
@@ -338,10 +338,10 @@
     public abstract void addIndexOn( AttributeType attribute ) throws NamingException;
 
 
-    public abstract boolean hasUserIndexOn( String attribute );
+    public abstract boolean hasUserIndexOn( String attribute ) throws NamingException;
 
 
-    public abstract boolean hasSystemIndexOn( String attribute );
+    public abstract boolean hasSystemIndexOn( String attribute ) throws NamingException;
 
 
     public abstract Index getExistanceIndex();

Modified: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java?rev=412916&r1=412915&r2=412916&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/LeafEvaluator.java
Thu Jun  8 20:54:25 2006
@@ -25,6 +25,7 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 
+import org.apache.directory.server.core.ServerUtils;
 import org.apache.directory.server.core.schema.AttributeTypeRegistry;
 import org.apache.directory.server.core.schema.OidRegistry;
 import org.apache.directory.shared.ldap.NotImplementedException;
@@ -248,26 +249,11 @@
             return false;
         }
 
-        return null != getAttributeByOid( attrId, attrs );
+        AttributeType type = attributeTypeRegistry.lookup( oidRegistry.getOid( attrId ) );
+        return null != ServerUtils.getAttribute( type, attrs );
     }
 
-    
-    private Attribute getAttributeByOid( String attributeOid, Attributes entry ) throws NamingException
-    {
-        String matchForOid = this.oidRegistry.getOid( attributeOid );
-        for ( NamingEnumeration ii = entry.getIDs(); ii.hasMore(); /**/ )
-        {
-            String id = ( String ) ii.next();
-            String oid = this.oidRegistry.getOid( id );
-            if ( matchForOid.equals( oid ) )
-            {
-                return entry.get( id );
-            }
-        }
-        return null;
-    }
-
-    
+   
     /**
      * Evaluates a simple equality attribute value assertion on a perspective
      * candidate.
@@ -304,7 +290,8 @@
 
         // get the attribute associated with the node 
         Attributes attrs = rec.getAttributes();
-        Attribute attr = getAttributeByOid( node.getAttribute(), attrs );
+        AttributeType type = attributeTypeRegistry.lookup( oidRegistry.getOid( node.getAttribute()
) );
+        Attribute attr = ServerUtils.getAttribute( type, attrs );
 
         // If we do not have the attribute just return false
         if ( null == attr )

Modified: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/EntryDialog.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/EntryDialog.java?rev=412916&r1=412915&r2=412916&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/EntryDialog.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/EntryDialog.java
Thu Jun  8 20:54:25 2006
@@ -67,10 +67,9 @@
      * @param a_parent
      * @param a_modal
      */
-    public EntryDialog(Frame a_parent, String a_opMode, boolean a_modal)
+    public EntryDialog( Frame parent, boolean modal )
     {
-        super( a_parent, a_modal );
-        //        m_opMode = a_opMode ;
+        super( parent, modal );
         initGUI();
     }
 

Modified: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/IndexDialog.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/IndexDialog.java?rev=412916&r1=412915&r2=412916&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/IndexDialog.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/gui/IndexDialog.java
Thu Jun  8 20:54:25 2006
@@ -72,12 +72,20 @@
 
 
     /** Creates new form JDialog */
-    public IndexDialog(Frame parent, boolean modal, Index index)
+    public IndexDialog( Frame parent, boolean modal, Index index )
     {
         super( parent, modal );
         this.index = index;
         initGUI();
     }
+    
+    
+    public IndexDialog( Index index )
+    {
+        super();
+        this.index = index;
+        initGUI();
+    }
 
 
     /**
@@ -344,4 +352,11 @@
 
         return true;
     }
-}
\ No newline at end of file
+    
+    
+    public static void show( Index index )
+    {
+        IndexDialog dialog = new IndexDialog( index );
+        dialog.setVisible( true );
+    }
+}

Modified: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDirectoryPartition.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDirectoryPartition.java?rev=412916&r1=412915&r2=412916&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDirectoryPartition.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDirectoryPartition.java
Thu Jun  8 20:54:25 2006
@@ -26,7 +26,6 @@
 import java.util.List;
 import java.util.Map;
 
-import javax.naming.Name;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
@@ -40,6 +39,7 @@
 import jdbm.recman.CacheRecordManager;
 
 import org.apache.directory.server.core.DirectoryServiceConfiguration;
+import org.apache.directory.server.core.ServerUtils;
 import org.apache.directory.server.core.configuration.DirectoryPartitionConfiguration;
 import org.apache.directory.server.core.partition.DirectoryPartition;
 import org.apache.directory.server.core.partition.impl.btree.BTreeDirectoryPartition;
@@ -48,6 +48,7 @@
 import org.apache.directory.server.core.partition.impl.btree.IndexAssertionEnumeration;
 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.schema.AttributeTypeRegistry;
 import org.apache.directory.server.core.schema.OidRegistry;
 
 import org.apache.directory.shared.ldap.exception.LdapAuthenticationNotSupportedException;
@@ -110,6 +111,7 @@
     private Index aliasIdx;
     
     private OidRegistry oidRegistry;
+    private AttributeTypeRegistry attrRegistry;
 
 
     // ------------------------------------------------------------------------
@@ -128,6 +130,7 @@
         throws NamingException
     {
         oidRegistry = factoryCfg.getGlobalRegistries().getOidRegistry();
+        attrRegistry = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry();
         Map oids = factoryCfg.getGlobalRegistries().getAttributeTypeRegistry().getNormalizerMapping();
         LdapDN.setOidsMap( oids );
         this.upSuffix = new LdapDN( cfg.getSuffix() );
@@ -449,96 +452,92 @@
     }
 
 
-    public boolean hasUserIndexOn( String oid )
+    public boolean hasUserIndexOn( String id ) throws NamingException
     {
-        return indices.containsKey( oid );
+        return indices.containsKey( oidRegistry.getOid( id ) );
     }
 
 
-    public boolean hasSystemIndexOn( String oid )
+    public boolean hasSystemIndexOn( String id ) throws NamingException
     {
-        return sysIndices.containsKey( oid );
+        return sysIndices.containsKey( oidRegistry.getOid( id ) );
     }
 
 
     /**
-     * 
      * @see org.apache.directory.server.core.partition.impl.btree.BTreeDirectoryPartition#getUserIndex(String)
      */
-    public Index getUserIndex( String oid ) throws IndexNotFoundException
+    public Index getUserIndex( String id ) throws IndexNotFoundException
     {
         try
         {
-            oid = oidRegistry.getOid( oid );
+            id = oidRegistry.getOid( id );
         }
         catch ( NamingException e )
         {
-            log.error( "Failed to identify OID for: " + oid, e );
-            throw new IndexNotFoundException( "Failed to identify OID for: " + oid, oid,
e );
+            log.error( "Failed to identify OID for: " + id, e );
+            throw new IndexNotFoundException( "Failed to identify OID for: " + id, id, e
);
         }
 
-        if ( indices.containsKey( oid ) )
+        if ( indices.containsKey( id ) )
         {
-            return ( Index ) indices.get( oid );
+            return ( Index ) indices.get( id );
         }
         else
         {
             String name = "unknown";
             try
             {
-                name = oidRegistry.getPrimaryName( oid );
+                name = oidRegistry.getPrimaryName( id );
             }
             catch ( NamingException e )
             {
-                String msg = "Failed to resolve primary name for " + oid + " in user index
lookup";
+                String msg = "Failed to resolve primary name for " + id + " in user index
lookup";
                 log.error( msg, e );
-                throw new IndexNotFoundException( msg, oid, e );
+                throw new IndexNotFoundException( msg, id, e );
             }
             
-            throw new IndexNotFoundException( "A user index on attribute " + oid + " (" 
+            throw new IndexNotFoundException( "A user index on attribute " + id + " (" 
                 + name + ") does not exist!" );
         }
     }
 
 
     /**
-     * @todo replace lookups to use the OID instead of the name.  Also note
-     * that the OID registry can be used to go between names and oids.
-     * 
      * @see BTreeDirectoryPartition#getEntryId(String)
      */
-    public Index getSystemIndex( String oid ) throws IndexNotFoundException
+    public Index getSystemIndex( String id ) throws IndexNotFoundException
     {
         try
         {
-            oid = oidRegistry.getOid( oid );
+            id = oidRegistry.getOid( id );
         }
         catch ( NamingException e )
         {
-            log.error( "Failed to identify OID for: " + oid, e );
-            throw new IndexNotFoundException( "Failed to identify OID for: " + oid, oid,
e );
+            log.error( "Failed to identify OID for: " + id, e );
+            throw new IndexNotFoundException( "Failed to identify OID for: " + id, id, e
);
         }
 
 
-        if ( sysIndices.containsKey( oid ) )
+        if ( sysIndices.containsKey( id ) )
         {
-            return ( Index ) sysIndices.get( oid );
+            return ( Index ) sysIndices.get( id );
         }
         else
         {
             String name = "unknown";
             try
             {
-                name = oidRegistry.getPrimaryName( oid );
+                name = oidRegistry.getPrimaryName( id );
             }
             catch ( NamingException e )
             {
-                String msg = "Failed to resolve primary name for " + oid + " in user index
lookup";
+                String msg = "Failed to resolve primary name for " + id + " in user index
lookup";
                 log.error( msg, e );
-                throw new IndexNotFoundException( msg, oid, e );
+                throw new IndexNotFoundException( msg, id, e );
             }
             
-            throw new IndexNotFoundException( "A system index on attribute " + oid + " ("

+            throw new IndexNotFoundException( "A system index on attribute " + id + " ("

                 + name + ") does not exist!" );
         }
     }
@@ -601,7 +600,7 @@
         String targetDn = ( String ) aliasIdx.reverseLookup( aliasId );
         BigInteger targetId = getEntryId( targetDn );
         String aliasDn = getEntryDn( aliasId );
-        Name ancestorDn = new LdapDN( aliasDn ).getPrefix( 1 );
+        LdapDN ancestorDn = ( LdapDN ) new LdapDN( aliasDn ).getPrefix( 1 );
         BigInteger ancestorId = getEntryId( ancestorDn.toString() );
 
         /*
@@ -620,7 +619,7 @@
 
         while ( !ancestorDn.equals( upSuffix ) )
         {
-            ancestorDn = ancestorDn.getPrefix( 1 );
+            ancestorDn = ( LdapDN ) ancestorDn.getPrefix( 1 );
             ancestorId = getEntryId( ancestorDn.toString() );
 
             subAliasIdx.drop( ancestorId, targetId );
@@ -641,12 +640,12 @@
      * @throws NamingException if index addition fails, of the alias is not 
      * allowed due to chaining or cycle formation.
      */
-    private void addAliasIndices( BigInteger aliasId, Name aliasDn, String aliasTarget )
throws NamingException
+    private void addAliasIndices( BigInteger aliasId, LdapDN aliasDn, String aliasTarget
) throws NamingException
     {
-        Name targetDn = null; // Name value of aliasedObjectName
+        LdapDN targetDn = null; // Name value of aliasedObjectName
         BigInteger targetId = null; // Id of the aliasedObjectName
         Normalizer normalizer = null; // Temporary handle for Dn's
-        Name ancestorDn = null; // Name of an alias entry relative
+        LdapDN ancestorDn = null; // Name of an alias entry relative
         BigInteger ancestorId = null; // Id of an alias entry relative
 
         // Access aliasedObjectName, normalize it and generate the Name 
@@ -692,7 +691,7 @@
         }
 
         // L O O K U P   T A R G E T   I D
-        targetId = ndnIdx.forwardLookup( targetDn.toString() );
+        targetId = ndnIdx.forwardLookup( targetDn.toNormName() );
 
         /*
          * Check For Target Existance
@@ -735,7 +734,7 @@
          * index.  If the target is not a sibling of the alias then we add the
          * index entry maping the parent's id to the aliased target id.
          */
-        ancestorDn = aliasDn.getPrefix( 1 );
+        ancestorDn = ( LdapDN ) aliasDn.getPrefix( 1 );
         ancestorId = getEntryId( ancestorDn.toString() );
 
         if ( !NamespaceTools.isSibling( targetDn, aliasDn ) )
@@ -760,12 +759,12 @@
                 subAliasIdx.add( ancestorId, targetId );
             }
 
-            ancestorDn = ancestorDn.getPrefix( 1 );
+            ancestorDn = ( LdapDN ) ancestorDn.getPrefix( 1 );
             ancestorId = getEntryId( ancestorDn.toString() );
         }
     }
 
-
+    
     public void add( LdapDN normName, Attributes entry ) throws NamingException
     {
         BigInteger id;
@@ -797,21 +796,23 @@
             throw new LdapNameNotFoundException( "Id for parent '" + parentDn + "' not found!"
);
         }
 
-        Attribute objectClass = entry.get( "objectClass" );
+        AttributeType octype = attrRegistry.lookup( "objectClass" );
+        Attribute objectClass = ServerUtils.getAttribute( octype, entry );
 
         if ( objectClass == null )
         {
             String msg = "Entry " + normName.toUpName() + " contains no objectClass attribute:
" + entry;
-
             throw new LdapSchemaViolationException( msg, ResultCodeEnum.OBJECTCLASSVIOLATION
);
         }
 
         // Start adding the system indices
         // Why bother doing a lookup if this is not an alias.
 
-        if ( entry.get( "objectClass" ).contains( DirectoryPartition.ALIAS_OBJECT ) )
+        if ( objectClass.contains( DirectoryPartition.ALIAS_OBJECT ) )
         {
-            addAliasIndices( id, normName, ( String ) entry.get( DirectoryPartition.ALIAS_ATTRIBUTE
).get() );
+            AttributeType aliasType = attrRegistry.lookup( DirectoryPartition.ALIAS_ATTRIBUTE
);
+            Attribute aliasAttr = ServerUtils.getAttribute( aliasType, entry );
+            addAliasIndices( id, normName, ( String ) aliasAttr.get() );
         }
 
         ndnIdx.add( normName.toNormName(), id );
@@ -822,12 +823,16 @@
         NamingEnumeration list = entry.getIDs();
         while ( list.hasMore() )
         {
-            String attribute = ( String ) list.next();
+            String attributeId = ( String ) list.next();
+            String attributeOid = oidRegistry.getOid( attributeId );
 
-            if ( hasUserIndexOn( attribute ) )
+            if ( hasUserIndexOn( attributeOid ) )
             {
-                Index idx = getUserIndex( attribute );
-                NamingEnumeration values = entry.get( attribute ).getAll();
+                Index idx = getUserIndex( attributeOid );
+                
+                // here lookup by attributeId is ok since we got attributeId from 
+                // the entry via the enumeration - it's in there as is for sure
+                NamingEnumeration values = entry.get( attributeId ).getAll();
 
                 while ( values.hasMore() )
                 {
@@ -835,7 +840,7 @@
                 }
 
                 // Adds only those attributes that are indexed
-                existanceIdx.add( attribute.toLowerCase(), id );
+                existanceIdx.add( attributeOid, id );
             }
         }
 
@@ -855,7 +860,9 @@
         BigInteger parentId = getParentId( id );
         NamingEnumeration attrs = entry.getIDs();
 
-        if ( entry.get( "objectClass" ).contains( DirectoryPartition.ALIAS_OBJECT ) )
+        AttributeType octype = attrRegistry.lookup( "objectClass" );
+        Attribute objectClass = ServerUtils.getAttribute( octype, entry );
+        if ( objectClass.contains( DirectoryPartition.ALIAS_OBJECT ) )
         {
             dropAliasIndices( id );
         }
@@ -872,19 +879,23 @@
 
         while ( attrs.hasMore() )
         {
-            String attr = ( ( String ) attrs.next() );
+            String attributeId = ( ( String ) attrs.next() );
+            String attributeOid = oidRegistry.getOid( attributeId );
 
-            if ( hasUserIndexOn( attr ) )
+            if ( hasUserIndexOn( attributeOid ) )
             {
-                Index index = getUserIndex( attr );
-                NamingEnumeration values = entry.get( attr ).getAll();
+                Index index = getUserIndex( attributeOid );
+
+                // here lookup by attributeId is ok since we got attributeId from 
+                // the entry via the enumeration - it's in there as is for sure
+                NamingEnumeration values = entry.get( attributeId ).getAll();
 
                 while ( values.hasMore() )
                 {
                     index.drop( values.next(), id );
                 }
 
-                existanceIdx.drop( attr.toLowerCase(), id );
+                existanceIdx.drop( attributeOid, id );
             }
         }
 
@@ -1020,20 +1031,23 @@
      */
     private void add( BigInteger id, Attributes entry, Attribute mods ) throws NamingException
     {
-        if ( hasUserIndexOn( mods.getID() ) )
+        String modsOid = oidRegistry.getOid( mods.getID() );
+        
+        if ( hasUserIndexOn( modsOid ) )
         {
-            Index idx = getUserIndex( mods.getID() );
+            Index idx = getUserIndex( modsOid );
             idx.add( mods, id );
 
             // If the attr didn't exist for this id add it to existance index
-            if ( !existanceIdx.hasValue( mods.getID().toLowerCase(), id ) )
+            if ( !existanceIdx.hasValue( modsOid, id ) )
             {
-                existanceIdx.add( mods.getID().toLowerCase(), id );
+                existanceIdx.add( modsOid, id );
             }
         }
 
         // add all the values in mods to the same attribute in the entry
-        Attribute entryAttrToAddTo = entry.get( mods.getID() );
+        AttributeType type = attrRegistry.lookup( modsOid );
+        Attribute entryAttrToAddTo = ServerUtils.getAttribute( type, entry );
 
         if ( entryAttrToAddTo == null )
         {
@@ -1046,7 +1060,7 @@
             entryAttrToAddTo.add( mods.get( ii ) );
         }
 
-        if ( mods.getID().equals( DirectoryPartition.ALIAS_ATTRIBUTE ) )
+        if ( modsOid.equals( oidRegistry.getOid( DirectoryPartition.ALIAS_ATTRIBUTE ) ) )
         {
             String ndnStr = ( String ) ndnIdx.reverseLookup( id );
             addAliasIndices( id, new LdapDN( ndnStr ), ( String ) mods.get() );
@@ -1070,9 +1084,11 @@
      */
     private void remove( BigInteger id, Attributes entry, Attribute mods ) throws NamingException
     {
-        if ( hasUserIndexOn( mods.getID() ) )
+        String modsOid = oidRegistry.getOid( mods.getID() );
+        
+        if ( hasUserIndexOn( modsOid ) )
         {
-            Index idx = getUserIndex( mods.getID() );
+            Index idx = getUserIndex( modsOid );
             idx.drop( mods, id );
 
             /* 
@@ -1081,10 +1097,11 @@
              */
             if ( null == idx.reverseLookup( id ) )
             {
-                existanceIdx.drop( mods.getID(), id );
+                existanceIdx.drop( modsOid, id );
             }
         }
 
+        AttributeType attrType = attrRegistry.lookup( modsOid );
         /*
          * If there are no attribute values in the modifications then this 
          * implies the compelete removal of the attribute from the entry. Else
@@ -1093,11 +1110,11 @@
          */
         if ( mods.size() == 0 )
         {
-            entry.remove( mods.getID() );
+            ServerUtils.removeAttribute( attrType, entry );
         }
         else
         {
-            Attribute entryAttr = entry.get( mods.getID() );
+            Attribute entryAttr = ServerUtils.getAttribute( attrType, entry );
             NamingEnumeration values = mods.getAll();
             while ( values.hasMore() )
             {
@@ -1112,7 +1129,7 @@
         }
 
         // Aliases->single valued comp/partial attr removal is not relevant here
-        if ( mods.getID().equals( DirectoryPartition.ALIAS_ATTRIBUTE ) )
+        if ( modsOid.equals( oidRegistry.getOid( DirectoryPartition.ALIAS_ATTRIBUTE ) ) )
         {
             dropAliasIndices( id );
         }
@@ -1133,9 +1150,11 @@
      */
     private void replace( BigInteger id, Attributes entry, Attribute mods ) throws NamingException
     {
-        if ( hasUserIndexOn( mods.getID() ) )
+        String modsOid = oidRegistry.getOid( mods.getID() );
+        
+        if ( hasUserIndexOn( modsOid ) )
         {
-            Index idx = getUserIndex( mods.getID() );
+            Index idx = getUserIndex( modsOid );
 
             // Drop all existing attribute value index entries and add new ones
             idx.drop( id );
@@ -1147,11 +1166,12 @@
              */
             if ( null == idx.reverseLookup( id ) )
             {
-                existanceIdx.drop( mods.getID(), id );
+                existanceIdx.drop( modsOid, id );
             }
         }
 
-        if ( mods.getID().equals( DirectoryPartition.ALIAS_ATTRIBUTE ) )
+        String aliasAttributeOid = oidRegistry.getOid( DirectoryPartition.ALIAS_ATTRIBUTE
);
+        if ( modsOid.equals( aliasAttributeOid ) )
         {
             dropAliasIndices( id );
         }
@@ -1159,7 +1179,7 @@
         // Automatically replaces old attributes with new modified ones
         entry.put( mods );
 
-        if ( mods.getID().equals( DirectoryPartition.ALIAS_ATTRIBUTE ) )
+        if ( modsOid.equals( aliasAttributeOid ) )
         {
             String ndnStr = ( String ) ndnIdx.reverseLookup( id );
             addAliasIndices( id, new LdapDN( ndnStr ), ( String ) mods.get() );
@@ -1268,7 +1288,7 @@
         String newRdnValue = NamespaceTools.getRdnValue( newRdn );
         BigInteger id = getEntryId( dn.toString() );
         Attributes entry = lookup( id );
-        Name updn = new LdapDN( getEntryUpdn( id ) );
+        LdapDN updn = new LdapDN( getEntryUpdn( id ) );
 
         /* 
          * H A N D L E   N E W   R D N
@@ -1279,7 +1299,9 @@
          * new Rdn attribute within this entry.
          */
 
-        Attribute rdnAttr = entry.get( newRdnAttr );
+        String newRdnAttrOid = oidRegistry.getOid( newRdnAttr );
+        AttributeType newRdnAttrType = attrRegistry.lookup( newRdnAttrOid );
+        Attribute rdnAttr = ServerUtils.getAttribute( newRdnAttrType, entry );
         if ( rdnAttr == null )
         {
             rdnAttr = new LockableAttributeImpl( newRdnAttr );
@@ -1293,15 +1315,15 @@
 
         entry.put( rdnAttr );
 
-        if ( hasUserIndexOn( newRdnAttr ) )
+        if ( hasUserIndexOn( newRdnAttrOid ) )
         {
-            Index idx = getUserIndex( newRdnAttr );
+            Index idx = getUserIndex( newRdnAttrOid );
             idx.add( newRdnValue, id );
 
             // Make sure the altered entry shows the existance of the new attrib
-            if ( !existanceIdx.hasValue( newRdnAttr.toLowerCase(), id ) )
+            if ( !existanceIdx.hasValue( newRdnAttrOid, id ) )
             {
-                existanceIdx.add( newRdnAttr.toLowerCase(), id );
+                existanceIdx.add( newRdnAttrOid, id );
             }
         }
 
@@ -1323,13 +1345,15 @@
         {
             String oldRdn = updn.get( updn.size() - 1 );
             String oldRdnAttr = NamespaceTools.getRdnAttribute( oldRdn );
+            String oldRdnAttrOid = oidRegistry.getOid( oldRdnAttr );
             String oldRdnValue = NamespaceTools.getRdnValue( oldRdn );
+            AttributeType oldRdnAttrType = attrRegistry.lookup( oldRdnAttrOid );
+            
+            ServerUtils.getAttribute( oldRdnAttrType, entry ).remove( oldRdnValue );
 
-            entry.get( oldRdnAttr ).remove( oldRdnValue );
-
-            if ( hasUserIndexOn( oldRdnAttr ) )
+            if ( hasUserIndexOn( oldRdnAttrOid ) )
             {
-                Index idx = getUserIndex( oldRdnAttr );
+                Index idx = getUserIndex( oldRdnAttrOid );
                 idx.drop( oldRdnValue, id );
 
                 /*
@@ -1338,7 +1362,7 @@
                  */
                 if ( null == idx.reverseLookup( id ) )
                 {
-                    existanceIdx.drop( oldRdnAttr, id );
+                    existanceIdx.drop( oldRdnAttrOid, id );
                 }
             }
         }
@@ -1354,7 +1378,7 @@
          *    entry and its descendants
          */
 
-        Name newUpdn = ( Name ) updn.clone(); // copy da old updn
+        LdapDN newUpdn = ( LdapDN ) updn.clone(); // copy da old updn
         newUpdn.remove( newUpdn.size() - 1 ); // remove old upRdn
         newUpdn.add( newUpdn.size(), newRdn ); // add da new upRdn
         modifyDn( id, newUpdn, false ); // propagate dn changes
@@ -1378,7 +1402,7 @@
      * which affects alias indices.
      * @throws NamingException if something goes wrong
      */
-    private void modifyDn( BigInteger id, Name updn, boolean isMove ) throws NamingException
+    private void modifyDn( BigInteger id, LdapDN updn, boolean isMove ) throws NamingException
     {
         String aliasTarget = null;
 
@@ -1420,8 +1444,8 @@
              * Calculate the Dn for the child's new name by copying the parents
              * new name and adding the child's old upRdn to new name as its Rdn
              */
-            Name childUpdn = ( Name ) updn.clone();
-            Name oldUpdn = new LdapDN( getEntryUpdn( childId ) );
+            LdapDN childUpdn = ( LdapDN ) updn.clone();
+            LdapDN oldUpdn = new LdapDN( getEntryUpdn( childId ) );
             String rdn = oldUpdn.get( oldUpdn.size() - 1 );
             childUpdn.add( childUpdn.size(), rdn );
 
@@ -1459,7 +1483,7 @@
      * @param newParentDn the normalized dn of the new parent for the child
      * @throws NamingException if something goes wrong
      */
-    private void move( Name oldChildDn, BigInteger childId, Name newParentDn ) throws NamingException
+    private void move( LdapDN oldChildDn, BigInteger childId, LdapDN newParentDn ) throws
NamingException
     {
         // Get the child and the new parent to be entries and Ids
         BigInteger newParentId = getEntryId( newParentDn.toString() );
@@ -1487,9 +1511,9 @@
          * user provided RDN & the new parent's UPDN.  Basically add the child's
          * UpRdn String to the tail of the new parent's Updn Name.
          */
-        Name childUpdn = new LdapDN( getEntryUpdn( childId ) );
+        LdapDN childUpdn = new LdapDN( getEntryUpdn( childId ) );
         String childRdn = childUpdn.get( childUpdn.size() - 1 );
-        Name newUpdn = new LdapDN( getEntryUpdn( newParentId ) );
+        LdapDN newUpdn = new LdapDN( getEntryUpdn( newParentId ) );
         newUpdn.add( newUpdn.size(), childRdn );
 
         // Call the modifyDn operation with the new updn
@@ -1505,7 +1529,7 @@
      * @param movedBase the base at which the move occured - the moved node
      * @throws NamingException if system indices fail
      */
-    private void dropMovedAliasIndices( final Name movedBase ) throws NamingException
+    private void dropMovedAliasIndices( final LdapDN movedBase ) throws NamingException
     {
         // Find all the aliases from movedBase down
         IndexAssertion isBaseDescendant = new IndexAssertion()
@@ -1546,7 +1570,7 @@
      * @param movedBase the base where the move occured
      * @throws NamingException if indices fail
      */
-    private void dropAliasIndices( BigInteger aliasId, Name movedBase ) throws NamingException
+    private void dropAliasIndices( BigInteger aliasId, LdapDN movedBase ) throws NamingException
     {
         String targetDn = ( String ) aliasIdx.reverseLookup( aliasId );
         BigInteger targetId = getEntryId( targetDn );
@@ -1556,7 +1580,7 @@
          * Start droping index tuples with the first ancestor right above the 
          * moved base.  This is the first ancestor effected by the move.
          */
-        Name ancestorDn = movedBase.getPrefix( 1 );
+        LdapDN ancestorDn = ( LdapDN ) movedBase.getPrefix( 1 );
         BigInteger ancestorId = getEntryId( ancestorDn.toString() );
 
         /*
@@ -1580,7 +1604,7 @@
 
         while ( !ancestorDn.equals( upSuffix ) )
         {
-            ancestorDn = ancestorDn.getPrefix( 1 );
+            ancestorDn = ( LdapDN ) ancestorDn.getPrefix( 1 );
             ancestorId = getEntryId( ancestorDn.toString() );
 
             subAliasIdx.drop( ancestorId, targetId );

Modified: directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java?rev=412916&r1=412915&r2=412916&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
(original)
+++ directory/branches/apacheds/optimization/core/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
Thu Jun  8 20:54:25 2006
@@ -32,6 +32,7 @@
 import jdbm.recman.BaseRecordManager;
 import jdbm.recman.CacheRecordManager;
 
+import org.apache.directory.server.core.ServerUtils;
 import org.apache.directory.server.core.partition.impl.btree.Index;
 import org.apache.directory.server.core.partition.impl.btree.IndexComparator;
 import org.apache.directory.server.core.partition.impl.btree.IndexEnumeration;
@@ -81,7 +82,7 @@
      * @param recMan the record manager
      * @throws NamingException if we fail to create B+Trees using recMan
      */
-    public JdbmIndex(AttributeType attribute, RecordManager recMan) throws NamingException
+    public JdbmIndex( AttributeType attribute, RecordManager recMan ) throws NamingException
     {
         this.attribute = attribute;
         keyCache = new SynchronizedLRUMap( 1000 );
@@ -90,7 +91,7 @@
     }
 
 
-    public JdbmIndex(AttributeType attribute, File wkDirPath) throws NamingException
+    public JdbmIndex( AttributeType attribute, File wkDirPath ) throws NamingException
     {
         File file = new File( wkDirPath.getPath() + File.separator + attribute.getName()
);
         this.attribute = attribute;
@@ -245,7 +246,7 @@
      */
     public synchronized void add( Attributes attrs, BigInteger id ) throws NamingException
     {
-        add( attrs.get( attribute.getName() ), id );
+        add( ServerUtils.getAttribute( attribute, attrs ), id );
     }
 
 
@@ -309,7 +310,7 @@
      */
     public void drop( Attributes attrs, BigInteger id ) throws NamingException
     {
-        drop( attrs.get( attribute.getName() ), id );
+        drop( ServerUtils.getAttribute( attribute, attrs ), id );
     }
 
 



Mime
View raw message