directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r834895 - in /directory: apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/s...
Date Wed, 11 Nov 2009 14:33:32 GMT
Author: elecharny
Date: Wed Nov 11 14:33:32 2009
New Revision: 834895

URL: http://svn.apache.org/viewvc?rev=834895&view=rev
Log:
Fix some tests in the ComparatorHandler. 

Modified:
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java
    directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
    directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultComparatorRegistry.java
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java?rev=834895&r1=834894&r2=834895&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/AttributeTypeSynchronizer.java
Wed Nov 11 14:33:32 2009
@@ -80,7 +80,7 @@
         // Build the new AttributeType from the given entry
         String schemaName = getSchemaName( dn );
         
-        // At this point, as we may break the regisytries, work on a cloned registries
+        // At this point, as we may break the registries, work on a cloned registries
         Registries clonedRegistries = schemaManager.getRegistries().clone();
         
         // Relax the cloned registries
@@ -96,7 +96,7 @@
             if ( errors.size() == 0 )
             {
                 clonedRegistries.setStrict();
-                schemaManager.setRegistries( clonedRegistries  );
+                schemaManager.swapRegistries( clonedRegistries  );
             }
             else
             {

Modified: directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java?rev=834895&r1=834894&r2=834895&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java
(original)
+++ directory/apacheds/branches/apacheds-schema/core-api/src/main/java/org/apache/directory/server/core/schema/registries/synchronizers/ComparatorSynchronizer.java
Wed Nov 11 14:33:32 2009
@@ -20,6 +20,8 @@
 package org.apache.directory.server.core.schema.registries.synchronizers;
 
 
+import java.util.List;
+
 import javax.naming.NamingException;
 
 import org.apache.directory.server.core.entry.ServerEntry;
@@ -34,6 +36,8 @@
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.LdapComparator;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.registries.Registries;
+import org.apache.directory.shared.ldap.schema.registries.Schema;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -106,18 +110,47 @@
         // Build the new Comparator from the given entry
         String schemaName = getSchemaName( dn );
         
+        // At this point, as we may break the registries, work on a cloned registries
+        Registries clonedRegistries = schemaManager.getRegistries().clone();
+        
+        // Relax the cloned registries
+        clonedRegistries.setRelaxed();
+        
         LdapComparator<?> comparator = factory.getLdapComparator( schemaManager, entry,
schemaManager.getRegistries(), schemaName );
         
         if ( comparator != null )
         {
-            addToSchema( comparator, schemaName );
+            List<Throwable> errors = clonedRegistries.checkRefInteg();
+            
+            if ( errors.size() == 0 )
+            {
+                clonedRegistries.setStrict();
+                schemaManager.swapRegistries( clonedRegistries  );
+            }
+            else
+            {
+                // We have some error : reject the addition and get out
+                return;
+            }
 
-            if ( isSchemaEnabled( schemaName ) && comparator.isEnabled() )
+            // At this point, the constructed LdapComparator has not been checked against
the 
+            // existing Registries. It will be checked there, if the schema and the 
+            // LdapComparator are both enabled.
+            Schema schema = schemaManager.getLoadedSchema( schemaName );
+            
+            if ( schema.isEnabled() && comparator.isEnabled() )
             {
+                comparator.applyRegistries( schemaManager.getRegistries() );
+                addToSchema( comparator, schemaName );
                 schemaManager.register( comparator );
                 LOG.debug( "Added {} into the enabled schema {}", dn.getUpName(), schemaName
);
             }
         }
+        else
+        {
+            LOG.debug( "The comparator {} cannot be added in schema {}", dn.getUpName(),
schemaName );
+
+        }
     }
 
 
@@ -148,9 +181,11 @@
                 LOG.warn( msg );
                 throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
             }
+
+            // As the comparator has the same OID than its attached MR, it won't
+            // be loaded into the schemaManager if it's disabled
+            deleteFromSchema( comparator, schemaName );
         }
-        
-        deleteFromSchema( comparator, schemaName );
 
         if ( schemaManager.getComparatorRegistry().contains( oid ) )
         {

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java?rev=834895&r1=834894&r2=834895&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/DefaultSchemaManager.java
Wed Nov 11 14:33:32 2009
@@ -164,26 +164,25 @@
     
     
     /***
-     * Swap the registries, deleting all the schemaObjects and links from the old one
-     * to avoid memory leaks.
+     * {@inheritDoc}
      */
-    private boolean swapRegistries( Registries clonedRegistries )
+    public boolean swapRegistries( Registries targetRegistries )
     {
         // Check the resulting registries
-        errors = clonedRegistries.checkRefInteg();
+        errors = targetRegistries.checkRefInteg();
         
         // if we have no more error, we can swap the registries
         if ( errors.size() == 0 )
         {
-            clonedRegistries.setStrict();
+            targetRegistries.setStrict();
             
             // Rebuild the references
-            errors = clonedRegistries.checkRefInteg();
+            errors = targetRegistries.checkRefInteg();
 
             if ( errors.size() == 0 )
             {
                 Registries oldRegistries = registries;
-                registries = clonedRegistries;
+                registries = targetRegistries;
 
                 // Delete the old registries to avoid memory leaks
                 //destroy( oldRegistries );

Modified: directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java?rev=834895&r1=834894&r2=834895&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
(original)
+++ directory/shared/branches/shared-schema/ldap-schema-loader/src/main/java/org/apache/directory/shared/schema/loader/ldif/SchemaEntityFactory.java
Wed Nov 11 14:33:32 2009
@@ -468,9 +468,7 @@
         String oid = getOid( entry, SchemaConstants.COMPARATOR );
         
         // Get the schema
-        Schema schema = getSchema( schemaName, targetRegistries );
-
-        if ( schema == null )
+        if ( !schemaManager.isSchemaLoaded( schemaName ) )
         {
             // The schema is not loaded. We can't create the requested Comparator
             String msg = "Cannot add the Comparator " + entry.getDn().getUpName() + ", as
the associated schema (" +
@@ -479,6 +477,17 @@
             throw new LdapOperationNotSupportedException( msg, ResultCodeEnum.UNWILLING_TO_PERFORM
);
         }
         
+        Schema schema = getSchema( schemaName, targetRegistries );
+        
+        if ( schema == null )
+        {
+            // The schema is disabled. We still have to update the backend
+            String msg = "Cannot add the Comparator " + entry.getDn().getUpName() + " into
the registries, "+
+                "as the associated schema (" + schemaName + ") is disabled";
+            LOG.info( msg );
+            schema = schemaManager.getLoadedSchema( schemaName );
+        }
+
         // The FQCN
         String fqcn = getFqcn( entry, SchemaConstants.COMPARATOR );
         
@@ -849,7 +858,7 @@
         {
             // The schema is disabled. We still have to update the backend
             String msg = "Cannot add the AttributeType " + entry.getDn().getUpName() + "
into the registries, "+
-                "as the associated schema (" + schemaName + " is disabled";
+                "as the associated schema (" + schemaName + ") is disabled";
             LOG.info( msg );
             schema = schemaManager.getLoadedSchema( schemaName );
         }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java?rev=834895&r1=834894&r2=834895&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SchemaManager.java
Wed Nov 11 14:33:32 2009
@@ -408,6 +408,16 @@
     void setRegistries( Registries registries );
     
     
+    /***
+     * Swap the registries, deleting all the schemaObjects and links from the old one
+     * to avoid memory leaks.
+     * 
+     * @param targetRegistries The registries we want to store in place of the existing one
+     * @return true if the replacement has been done
+     */
+    public boolean swapRegistries( Registries targetRegistries );
+    
+    
     /**
      * @return The errors obtained when checking the registries
      */

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultComparatorRegistry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultComparatorRegistry.java?rev=834895&r1=834894&r2=834895&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultComparatorRegistry.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/DefaultComparatorRegistry.java
Wed Nov 11 14:33:32 2009
@@ -163,4 +163,30 @@
     {
         return byName.values().size();
     }
+
+
+    /**
+     * @see Object#toString()
+     */
+    public String toString()
+    {
+        StringBuilder sb = new StringBuilder();
+        boolean isFirst = true;
+        
+        for ( String name:byName.keySet() )
+        {
+            if ( isFirst )
+            {
+                isFirst = false;
+            }
+            else
+            {
+                sb.append(  ", " );
+            }
+            
+            sb.append( name );
+        }
+        
+        return sb.toString();
+    }
 }

Modified: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java?rev=834895&r1=834894&r2=834895&view=diff
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
(original)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/registries/Registries.java
Wed Nov 11 14:33:32 2009
@@ -981,6 +981,10 @@
 	            attributeTypeRegistry.register( (AttributeType)schemaObject );
 	            break;
 	            
+	        case COMPARATOR :
+	            comparatorRegistry.register( (LdapComparator<?>)schemaObject );
+	            break;
+	            
             case DIT_CONTENT_RULE : 
                 ditContentRuleRegistry.register( (DITContentRule)schemaObject );
                 break;



Mime
View raw message