directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r810338 - in /directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core: ./ partition/ schema/
Date Wed, 02 Sep 2009 02:35:34 GMT
Author: akarasulu
Date: Wed Sep  2 02:35:33 2009
New Revision: 810338

URL: http://svn.apache.org/viewvc?rev=810338&view=rev
Log:
The SchemaPartition has been put into place to cleanup much of the initialization code in DirectoryService.

Added:
    directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartition.java
      - copied, changed from r810260, directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/partition/SchemaPartition.java
Removed:
    directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/partition/SchemaPartition.java
Modified:
    directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
    directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DirectoryService.java
    directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
    directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java

Modified: directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?rev=810338&r1=810337&r2=810338&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java (original)
+++ directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java Wed Sep  2 02:35:33 2009
@@ -54,20 +54,14 @@
 import org.apache.directory.server.core.partition.DefaultPartitionNexus;
 import org.apache.directory.server.core.partition.Partition;
 import org.apache.directory.server.core.partition.PartitionNexus;
-import org.apache.directory.server.core.partition.impl.btree.BTreePartition;
-import org.apache.directory.server.xdbm.Index;
 
 import org.apache.directory.server.core.referral.ReferralInterceptor;
 import org.apache.directory.server.core.replication.ReplicationConfiguration;
-import org.apache.directory.server.core.schema.PartitionSchemaLoader;
 import org.apache.directory.server.core.schema.SchemaInterceptor;
-import org.apache.directory.server.core.schema.SchemaOperationControl;
-import org.apache.directory.server.core.schema.SchemaPartitionDao;
 import org.apache.directory.server.core.schema.SchemaService;
 import org.apache.directory.server.core.security.TlsKeyGenerator;
 import org.apache.directory.server.core.subtree.SubentryInterceptor;
 import org.apache.directory.server.core.trigger.TriggerInterceptor;
-import org.apache.directory.shared.ldap.schema.registries.Schema;
 import org.apache.directory.shared.ldap.NotImplementedException;
 import org.apache.directory.shared.ldap.constants.AuthenticationLevel;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
@@ -84,16 +78,12 @@
 import org.apache.directory.shared.ldap.ldif.LdifReader;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
-import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.SchemaUtils;
-import org.apache.directory.shared.ldap.schema.comparators.SerializableComparator;
-import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
 import org.apache.directory.shared.ldap.schema.normalizers.OidNormalizer;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
 import org.apache.directory.shared.ldap.util.AttributeUtils;
 import org.apache.directory.shared.ldap.util.DateUtils;
 import org.apache.directory.shared.ldap.util.StringTools;
-import org.apache.directory.shared.schema.loader.ldif.LdifSchemaLoader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -122,15 +112,8 @@
 {
     /** The logger */
     private static final Logger LOG = LoggerFactory.getLogger( DefaultDirectoryService.class );
-
-    private static final String ILLEGAL_STATE_MSG = "Something has got to be severely " +
-    "wrong with the core packaging\nor the build to have " +
-    "resulted in this exception.";
     
     private SchemaService schemaService;
-
-    /** the registries for system schema objects */
-    private Registries registries;
     
     /** the root nexus */
     private PartitionNexus partitionNexus;
@@ -302,6 +285,8 @@
     // ------------------------------------------------------------------------
     // Constructor
     // ------------------------------------------------------------------------
+    
+    
     /**
      * Creates a new instance of the directory service.
      */
@@ -312,13 +297,14 @@
         journal = new DefaultJournal();
         syncPeriodMillis = DEFAULT_SYNC_PERIOD;
         csnFactory = new CsnFactory( replicaId );
-        registries = new Registries();
     }
 
 
     // ------------------------------------------------------------------------
     // C O N F I G U R A T I O N   M E T H O D S
     // ------------------------------------------------------------------------
+    
+    
     public void setInstanceId( String instanceId )
     {
         this.instanceId = instanceId;
@@ -835,7 +821,7 @@
                     {
                         case ChangeType.ADD_ORDINAL :
                             adminSession.add( 
-                                new DefaultServerEntry( registries, reverse.getEntry() ), true ); 
+                                new DefaultServerEntry( getRegistries(), reverse.getEntry() ), true ); 
                             break;
                             
                         case ChangeType.DELETE_ORDINAL :
@@ -1033,13 +1019,7 @@
      */
     public Registries getRegistries()
     {
-        return registries;
-    }
-
-
-    public void setRegistries( Registries registries )
-    {
-        this.registries = registries;
+        return schemaService.getRegistries();
     }
 
 
@@ -1081,7 +1061,7 @@
 
     public ServerEntry newEntry( LdapDN dn ) 
     {
-        return new DefaultServerEntry( registries, dn );
+        return new DefaultServerEntry( getRegistries(), dn );
     }
     
 
@@ -1108,7 +1088,7 @@
         {
             firstStart = true;
 
-            ServerEntry serverEntry = new DefaultServerEntry( registries, PartitionNexus.getAdminName() );
+            ServerEntry serverEntry = new DefaultServerEntry( getRegistries(), PartitionNexus.getAdminName() );
             
             serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, 
                                 SchemaConstants.TOP_OC,
@@ -1135,7 +1115,7 @@
         // create system users area
         // -------------------------------------------------------------------
 
-        Map<String,OidNormalizer> oidsMap = registries.getAttributeTypeRegistry().getNormalizerMapping();
+        Map<String,OidNormalizer> oidsMap = getRegistries().getAttributeTypeRegistry().getNormalizerMapping();
         LdapDN userDn = new LdapDN( ServerDNConstants.USERS_SYSTEM_DN );
         userDn.normalize( oidsMap );
         
@@ -1143,7 +1123,7 @@
         {
             firstStart = true;
 
-            ServerEntry serverEntry = new DefaultServerEntry( registries, userDn );
+            ServerEntry serverEntry = new DefaultServerEntry( getRegistries(), userDn );
             
             serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, 
                                 SchemaConstants.TOP_OC,
@@ -1169,7 +1149,7 @@
         {
             firstStart = true;
 
-            ServerEntry serverEntry = new DefaultServerEntry( registries, groupDn );
+            ServerEntry serverEntry = new DefaultServerEntry( getRegistries(), groupDn );
             
             serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, 
                                 SchemaConstants.TOP_OC,
@@ -1195,7 +1175,7 @@
         {
             firstStart = true;
 
-            ServerEntry serverEntry = new DefaultServerEntry( registries, name );
+            ServerEntry serverEntry = new DefaultServerEntry( getRegistries(), name );
             
             serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, 
                                 SchemaConstants.TOP_OC,
@@ -1245,7 +1225,7 @@
         {
             firstStart = true;
 
-            ServerEntry serverEntry = new DefaultServerEntry( registries, configurationDn );
+            ServerEntry serverEntry = new DefaultServerEntry( getRegistries(), configurationDn );
             serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.ORGANIZATIONAL_UNIT_OC );
 
             serverEntry.put( SchemaConstants.OU_AT, "configuration" );
@@ -1268,7 +1248,7 @@
         {
             firstStart = true;
 
-            ServerEntry serverEntry = new DefaultServerEntry( registries, partitionsDn );
+            ServerEntry serverEntry = new DefaultServerEntry( getRegistries(), partitionsDn );
             serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.ORGANIZATIONAL_UNIT_OC );
             serverEntry.put( SchemaConstants.OU_AT, "partitions" );
             serverEntry.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
@@ -1290,7 +1270,7 @@
         {
             firstStart = true;
 
-            ServerEntry serverEntry = new DefaultServerEntry( registries, servicesDn );
+            ServerEntry serverEntry = new DefaultServerEntry( getRegistries(), servicesDn );
             serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.ORGANIZATIONAL_UNIT_OC );
 
             serverEntry.put( SchemaConstants.OU_AT, "services" );
@@ -1313,7 +1293,7 @@
         {
             firstStart = true;
 
-            ServerEntry serverEntry = new DefaultServerEntry( registries, interceptorsDn );
+            ServerEntry serverEntry = new DefaultServerEntry( getRegistries(), interceptorsDn );
             serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.ORGANIZATIONAL_UNIT_OC );
 
             serverEntry.put( SchemaConstants.OU_AT, "interceptors" );
@@ -1336,7 +1316,7 @@
         {
             firstStart = true;
 
-            ServerEntry serverEntry = new DefaultServerEntry( registries, sysPrefRootDn );
+            ServerEntry serverEntry = new DefaultServerEntry( getRegistries(), sysPrefRootDn );
             serverEntry.put( SchemaConstants.OBJECT_CLASS_AT, 
                 SchemaConstants.TOP_OC, 
                 SchemaConstants.ORGANIZATIONAL_UNIT_OC,
@@ -1365,7 +1345,7 @@
         boolean needToChangeAdminPassword = false;
 
         LdapDN adminDn = new LdapDN( ServerDNConstants.ADMIN_SYSTEM_DN );
-        adminDn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        adminDn.normalize( getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
         
         ServerEntry adminEntry = partitionNexus.lookup( new LookupOperationContext( adminSession, adminDn ) );
         Object userPassword = adminEntry.get( SchemaConstants.USER_PASSWORD_AT ).get();
@@ -1406,8 +1386,7 @@
 
                 try
                 {
-                    getAdminSession().add( 
-                        new DefaultServerEntry( registries, entry ) ); 
+                    getAdminSession().add( new DefaultServerEntry( getRegistries(), entry ) ); 
                 }
                 catch ( Exception e )
                 {
@@ -1434,135 +1413,22 @@
             LOG.debug( "---> Initializing the DefaultDirectoryService " );
         }
 
-        // --------------------------------------------------------------------
-        // If not present extract schema repository from jar
-        // --------------------------------------------------------------------
-
-        File schemaRepository = new File( workingDirectory, "schema" );
-        SchemaLdifExtractor extractor = new SchemaLdifExtractor( workingDirectory );
-        extractor.extractOrCopy();
-        LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
-        registries = new Registries();
-        
-        // --------------------------------------------------------------------
-        // Load schemas into the schema registry from LDIF schema repository
-        // --------------------------------------------------------------------
-        
-        try
-        {
-            loader.loadAllEnabled( registries );
-        }
-        catch ( Exception e )
-        {
-            throw new IllegalStateException( ILLEGAL_STATE_MSG, e );
-        }
-
-        // run referential integrity tests
-        List<Throwable> errors = registries.checkRefInteg();
-        
-        if ( !errors.isEmpty() )
-        {
-            NamingException e = new NamingException();
-            e.setRootCause( errors.get( 0 ) );
-            throw new IllegalStateException( ILLEGAL_STATE_MSG, e );
-        }
-        
-        SerializableComparator.setRegistry( registries.getComparatorRegistry() );
-        
-        // --------------------------------------------------------------------
-        // Initialize schema partition
-        // --------------------------------------------------------------------
-
-        // @TODO implement the LDIF schema partition here and set it up
-        
-        Partition schemaPartition = null;
-        
-        // this is really dumb but ...
-        // just bail but do so so we don't dead code complaint for now
-        if ( "blah".equals( "blah" ) )
-        {
-        	throw new NotImplementedException();
-        }
-        
-        // --------------------------------------------------------------------
-        // Enable schemas of all indices of partition configurations 
-        // --------------------------------------------------------------------
-
-        /*
-         * We need to make sure that every attribute indexed by a partition is
-         * loaded into the registries on the next step.  So here we must enable
-         * the schemas of those attributes so they are loaded into the global
-         * registries.
-         */
-        
-        SchemaPartitionDao dao = new SchemaPartitionDao( schemaPartition, registries );
-        Map<String,Schema> schemaMap = dao.getSchemas();
-        Set<Partition> partitions = new HashSet<Partition>();
-        partitions.add( systemPartition );
-        partitions.addAll( this.partitions );
-
-        for ( Partition partition : partitions )
-        {
-            if ( partition instanceof BTreePartition )
-            {
-                BTreePartition btpconf = ( BTreePartition ) partition;
-                for ( Index<?,ServerEntry> index : btpconf.getIndexedAttributes() )
-                {
-                    String schemaName = null;
-                    
-                    try
-                    {
-                        // Try to retrieve the AT in the registries
-                        AttributeType at = registries.getAttributeTypeRegistry().lookup( index.getAttributeId() );
-                        schemaName = dao.findSchema( at.getOid() );
-                    }
-                    catch ( Exception e )
-                    {
-                        // It does not exists: just use the attribute ID
-                        schemaName = dao.findSchema( index.getAttributeId() );
-                    }
-                    
-                    if ( schemaName == null )
-                    {
-                        throw new NamingException( "Index on unidentified attribute: " + index.toString() );
-                    }
-
-                    Schema schema = schemaMap.get( schemaName );
-                    if ( schema.isDisabled() )
-                    {
-                        dao.enableSchema( schemaName );
-                    }
-                }
-            }
-        }
-        
-        // --------------------------------------------------------------------
-        // Initialize schema subsystem and reset registries
-        // --------------------------------------------------------------------
-        
-        PartitionSchemaLoader schemaLoader = new PartitionSchemaLoader( schemaPartition, registries );
-        Registries globalRegistries = new Registries();
-        schemaLoader.loadEnabled( globalRegistries );
-        registries = globalRegistries;
-        SerializableComparator.setRegistry( globalRegistries.getComparatorRegistry() );
-
-        SchemaOperationControl schemaControl = new SchemaOperationControl( registries, schemaLoader,
-            new SchemaPartitionDao( schemaPartition, registries ) );
-
-        schemaService = new SchemaService( this, schemaPartition, schemaControl );
+        // triggers partition to load schema fully from schema partition
+        schemaService.getSchemaPartition().init( this );
 
         adminDn = new LdapDN( ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED );
-        adminDn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        adminDn.normalize( getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
         adminSession = new DefaultCoreSession( new LdapPrincipal( adminDn, AuthenticationLevel.STRONG ), this );
-
+        
         // @TODO - NOTE: Need to find a way to instantiate without dependency on DPN
-        partitionNexus = new DefaultPartitionNexus( new DefaultServerEntry( registries, LdapDN.EMPTY_LDAPDN ) );
+        partitionNexus = new DefaultPartitionNexus( new DefaultServerEntry( getRegistries(), LdapDN.EMPTY_LDAPDN ) );
         partitionNexus.init( this );
-        partitionNexus.addContextPartition( new AddContextPartitionOperationContext( adminSession, schemaPartition ) );
+        partitionNexus.addContextPartition( new AddContextPartitionOperationContext( adminSession, schemaService.getSchemaPartition() ) );
 
         // --------------------------------------------------------------------
         // Create all the bootstrap entries before initializing chain
         // --------------------------------------------------------------------
+        
         firstStart = createBootstrapEntries();
 
         interceptorChain = new InterceptorChain();
@@ -1571,6 +1437,7 @@
         // --------------------------------------------------------------------
         // Initialize the changeLog if it's enabled
         // --------------------------------------------------------------------
+        
         if ( changeLog.isEnabled() )
         {
             changeLog.init( this );
@@ -1681,7 +1548,7 @@
             entry.setDn( ldapDn );
             
             // TODO Let's get rid of this Attributes crap
-            ServerEntry serverEntry = new DefaultServerEntry( registries, entry );
+            ServerEntry serverEntry = new DefaultServerEntry( getRegistries(), entry );
             return serverEntry;
         }
         catch ( Exception e )

Modified: directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DirectoryService.java?rev=810338&r1=810337&r2=810338&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DirectoryService.java (original)
+++ directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/DirectoryService.java Wed Sep  2 02:35:33 2009
@@ -105,15 +105,6 @@
 
 
     /**
-     * Inject the registries into the directory service
-     * 
-     * @org.apache.xbean.Property hidden="true"
-     * @param registries The new registries
-     */
-    void setRegistries( Registries registries );
-
-
-    /**
      * @return The referral manager
      */
     ReferralManager getReferralManager();

Modified: directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java?rev=810338&r1=810337&r2=810338&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java (original)
+++ directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaInterceptor.java Wed Sep  2 02:35:33 2009
@@ -49,12 +49,9 @@
 import org.apache.directory.server.core.interceptor.BaseInterceptor;
 import org.apache.directory.server.core.interceptor.NextInterceptor;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
-import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
 import org.apache.directory.server.core.interceptor.context.ListOperationContext;
 import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
 import org.apache.directory.server.core.interceptor.context.ModifyOperationContext;
-import org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext;
-import org.apache.directory.server.core.interceptor.context.MoveOperationContext;
 import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
 import org.apache.directory.server.core.interceptor.context.SearchingOperationContext;
@@ -213,7 +210,7 @@
         schemaBaseDN = new LdapDN( ServerDNConstants.OU_SCHEMA_DN );
         schemaBaseDN.normalize( atRegistry.getNormalizerMapping() );
         schemaService = directoryService.getSchemaService();
-        schemaManager = directoryService.getSchemaService().getSchemaControl();
+        schemaManager = schemaService.getSchemaPartition().getSchemaControl();
 
         // stuff for dealing with subentries (garbage for now)
         Value<?> subschemaSubentry = nexus.getRootDSE( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get();
@@ -1106,36 +1103,6 @@
     }
 
 
-    public void moveAndRename( NextInterceptor next, MoveAndRenameOperationContext opContext ) throws Exception
-    {
-        LdapDN oriChildName = opContext.getDn();
-
-        ClonedServerEntry entry = opContext.lookup( oriChildName, ByPassConstants.LOOKUP_BYPASS );
-
-        if ( oriChildName.startsWith( schemaBaseDN ) )
-        {
-            schemaManager.move( opContext, entry, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
-        }
-
-        next.moveAndRename( opContext );
-    }
-
-
-    public void move( NextInterceptor next, MoveOperationContext opContext ) throws Exception
-    {
-        LdapDN oriChildName = opContext.getDn();
-
-        ClonedServerEntry entry = opContext.lookup( oriChildName, ByPassConstants.LOOKUP_BYPASS );
-
-        if ( oriChildName.startsWith( schemaBaseDN ) )
-        {
-            schemaManager.replace( opContext, entry, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
-        }
-
-        next.move( opContext );
-    }
-
-
     public void rename( NextInterceptor next, RenameOperationContext opContext ) throws Exception
     {
         LdapDN name = opContext.getDn();
@@ -1193,11 +1160,6 @@
             }
         }
 
-        if ( name.startsWith( schemaBaseDN ) )
-        {
-            schemaManager.modifyRn( opContext, entry, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
-        }
-
         next.rename( opContext );
     }
 
@@ -1509,14 +1471,7 @@
             }
         }
 
-        if ( schemaModification )
-        {
-            LOG.debug( "Modification attempt on schema partition {}: \n{}", name, opContext );
-
-            schemaManager.modify( opContext, entry, targetEntry, opContext
-                .hasRequestControl( CascadeControl.CONTROL_OID ) );
-        }
-        else if ( subSchemaModification )
+        if ( subSchemaModification )
         {
             LOG.debug( "Modification attempt on schema subentry {}: \n{}", name, opContext );
 
@@ -2033,8 +1988,6 @@
         // Special checks for the MetaSchema branch
         if ( name.startsWith( schemaBaseDN ) )
         {
-            schemaManager.add( addContext );
-            
             if ( entry.contains( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.META_SCHEMA_OC ) )
             {
                 // This is a schema addition
@@ -2121,20 +2074,6 @@
     }
 
 
-    public void delete( NextInterceptor next, DeleteOperationContext opContext ) throws Exception
-    {
-        LdapDN name = opContext.getDn();
-
-        if ( name.startsWith( schemaBaseDN ) )
-        {
-            ClonedServerEntry entry = nexus.lookup( opContext.newLookupContext( name ) );
-            schemaManager.delete( opContext, entry, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
-        }
-
-        next.delete( opContext );
-    }
-
-
     /**
      * Checks to see number of values of an attribute conforms to the schema
      */

Copied: directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartition.java (from r810260, directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/partition/SchemaPartition.java)
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartition.java?p2=directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartition.java&p1=directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/partition/SchemaPartition.java&r1=810260&r2=810338&rev=810338&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/partition/SchemaPartition.java (original)
+++ directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaPartition.java Wed Sep  2 02:35:33 2009
@@ -17,15 +17,18 @@
  *   under the License.
  *
  */
-package org.apache.directory.server.core.partition;
+package org.apache.directory.server.core.schema;
 
 
-import java.net.URL;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 
 import javax.naming.NamingException;
 
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.entry.ClonedServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
 import org.apache.directory.server.core.interceptor.context.BindOperationContext;
@@ -38,9 +41,21 @@
 import org.apache.directory.server.core.interceptor.context.RenameOperationContext;
 import org.apache.directory.server.core.interceptor.context.SearchOperationContext;
 import org.apache.directory.server.core.interceptor.context.UnbindOperationContext;
+import org.apache.directory.server.core.partition.AbstractPartition;
+import org.apache.directory.server.core.partition.ByPassConstants;
+import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.server.core.partition.impl.btree.BTreePartition;
+import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.shared.ldap.constants.MetaSchemaConstants;
+import org.apache.directory.shared.ldap.message.control.CascadeControl;
 import org.apache.directory.shared.ldap.name.LdapDN;
-import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.SchemaUtils;
+import org.apache.directory.shared.ldap.schema.comparators.SerializableComparator;
 import org.apache.directory.shared.ldap.schema.registries.Registries;
+import org.apache.directory.shared.ldap.schema.registries.Schema;
+import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
+import org.apache.directory.shared.schema.loader.ldif.JarLdifSchemaLoader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -106,6 +121,11 @@
     /** the registries managed by this SchemaPartition */
     private Registries registries = new Registries();
     
+    /** the schema loader used: gets swapped out right after init */
+    private SchemaLoader loader = new JarLdifSchemaLoader();
+
+    private SchemaOperationControl schemaManager;
+    
     
     /**
      * Creates a new instance of SchemaPartition.
@@ -119,20 +139,40 @@
         // Load apachemeta schema from within the ldap-schema Jar with all the
         // schema it depends on.  This is a minimal mandatory set of schemas.
         // -----------------------------------------------------------------------
-        
-        // @TODO - load apachemeta into registries
-        
-        URL url = SchemaLdifExtractor.getUniqueResource( "schema.ldif", "the base schema.ldif file" );
-        LOG.debug( "Found schema.ldif file in jar: {}", url );
+
+        loader.loadWithDependencies( loader.getSchema( MetaSchemaConstants.SCHEMA_NAME ), registries );
+        SerializableComparator.setRegistry( registries.getComparatorRegistry() );
     }
 
     
+    public SchemaOperationControl getSchemaControl()
+    {
+        return schemaManager;
+    }
+    
+    
     public Registries getRegistries()
     {
         return registries;
     }
     
     
+    public void setWrappedPartition( Partition wrapped )
+    {
+        if ( this.isInitialized() )
+        {
+            throw new IllegalStateException( "Not allowed to set the wrappedPartition after initialization." );
+        }
+        this.wrapped = wrapped;
+    }
+    
+    
+    public Partition getWrappedPartition()
+    {
+        return this.wrapped;
+    }
+    
+    
     // -----------------------------------------------------------------------
     // Partition Interface Method Overrides
     // -----------------------------------------------------------------------
@@ -148,13 +188,68 @@
     @Override
     protected void doInit()
     {
-        getDirectoryService().setRegistries( registries );
         wrapped.setId( ID );
         wrapped.setSuffix( ServerDNConstants.OU_SCHEMA_DN );
         
         try
         {
             wrapped.init( getDirectoryService() );
+            PartitionSchemaLoader partitionLoader = new PartitionSchemaLoader( wrapped, registries );
+            partitionLoader.loadAllEnabled( registries );
+            loader = partitionLoader;
+
+            SchemaPartitionDao dao = new SchemaPartitionDao( wrapped, registries );
+            schemaManager = new SchemaOperationControl( registries, partitionLoader, dao );
+            
+            // --------------------------------------------------------------------
+            // Make sure all schema with attributes that are indexed are enabled
+            // --------------------------------------------------------------------
+
+            /*
+             * We need to make sure that every attribute indexed by a partition is
+             * loaded into the registries on the next step.  So here we must enable
+             * the schemas of those attributes so they are loaded into the global
+             * registries.
+             */
+            Map<String,Schema> schemaMap = dao.getSchemas();
+            Set<Partition> partitions = new HashSet<Partition>();
+            partitions.add( getDirectoryService().getSystemPartition() );
+            partitions.addAll( getDirectoryService().getPartitions() );
+
+            for ( Partition partition : partitions )
+            {
+                if ( partition instanceof BTreePartition )
+                {
+                    BTreePartition btpconf = ( BTreePartition ) partition;
+                    for ( Index<?,ServerEntry> index : btpconf.getIndexedAttributes() )
+                    {
+                        String schemaName = null;
+                        
+                        try
+                        {
+                            // Try to retrieve the AT in the registries
+                            AttributeType at = registries.getAttributeTypeRegistry().lookup( index.getAttributeId() );
+                            schemaName = dao.findSchema( at.getOid() );
+                        }
+                        catch ( Exception e )
+                        {
+                            // It does not exists: just use the attribute ID
+                            schemaName = dao.findSchema( index.getAttributeId() );
+                        }
+                        
+                        if ( schemaName == null )
+                        {
+                            throw new NamingException( "Index on unidentified attribute: " + index.toString() );
+                        }
+
+                        Schema schema = schemaMap.get( schemaName );
+                        if ( schema.isDisabled() )
+                        {
+                            dao.enableSchema( schemaName );
+                        }
+                    }
+                }
+            }
         }
         catch ( Exception e )
         {
@@ -189,6 +284,7 @@
      */
     public void add( AddOperationContext opContext ) throws Exception
     {
+        schemaManager.add( opContext );
         wrapped.add( opContext );
     }
 
@@ -207,6 +303,8 @@
      */
     public void delete( DeleteOperationContext opContext ) throws Exception
     {
+        ClonedServerEntry entry = directoryService.getPartitionNexus().lookup( opContext.newLookupContext( opContext.getDn() ) );
+        schemaManager.delete( opContext, entry, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
         wrapped.delete( opContext );
     }
 
@@ -279,6 +377,13 @@
      */
     public void modify( ModifyOperationContext opContext ) throws Exception
     {
+        LOG.debug( "Modification attempt on schema partition {}: \n{}", opContext.getDn(), opContext );
+
+        ServerEntry targetEntry = ( ServerEntry ) SchemaUtils.getTargetEntry( 
+            opContext.getModItems(), opContext.getEntry() );
+
+        schemaManager.modify( opContext, opContext.getEntry(), targetEntry, opContext
+            .hasRequestControl( CascadeControl.CONTROL_OID ) );
         wrapped.modify( opContext );
     }
 
@@ -288,6 +393,9 @@
      */
     public void move( MoveOperationContext opContext ) throws Exception
     {
+        LdapDN oriChildName = opContext.getDn();
+        ClonedServerEntry entry = opContext.lookup( oriChildName, ByPassConstants.LOOKUP_BYPASS );
+        schemaManager.replace( opContext, entry, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
         wrapped.move( opContext );
     }
 
@@ -297,6 +405,9 @@
      */
     public void moveAndRename( MoveAndRenameOperationContext opContext ) throws Exception
     {
+        LdapDN oriChildName = opContext.getDn();
+        ClonedServerEntry entry = opContext.lookup( oriChildName, ByPassConstants.LOOKUP_BYPASS );
+        schemaManager.move( opContext, entry, opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
         wrapped.moveAndRename( opContext );
     }
 
@@ -306,6 +417,7 @@
      */
     public void rename( RenameOperationContext opContext ) throws Exception
     {
+        schemaManager.modifyRn( opContext, opContext.getEntry(), opContext.hasRequestControl( CascadeControl.CONTROL_OID ) );
         wrapped.rename( opContext );
     }
 

Modified: directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java?rev=810338&r1=810337&r2=810338&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java (original)
+++ directory/apacheds/branches/apacheds-schema/core/src/main/java/org/apache/directory/server/core/schema/SchemaService.java Wed Sep  2 02:35:33 2009
@@ -21,13 +21,11 @@
 
 import org.apache.directory.server.constants.ApacheSchemaConstants;
 import org.apache.directory.server.constants.ServerDNConstants;
-import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.entry.DefaultServerAttribute;
 import org.apache.directory.server.core.entry.DefaultServerEntry;
 import org.apache.directory.server.core.entry.ServerAttribute;
 import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
-import org.apache.directory.server.core.partition.Partition;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.name.LdapDN;
@@ -66,14 +64,8 @@
     private ServerEntry schemaSubentry;
     private final Object lock = new Object();
 
-    /** a handle on the registries */
-    private Registries registries;
-
     /** a handle on the schema partition */
-    private Partition schemaPartition;
-
-    /** schema operation control */
-    private SchemaOperationControl schemaControl;
+    private SchemaPartition schemaPartition;
 
     /**
      * the normalized name for the schema modification attributes
@@ -82,25 +74,6 @@
 
 
     /**
-     * Create a new instance of the schemaService
-     * 
-     * @param registries The associated registries
-     * @param schemaPartition The schema partition reference
-     * @param schemaControl The schema control instance
-     * @throws NamingException If somethi,ng went wrong during initialization
-     */
-    public SchemaService( DirectoryService directoryService, Partition schemaPartition, SchemaOperationControl schemaControl ) throws NamingException
-    {
-        this.registries = directoryService.getRegistries();
-        this.schemaPartition = schemaPartition;
-        this.schemaControl = schemaControl;
-
-        schemaModificationAttributesDN = new LdapDN( ServerDNConstants.SCHEMA_TIMESTAMP_ENTRY_DN );
-        schemaModificationAttributesDN.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
-    }
-
-
-    /**
      * Tells if the given DN is the schemaSubentry DN
      * 
      * @param dnString The DN we want to check
@@ -115,17 +88,39 @@
             return true;
         }
 
-        LdapDN dn = new LdapDN( dnString ).normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
+        LdapDN dn = new LdapDN( dnString ).normalize( schemaPartition.getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
         return dn.getNormName().equals( ServerDNConstants.CN_SCHEMA_DN_NORMALIZED );
     }
 
 
     /**
-     * @return The dirctoryService associated regirstries
+     * @return the registries loaded from schemaPartition
      */
-    public Registries getRegistries()
+    public final Registries getRegistries()
+    {
+        return schemaPartition.getRegistries();
+    }
+    
+    
+    public SchemaPartition getSchemaPartition()
+    {
+        return schemaPartition;
+    }
+    
+    
+    public void setSchemaPartition( SchemaPartition schemaPartition )
     {
-        return registries;
+        this.schemaPartition = schemaPartition;
+        try
+        {
+            schemaModificationAttributesDN = new LdapDN( ServerDNConstants.SCHEMA_TIMESTAMP_ENTRY_DN );
+            schemaModificationAttributesDN.normalize( 
+                getRegistries().getAttributeTypeRegistry().getNormalizerMapping() );
+        }
+        catch ( NamingException e )
+        {
+            throw new RuntimeException( e );
+        }
     }
 
 
@@ -135,9 +130,9 @@
     private ServerAttribute generateComparators() throws NamingException
     {
         ServerAttribute attr = new DefaultServerAttribute( 
-            registries.getAttributeTypeRegistry().lookup( SchemaConstants.COMPARATORS_AT ) );
+            getRegistries().getAttributeTypeRegistry().lookup( SchemaConstants.COMPARATORS_AT ) );
 
-        Iterator<LdapComparator<?>> list = registries.getComparatorRegistry().iterator();
+        Iterator<LdapComparator<?>> list = getRegistries().getComparatorRegistry().iterator();
         
         while ( list.hasNext() )
         {
@@ -151,9 +146,9 @@
     private ServerAttribute generateNormalizers() throws NamingException
     {
         ServerAttribute attr = new DefaultServerAttribute( 
-            registries.getAttributeTypeRegistry().lookup( SchemaConstants.NORMALIZERS_AT ) );
+            getRegistries().getAttributeTypeRegistry().lookup( SchemaConstants.NORMALIZERS_AT ) );
 
-        Iterator<Normalizer> list = registries.getNormalizerRegistry().iterator();
+        Iterator<Normalizer> list = getRegistries().getNormalizerRegistry().iterator();
 
         while ( list.hasNext() )
         {
@@ -167,9 +162,9 @@
     private ServerAttribute generateSyntaxCheckers() throws NamingException
     {
         ServerAttribute attr = new DefaultServerAttribute( 
-            registries.getAttributeTypeRegistry().lookup( SchemaConstants.SYNTAX_CHECKERS_AT ) );
+            getRegistries().getAttributeTypeRegistry().lookup( SchemaConstants.SYNTAX_CHECKERS_AT ) );
 
-        Iterator<SyntaxChecker> list = registries.getSyntaxCheckerRegistry().iterator();
+        Iterator<SyntaxChecker> list = getRegistries().getSyntaxCheckerRegistry().iterator();
 
         while ( list.hasNext() )
         {
@@ -183,9 +178,9 @@
     private ServerAttribute generateObjectClasses() throws NamingException
     {
         ServerAttribute attr = new DefaultServerAttribute( 
-            registries.getAttributeTypeRegistry().lookup( SchemaConstants.OBJECT_CLASSES_AT ) );
+            getRegistries().getAttributeTypeRegistry().lookup( SchemaConstants.OBJECT_CLASSES_AT ) );
 
-        Iterator<ObjectClass> list = registries.getObjectClassRegistry().iterator();
+        Iterator<ObjectClass> list = getRegistries().getObjectClassRegistry().iterator();
 
         while ( list.hasNext() )
         {
@@ -200,9 +195,9 @@
     private ServerAttribute generateAttributeTypes() throws NamingException
     {
         ServerAttribute attr = new DefaultServerAttribute( 
-            registries.getAttributeTypeRegistry().lookup( SchemaConstants.ATTRIBUTE_TYPES_AT ) );
+            getRegistries().getAttributeTypeRegistry().lookup( SchemaConstants.ATTRIBUTE_TYPES_AT ) );
 
-        Iterator<AttributeType> list = registries.getAttributeTypeRegistry().iterator();
+        Iterator<AttributeType> list = getRegistries().getAttributeTypeRegistry().iterator();
 
         while ( list.hasNext() )
         {
@@ -217,9 +212,9 @@
     private ServerAttribute generateMatchingRules() throws NamingException
     {
         ServerAttribute attr = new DefaultServerAttribute( 
-            registries.getAttributeTypeRegistry().lookup( SchemaConstants.MATCHING_RULES_AT ) );
+            getRegistries().getAttributeTypeRegistry().lookup( SchemaConstants.MATCHING_RULES_AT ) );
 
-        Iterator<MatchingRule> list = registries.getMatchingRuleRegistry().iterator();
+        Iterator<MatchingRule> list = getRegistries().getMatchingRuleRegistry().iterator();
 
         while ( list.hasNext() )
         {
@@ -234,9 +229,9 @@
     private ServerAttribute generateMatchingRuleUses() throws NamingException
     {
         ServerAttribute attr = new DefaultServerAttribute( 
-            registries.getAttributeTypeRegistry().lookup( SchemaConstants.MATCHING_RULE_USE_AT ) );
+            getRegistries().getAttributeTypeRegistry().lookup( SchemaConstants.MATCHING_RULE_USE_AT ) );
 
-        Iterator<MatchingRuleUse> list = registries.getMatchingRuleUseRegistry().iterator();
+        Iterator<MatchingRuleUse> list = getRegistries().getMatchingRuleUseRegistry().iterator();
 
         while ( list.hasNext() )
         {
@@ -251,9 +246,9 @@
     private ServerAttribute generateSyntaxes() throws NamingException
     {
         ServerAttribute attr = new DefaultServerAttribute( 
-            registries.getAttributeTypeRegistry().lookup( SchemaConstants.LDAP_SYNTAXES_AT ) );
+            getRegistries().getAttributeTypeRegistry().lookup( SchemaConstants.LDAP_SYNTAXES_AT ) );
 
-        Iterator<LdapSyntax> list = registries.getLdapSyntaxRegistry().iterator();
+        Iterator<LdapSyntax> list = getRegistries().getLdapSyntaxRegistry().iterator();
 
         while ( list.hasNext() )
         {
@@ -268,9 +263,9 @@
     private ServerAttribute generateDitContextRules() throws NamingException
     {
         ServerAttribute attr = new DefaultServerAttribute( 
-            registries.getAttributeTypeRegistry().lookup( SchemaConstants.DIT_CONTENT_RULES_AT ) );
+            getRegistries().getAttributeTypeRegistry().lookup( SchemaConstants.DIT_CONTENT_RULES_AT ) );
 
-        Iterator<DITContentRule> list = registries.getDitContentRuleRegistry().iterator();
+        Iterator<DITContentRule> list = getRegistries().getDitContentRuleRegistry().iterator();
 
         while ( list.hasNext() )
         {
@@ -285,9 +280,9 @@
     private ServerAttribute generateDitStructureRules() throws NamingException
     {
         ServerAttribute attr = new DefaultServerAttribute( 
-            registries.getAttributeTypeRegistry().lookup( SchemaConstants.DIT_STRUCTURE_RULES_AT ) );
+            getRegistries().getAttributeTypeRegistry().lookup( SchemaConstants.DIT_STRUCTURE_RULES_AT ) );
 
-        Iterator<DITStructureRule> list = registries.getDitStructureRuleRegistry().iterator();
+        Iterator<DITStructureRule> list = getRegistries().getDitStructureRuleRegistry().iterator();
 
         while ( list.hasNext() )
         {
@@ -302,9 +297,9 @@
     private ServerAttribute generateNameForms() throws NamingException
     {
         ServerAttribute attr = new DefaultServerAttribute( 
-            registries.getAttributeTypeRegistry().lookup( SchemaConstants.NAME_FORMS_AT ) );
+            getRegistries().getAttributeTypeRegistry().lookup( SchemaConstants.NAME_FORMS_AT ) );
 
-        Iterator<NameForm> list = registries.getNameFormRegistry().iterator();
+        Iterator<NameForm> list = getRegistries().getNameFormRegistry().iterator();
 
         while ( list.hasNext() )
         {
@@ -318,7 +313,7 @@
 
     private void generateSchemaSubentry( ServerEntry mods ) throws NamingException
     {
-        ServerEntry attrs = new DefaultServerEntry( registries, mods.getDn() );
+        ServerEntry attrs = new DefaultServerEntry( getRegistries(), mods.getDn() );
 
         // add the objectClass attribute
         attrs.put( SchemaConstants.OBJECT_CLASS_AT, 
@@ -350,7 +345,7 @@
         // -------------------------------------------------------------------
 
         // Add the createTimestamp
-        AttributeType createTimestampAT = registries.
+        AttributeType createTimestampAT = getRegistries().
             getAttributeTypeRegistry().lookup( SchemaConstants.CREATE_TIMESTAMP_AT );
         EntryAttribute createTimestamp = mods.get( createTimestampAT );
         attrs.put( SchemaConstants.CREATE_TIMESTAMP_AT, createTimestamp.get() );
@@ -359,13 +354,13 @@
         attrs.put( SchemaConstants.CREATORS_NAME_AT, ServerDNConstants.ADMIN_SYSTEM_DN );
 
         // Add the modifyTimestamp
-        AttributeType schemaModifyTimestampAT = registries.
+        AttributeType schemaModifyTimestampAT = getRegistries().
             getAttributeTypeRegistry().lookup( ApacheSchemaConstants.SCHEMA_MODIFY_TIMESTAMP_AT );
         EntryAttribute schemaModifyTimestamp = mods.get( schemaModifyTimestampAT );
         attrs.put( SchemaConstants.MODIFY_TIMESTAMP_AT, schemaModifyTimestamp.get() );
 
         // Add the modifiersName
-        AttributeType schemaModifiersNameAT = registries.
+        AttributeType schemaModifiersNameAT = getRegistries().
             getAttributeTypeRegistry().lookup( ApacheSchemaConstants.SCHEMA_MODIFIERS_NAME_AT );
         EntryAttribute schemaModifiersName = mods.get( schemaModifiersNameAT );
         attrs.put( SchemaConstants.MODIFIERS_NAME_AT, schemaModifiersName.get() );
@@ -442,7 +437,7 @@
         }
 
         Set<String> setOids = new HashSet<String>();
-        ServerEntry attrs = new DefaultServerEntry( registries, LdapDN.EMPTY_LDAPDN );
+        ServerEntry attrs = new DefaultServerEntry( getRegistries(), LdapDN.EMPTY_LDAPDN );
         boolean returnAllOperationalAttributes = false;
 
         synchronized( lock )
@@ -503,7 +498,7 @@
                 }
                 else
                 {
-                    setOids.add( registries.getAttributeTypeRegistry().getOidByName( id ) );
+                    setOids.add( getRegistries().getAttributeTypeRegistry().getOidByName( id ) );
                 }
             }
 
@@ -627,10 +622,4 @@
 
         return attrs;
     }
-
-
-    SchemaOperationControl getSchemaControl()
-    {
-        return schemaControl;
-    }
 }



Mime
View raw message