directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 22611 - in incubator/directory/eve/branches/plus: . src/java/org/apache/eve/backend/jdbm src/java/org/apache/eve/jndi src/java/org/apache/eve/protocol src/java/org/apache/eve/schema
Date Tue, 06 Jul 2004 05:01:27 GMT
Author: akarasulu
Date: Mon Jul  5 22:01:26 2004
New Revision: 22611

Removed:
   incubator/directory/eve/branches/plus/.classpath
   incubator/directory/eve/branches/plus/.project
   incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/ModifyDNRequestProcessor.java
   incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/SearchRequestProcessor.java
   incubator/directory/eve/branches/plus/todo.txt
Modified:
   incubator/directory/eve/branches/plus/   (props changed)
   incubator/directory/eve/branches/plus/src/java/org/apache/eve/backend/jdbm/JdbmDatabase.java
   incubator/directory/eve/branches/plus/src/java/org/apache/eve/backend/jdbm/JdbmModule.java
   incubator/directory/eve/branches/plus/src/java/org/apache/eve/backend/jdbm/LdapEntryImpl.java
   incubator/directory/eve/branches/plus/src/java/org/apache/eve/jndi/ContextHelper.java
   incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/CompareHandler.java
   incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/ModifyDnHandler.java
   incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/SearchHandler.java
   incubator/directory/eve/branches/plus/src/java/org/apache/eve/schema/   (props changed)
Log:
Merging in changes from the start branch predominantly due to bug fixes in the
code where the database and protocol are concerned.  The merge was from the 
start branch at revision 21633 up to the HEAD (upto last change on start branch
at revision 22245).


Modified: incubator/directory/eve/branches/plus/src/java/org/apache/eve/backend/jdbm/JdbmDatabase.java
==============================================================================
--- incubator/directory/eve/branches/plus/src/java/org/apache/eve/backend/jdbm/JdbmDatabase.java
(original)
+++ incubator/directory/eve/branches/plus/src/java/org/apache/eve/backend/jdbm/JdbmDatabase.java
Mon Jul  5 22:01:26 2004
@@ -43,6 +43,7 @@
 
 import org.apache.commons.collections.MultiMap ;
 import org.apache.commons.collections.MultiHashMap ;
+import org.apache.commons.collections.LRUMap;
 
 import org.apache.ldap.common.name.DnParser ;
 import org.apache.ldap.common.util.NamespaceTools ;
@@ -74,19 +75,19 @@
     private final Map m_indices ;
 
     private NameParser m_nonNormalizingParser = null ;
-    private final NameParser m_parser ;
+    private final LRUMap byIdCache ;
 
 
     public JdbmDatabase(final Schema a_schema,
         final Name a_suffix,
-        final String a_wkdirPath)
+        final String a_wkdirPath, LRUMap byIdCache )
         throws BackendException, NamingException
     {
+        this.byIdCache = byIdCache ;
         m_schema = a_schema ;
         m_suffix = a_suffix ;
         m_wkdir = a_wkdirPath ;
 
-        m_parser = m_schema.getNormalizingParser() ;
         try {
             m_nonNormalizingParser = new DnParser() ;
         } catch(IOException e) {
@@ -312,6 +313,11 @@
     public LdapEntryImpl read(BigInteger a_id)
         throws BackendException, NamingException
     {
+        if (byIdCache.containsKey(a_id))
+        {
+            return (LdapEntryImpl) byIdCache.get(a_id);
+        }
+
         LdapEntryImpl l_entry = new LdapEntryImpl(this.m_schema) ;
         l_entry.enableLogging(getLogger()) ;
 
@@ -914,7 +920,7 @@
 	    }
 
         l_name.remove( l_name.size() - 1 ) ;
-	    l_name.add( l_name.size(), a_newRdn ) ;
+	    l_name.add( a_newRdn ) ;
 	    an_entry.addValue( l_attribute, l_value ) ;
 
         if( getLogger().isDebugEnabled() ) 
@@ -943,7 +949,7 @@
 	    Cursor l_children ;
 	    Name l_childDN ;
 
-        if ( getLogger().isDebugEnabled() ) 
+        if ( getLogger().isDebugEnabled() )
         {
             getLogger().debug( "" //ProtocolModule.getMessageKey()
                 + " - Database.modifyDn() - called on entry '"
@@ -973,8 +979,7 @@
 
             // Add to the copy of the parent the unnormalized rdn of the child
             // Dn to get the new Dn of the child entry - call recursively.
-	        l_childDN.add( 0,
-                NamespaceTools.getRdn( l_child.getEntryDN() ) ) ;
+	        l_childDN.add( NamespaceTools.getRdn( l_child.getEntryDN() ) ) ;
             modifyDn( l_child, l_childDN ) ;
 	    }
     }

Modified: incubator/directory/eve/branches/plus/src/java/org/apache/eve/backend/jdbm/JdbmModule.java
==============================================================================
--- incubator/directory/eve/branches/plus/src/java/org/apache/eve/backend/jdbm/JdbmModule.java
(original)
+++ incubator/directory/eve/branches/plus/src/java/org/apache/eve/backend/jdbm/JdbmModule.java
Mon Jul  5 22:01:26 2004
@@ -553,7 +553,7 @@
             m_byIdCache.setMaximumSize(m_cache.getMaximumSize()) ;
             m_searchEngine = new SearchEngine() ;
             m_searchEngine.enableLogging(getLogger()) ;
-            m_db = new JdbmDatabase (m_schema, m_suffix, m_wkdirPath) ;
+            m_db = new JdbmDatabase (m_schema, m_suffix, m_wkdirPath, this.m_byIdCache) ;
 	        m_db.enableLogging(getLogger()) ;
 
             Configuration [] l_indices =

Modified: incubator/directory/eve/branches/plus/src/java/org/apache/eve/backend/jdbm/LdapEntryImpl.java
==============================================================================
--- incubator/directory/eve/branches/plus/src/java/org/apache/eve/backend/jdbm/LdapEntryImpl.java
(original)
+++ incubator/directory/eve/branches/plus/src/java/org/apache/eve/backend/jdbm/LdapEntryImpl.java
Mon Jul  5 22:01:26 2004
@@ -21,20 +21,16 @@
 import javax.naming.NamingException ;
 import javax.naming.directory.AttributeInUseException ;
 import javax.naming.directory.InvalidAttributeValueException ;
-import javax.naming.directory.AttributeModificationException ;
 import javax.naming.directory.InvalidAttributeIdentifierException ;
 
-import org.apache.ldap.common.util.NamespaceTools ;
 import org.apache.eve.backend.LdapEntry ;
 import org.apache.eve.schema.Schema ;
-import org.apache.eve.protocol.ProtocolModule;
 
 import org.apache.avalon.framework.logger.Logger ;
 import org.apache.avalon.framework.logger.LogEnabled ;
 
 import org.apache.commons.collections.LRUMap ;
 import org.apache.commons.collections.MultiHashMap ;
-import org.apache.ldap.common.name.DnParser;
 
 
 /**
@@ -336,7 +332,7 @@
     /**
      * Gets a multivalued attribute by name.
      *
-     * @param a_attribName the name of the attribute to lookup.
+     * @param an_attribName the name of the attribute to lookup.
      * @return a Collection or null if no attribute value exists.
      */
     public Collection getMultiValue(String an_attribName)
@@ -349,7 +345,7 @@
      * Gets a single valued attribute by name or returns the first value of a
      * multivalued attribute.
      *
-     * @param a_attribName the name of the attribute to lookup.
+     * @param an_attribName the name of the attribute to lookup.
      * @return an Object value which is either a String or byte [] or null if
      * the attribute does not exist.
      */
@@ -474,7 +470,7 @@
      *
      * @param an_attribName attribute name/key
      * @param a_value the value to remove
-     * @throws AttributeModificationException when an attempt is made to modify
+     * @throws InvalidAttributeIdentifierException when an attempt is made to modify
      * an attribute, its identifier, or its values that conflicts with the
      * attribute's (schema) definition or the attribute's state.  Also thrown
      * if the specified attribute name does not exist as a key in this Entry.
@@ -509,8 +505,7 @@
      * attribute.
      *
      * @param an_attribName attribute name/key
-     * @param a_value the value to remove
-     * @throws AttributeModificationException when an attempt is made to modify
+     * @throws InvalidAttributeIdentifierException when an attempt is made to modify
      * an attribute, its identifier, or its values that conflicts with the
      * attribute's (schema) definition or the attribute's state.  Also thrown
      * if the specified attribute name does not exist as a key in this Entry.
@@ -546,7 +541,7 @@
      *
      * @param an_attribName attribute name/key
      * @param a_valueArray the set of values to remove
-     * @throws AttributeModificationException when an attempt is made to modify
+     * @throws InvalidAttributeIdentifierException when an attempt is made to modify
      * an attribute, its identifier, or its values that conflicts with the
      * attribute's (schema) definition or the attribute's state.  Also thrown
      * if the specified attribute name does not exist as a key in this Entry.
@@ -644,20 +639,29 @@
         // Get the old user provided Dn and remove it by removing it from
         // this MultiMap and adding it to the m_removed MultiMap.
         String l_oldDn = getEntryDN() ;
+        String oldParentDn = getParentDN();
+        Name newParentDn = (Name) a_dn.clone();
+        newParentDn.remove(newParentDn.size()-1);
         remove(DN_ATTR, l_oldDn) ;
+        remove(PARENTDN_ATTR, oldParentDn);
         if(m_isValid) {
             m_removed.put(DN_ATTR, l_oldDn) ;
+            m_removed.put(PARENTDN_ATTR, oldParentDn);
         }
 
         // Reparse as normalized name using schema's normalizing parser
 		m_normalizedDn =
             m_schema.getNormalizingParser().parse(a_dn.toString()) ;
+        Name normParentDn = (Name) m_normalizedDn.clone();
+        normParentDn.remove(normParentDn.size()-1);
 
         // Add unnormalized user provided Dn argument to this MultiMap and
         // the m_added MultiMap
         put(DN_ATTR, a_dn.toString()) ;
+        put(PARENTDN_ATTR, normParentDn.toString());
         if(this.m_isValid) {
             m_added.put(DN_ATTR, a_dn.toString()) ;
+            m_added.put(PARENTDN_ATTR, normParentDn.toString());
         }
 
         if(getLogger().isDebugEnabled()) {

Modified: incubator/directory/eve/branches/plus/src/java/org/apache/eve/jndi/ContextHelper.java
==============================================================================
--- incubator/directory/eve/branches/plus/src/java/org/apache/eve/jndi/ContextHelper.java
(original)
+++ incubator/directory/eve/branches/plus/src/java/org/apache/eve/jndi/ContextHelper.java
Mon Jul  5 22:01:26 2004
@@ -314,9 +314,9 @@
         LdapEntry l_oldEntry = null ;
         Name l_oldDn = new LdapName() ;
         Name l_newDn = new LdapName() ;
-        l_oldDn.addAll( l_entry.getNormalizedDN() ) ;
+        l_oldDn.addAll( l_entry.getUnNormalizedDN() ) ;
         l_oldDn.addAll( a_oldRdn ) ;
-        l_newDn.addAll( l_entry.getNormalizedDN() ) ;
+        l_newDn.addAll( l_entry.getUnNormalizedDN() ) ;
         l_newDn.addAll( a_newRdn ) ;
 
         try
@@ -338,7 +338,15 @@
         {
             try
             {
-                l_nexus.modifyRdn( l_oldEntry, a_newRdn, true ) ;
+                String deleteRdn = (String) m_ctx.getEnvironment().get("java.naming.ldap.deleteRDN");
+                if ( deleteRdn != null )
+                {
+                    l_nexus.modifyRdn( l_oldEntry, a_newRdn, deleteRdn.equals("true") ) ;
+                }
+                else
+                {
+                    l_nexus.modifyRdn( l_oldEntry, a_newRdn, true ) ;
+                }
             }
             catch( BackendException e )
             {
@@ -427,8 +435,8 @@
         throws NamingException
     {
         UnifiedBackend l_nexus = JndiProviderModule.getInstance().getNexus() ;
-        rename( l_nexus.getNormalizedName( a_oldRdn ),
-            l_nexus.getNormalizedName( a_newRdn ) ) ;
+        rename( l_nexus.getName( a_oldRdn ),
+            l_nexus.getName( a_newRdn ) ) ;
     }
 
 

Modified: incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/CompareHandler.java
==============================================================================
--- incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/CompareHandler.java
(original)
+++ incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/CompareHandler.java
Mon Jul  5 22:01:26 2004
@@ -10,11 +10,25 @@
 package org.apache.eve.protocol ;
 
 
-import org.apache.ldap.common.message.ResultResponse ;
-import org.apache.ldap.common.message.CompareRequest ;
-import org.apache.ldap.common.message.MessageTypeEnum ;
 import org.apache.ldap.common.NotImplementedException ;
-import org.apache.ldap.common.message.SingleReplyRequest ;
+import org.apache.ldap.common.message.*;
+import org.apache.eve.backend.LdapEntry;
+import org.apache.eve.backend.Backend;
+import org.apache.eve.backend.BackendException;
+import org.apache.eve.schema.Schema;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.CascadingRuntimeException;
+
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.InitialContext;
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import javax.naming.ldap.LdapContext;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
 
 
 /**
@@ -100,7 +114,121 @@
      */
     public ResultResponse handle( SingleReplyRequest a_request )
     {
-        CompareRequest l_request = ( CompareRequest ) a_request ;
-        throw new NotImplementedException() ;
+        Name dn = null;
+        Schema schema = null;
+        Logger log = m_module.getLogger();
+        CompareRequest req = ( CompareRequest ) a_request;
+        CompareResponseImpl resp;
+        resp = new CompareResponseImpl( req.getMessageId() );
+        LdapResultImpl result = new LdapResultImpl( resp );
+        resp.setLdapResult( result );
+        result.setResultCode( ResultCodeEnum.COMPAREFALSE );
+
+        try
+        {
+            dn = m_module.getNexus().getNormalizedName( req.getName() );
+        }
+        catch ( NamingException e )
+        {
+            String msg = "failed to parse dn " + req.getName();
+
+            if ( log.isErrorEnabled() )
+            {
+                log.error( msg, e );
+            }
+
+            throw new CascadingRuntimeException( msg, e );
+        }
+
+        try
+        {
+            schema = m_module.getNexus().getSchema( dn );
+        }
+        catch ( NamingException e )
+        {
+            String msg = "failed to lookup schema for dn " + req.getName();
+
+            if ( log.isErrorEnabled() )
+            {
+                log.error( msg, e );
+            }
+
+            throw new CascadingRuntimeException( msg, e );
+        }
+
+        Attributes attrs;
+        try
+        {
+            InitialContext initCtx = Utils.getInitialContext() ;
+            LdapContext ctx = ( LdapContext ) initCtx.lookup( req.getName() ) ;
+            attrs = ctx.getAttributes( "" );
+        }
+        catch ( NamingException e )
+        {
+            String msg = "failed to lookup entry " + req.getName();
+
+            if ( log.isErrorEnabled() )
+            {
+                log.error( msg, e );
+            }
+
+            throw new CascadingRuntimeException( msg, e );
+        }
+
+        Attribute attr = attrs.get( req.getAttributeId() );
+        if ( attr == null )
+        {
+            result.setMatchedDn(req.getName());
+            result.setResultCode(ResultCodeEnum.COMPAREFALSE);
+            return resp;
+        }
+
+        NamingEnumeration list;
+        try
+        {
+            list = attr.getAll();
+        }
+        catch ( NamingException e )
+        {
+            String msg = "failed to lookup attribute values for id " +
+                    req.getAttributeId() + " in entry " + req.getName();
+
+            if ( log.isErrorEnabled() )
+            {
+                log.error( msg, e );
+            }
+
+            throw new CascadingRuntimeException( msg, e );
+        }
+
+
+        String compareTo = req.getAssertionValue();
+        try
+        {
+            while( list.hasMore() )
+            {
+                String value = ( String ) list.next();
+                value = schema.normalize( req.getAttributeId(), value );
+                if ( value.equals( compareTo ) )
+                {
+                    result.setResultCode( ResultCodeEnum.COMPARETRUE );
+                    break;
+                }
+            }
+        }
+        catch( NamingException e )
+        {
+            String msg = "failed to normalize entry value for " + req.getName();
+
+            if ( log.isErrorEnabled() )
+            {
+                log.error( msg, e );
+            }
+
+            throw new CascadingRuntimeException( msg, e );
+        }
+
+        result.setMatchedDn( req.getName() );
+        return resp ;
     }
 }

Modified: incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/ModifyDnHandler.java
==============================================================================
--- incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/ModifyDnHandler.java
(original)
+++ incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/ModifyDnHandler.java
Mon Jul  5 22:01:26 2004
@@ -10,11 +10,14 @@
 package org.apache.eve.protocol ;
 
 
-import org.apache.ldap.common.message.ResultResponse ;
-import org.apache.ldap.common.message.MessageTypeEnum ;
-import org.apache.ldap.common.NotImplementedException ;
-import org.apache.ldap.common.message.ModifyDnRequest ;
-import org.apache.ldap.common.message.SingleReplyRequest ;
+import org.apache.ldap.common.message.*;
+import org.apache.ldap.common.name.LdapName;
+import org.apache.avalon.framework.CascadingRuntimeException;
+
+import javax.naming.Name;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.ldap.LdapContext;
 
 
 /**
@@ -94,13 +97,55 @@
      * Handles a request that generates a sole response by returning the
      * response object back to the caller.
      *
-     * @param a_request the request to handle.
+     * @param request the request to handle.
      * @return the response to the request argument.
      * @throws ClassCastException if a_request is not a ModifyRequest
      */
-    public ResultResponse handle( SingleReplyRequest a_request )
+    public ResultResponse handle( SingleReplyRequest request )
     {
-        ModifyDnRequest l_request = ( ModifyDnRequest ) a_request ;
-        throw new NotImplementedException() ;
+        LdapContext ctx = null;
+        InitialContext initCtx = null;
+        ModifyDnRequest req = (ModifyDnRequest) request ;
+        ModifyDnResponseImpl resp = new ModifyDnResponseImpl(req.getMessageId());
+        LdapResultImpl result = new LdapResultImpl(resp);
+        resp.setLdapResult(result);
+
+        try {
+            initCtx = Utils.getInitialContext();
+        } catch (NamingException e) {
+            String msg = "initial context lookup failure";
+            m_module.getLogger().error(msg, e);
+            throw new CascadingRuntimeException(msg,e);
+        }
+
+        try {
+            LdapName dn = (LdapName) m_module.getNexus().getName(req.getName());
+            if( req.getNewSuperior() == null )
+            {
+                ctx = (LdapContext) initCtx.lookup(dn.getSuffix(1));
+
+                if ( !req.getDeleteOldRdn() )
+                {
+                    ctx.getEnvironment().put("java.naming.ldap.deleteRDN", "false");
+                }
+
+                ctx.rename(dn.getRdn(), req.getNewRdn());
+                result.setResultCode(ResultCodeEnum.SUCCESS);
+                result.setMatchedDn(req.getName());
+                return resp;
+            }
+
+
+            Name newRdn = (LdapName) m_module.getNexus().getName(req.getNewSuperior());
+            newRdn.addAll(m_module.getNexus().getName(req.getNewRdn()));
+            initCtx.rename(dn,newRdn);
+            result.setResultCode(ResultCodeEnum.SUCCESS);
+            result.setMatchedDn(req.getName());
+            return resp;
+        } catch (NamingException e) {
+            String msg = "could not lookup entry context for " + req.getName();
+            m_module.getLogger().error(msg, e);
+            throw new CascadingRuntimeException(msg,e);
+        }
     }
 }

Modified: incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/SearchHandler.java
==============================================================================
--- incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/SearchHandler.java
(original)
+++ incubator/directory/eve/branches/plus/src/java/org/apache/eve/protocol/SearchHandler.java
Mon Jul  5 22:01:26 2004
@@ -13,11 +13,9 @@
 
 import java.util.Iterator ;
 import java.util.HashSet;
-import java.util.Collections;
 
 import java.io.IOException ;
 import java.io.ByteArrayInputStream ;
-import java.rmi.Naming;
 
 import javax.naming.Name ;
 import javax.naming.NamingException;

Mime
View raw message