directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r925604 - in /directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core: annotations/ factory/
Date Sat, 20 Mar 2010 13:27:59 GMT
Author: seelmann
Date: Sat Mar 20 13:27:59 2010
New Revision: 925604

URL: http://svn.apache.org/viewvc?rev=925604&view=rev
Log:
Partial fix for DIRSERVER-1480:
o added PartitionFactory interface and implementations for JDBM, LDIF, AVL
o system and custom partitions are created via PartitionFactory, if no explicit partiton type
is provided

Added:
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/AvlPartitionFactory.java
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/JdbmPartitionFactory.java
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/LdifPartitionFactory.java
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/PartitionFactory.java
Modified:
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateIndex.java
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreatePartition.java
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DefaultDirectoryServiceFactory.java
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DirectoryServiceFactory.java

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateIndex.java?rev=925604&r1=925603&r2=925604&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateIndex.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateIndex.java
Sat Mar 20 13:27:59 2010
@@ -23,7 +23,6 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.xdbm.Index;
 
 /**
@@ -49,7 +48,8 @@ import org.apache.directory.server.xdbm.
 public @interface CreateIndex
 {
     /** The index implementation class */
-    Class<? extends Index> type() default JdbmIndex.class;
+    @SuppressWarnings("unchecked")
+    Class<? extends Index> type() default Index.class;
     
     /** The cache size */
     int cacheSize() default 1000;

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreatePartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreatePartition.java?rev=925604&r1=925603&r2=925604&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreatePartition.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreatePartition.java
Sat Mar 20 13:27:59 2010
@@ -24,7 +24,6 @@ import java.lang.annotation.RetentionPol
 import java.lang.annotation.Target;
 
 import org.apache.directory.server.core.partition.Partition;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
 
 /**
  * An annotation for the Partition creation. A partition is defined by
@@ -55,7 +54,7 @@ import org.apache.directory.server.core.
 public @interface CreatePartition
 {
     /** The partition implementation class */
-    Class<? extends Partition> type() default JdbmPartition.class;
+    Class<? extends Partition> type() default Partition.class;
     
     /** The partition name */
     String name();

Added: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/AvlPartitionFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/AvlPartitionFactory.java?rev=925604&view=auto
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/AvlPartitionFactory.java
(added)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/AvlPartitionFactory.java
Sat Mar 20 13:27:59 2010
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.factory;
+
+
+import java.io.File;
+import java.util.Set;
+
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.server.core.partition.avl.AvlIndex;
+import org.apache.directory.server.core.partition.avl.AvlPartition;
+import org.apache.directory.server.xdbm.Index;
+
+
+/**
+ * A factory used to generate {@link AvlPartition}s.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class AvlPartitionFactory implements PartitionFactory
+{
+
+    /**
+     * {@inheritDoc}
+     */
+    public AvlPartition createPartition( String id, String suffix, int cacheSize, File workingDirectory
)
+        throws Exception
+    {
+        AvlPartition partition = new AvlPartition();
+        partition.setId( id );
+        partition.setSuffix( suffix );
+        partition.setCacheSize( 500 );
+        partition.setPartitionDir( workingDirectory );
+        return partition;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addIndex( Partition partition, String attributeId, int cacheSize ) throws
Exception
+    {
+        if ( !( partition instanceof AvlPartition ) )
+        {
+            throw new IllegalArgumentException( "Partition must be a AvlPartition" );
+        }
+
+        AvlPartition avlPartition = ( AvlPartition ) partition;
+        Set<Index<? extends Object, ServerEntry, Long>> indexedAttributes = avlPartition.getIndexedAttributes();
+
+        AvlIndex<Object, ServerEntry> index = new AvlIndex<Object, ServerEntry>(
attributeId );
+        //index.setCacheSize( cacheSize );
+
+        indexedAttributes.add( index );
+        avlPartition.setIndexedAttributes( indexedAttributes );
+    }
+
+}

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java?rev=925604&r1=925603&r2=925604&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DSAnnotationProcessor.java
Sat Mar 20 13:27:59 2010
@@ -35,11 +35,11 @@ import org.apache.directory.server.core.
 import org.apache.directory.server.core.annotations.CreateIndex;
 import org.apache.directory.server.core.annotations.CreatePartition;
 import org.apache.directory.server.core.entry.DefaultServerEntry;
-import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.interceptor.Interceptor;
 import org.apache.directory.server.core.partition.Partition;
 import org.apache.directory.server.core.partition.impl.btree.BTreePartition;
 import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.server.xdbm.GenericIndex;
 import org.apache.directory.server.xdbm.Index;
 import org.apache.directory.shared.ldap.ldif.LdifEntry;
 import org.apache.directory.shared.ldap.ldif.LdifReader;
@@ -87,27 +87,57 @@ public class DSAnnotationProcessor
         // Process the Partition, if any.
         for ( CreatePartition createPartition : dsBuilder.partitions() )
         {
-            // Create the partition
-            Partition partition = createPartition.type().newInstance();
-            partition.setId( createPartition.name() );
-            partition.setSuffix( createPartition.suffix() );
-            partition.setSchemaManager( service.getSchemaManager() );
+            Partition partition;
 
-            if ( partition instanceof BTreePartition<?> )
+            // Determine the partition type
+            if ( createPartition.type() == Partition.class )
             {
-                BTreePartition<Object> btreePartition = ( BTreePartition<Object>
) partition;
-                btreePartition.setCacheSize( createPartition.cacheSize() );
-                btreePartition.setPartitionDir( new File( service.getWorkingDirectory(),
createPartition.name() ) );
+                // The annotation does not specify a specific partition type.
+                // We use the partition factory to create partition and index instances.
+                PartitionFactory partitionFactory = dsf.getPartitionFactory();
+                partition = partitionFactory.createPartition( createPartition.name(), createPartition.suffix(),
+                    createPartition.cacheSize(), new File( service.getWorkingDirectory(),
createPartition.name() ) );
 
-                // Process the indexes if any
                 CreateIndex[] indexes = createPartition.indexes();
-
                 for ( CreateIndex createIndex : indexes )
                 {
-                    Index<? extends Object, ServerEntry, Object> index = createIndex.type().newInstance();
-                    index.setAttributeId( createIndex.attribute() );
-                    index.setCacheSize( createIndex.cacheSize() );
-                    btreePartition.addIndexedAttributes( index );
+                    partitionFactory.addIndex( partition, createIndex.attribute(), createIndex.cacheSize()
);
+                }
+            }
+            else
+            {
+                // The annotation contains a specific partition type, we use that type.
+                partition = createPartition.type().newInstance();
+                partition.setId( createPartition.name() );
+                partition.setSuffix( createPartition.suffix() );
+
+                if ( partition instanceof BTreePartition<?> )
+                {
+                    BTreePartition<?> btreePartition = ( BTreePartition<?> )
partition;
+                    btreePartition.setCacheSize( createPartition.cacheSize() );
+                    btreePartition.setPartitionDir( new File( service.getWorkingDirectory(),
createPartition.name() ) );
+
+                    // Process the indexes if any
+                    CreateIndex[] indexes = createPartition.indexes();
+
+                    for ( CreateIndex createIndex : indexes )
+                    {
+                        Index index;
+                        if ( createIndex.type() == Index.class )
+                        {
+                            // The annotation does not specify a specific index type.
+                            // We use the generic index implementation.
+                            index = new GenericIndex( createIndex.attribute(), createIndex.cacheSize()
);
+                        }
+                        else
+                        {
+                            // The annotation contains a specific index type, we use that
type.
+                            index = createIndex.type().newInstance();
+                            index.setAttributeId( createIndex.attribute() );
+                            index.setCacheSize( createIndex.cacheSize() );
+                        }
+                        btreePartition.addIndexedAttributes( index );
+                    }
                 }
             }
 

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DefaultDirectoryServiceFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DefaultDirectoryServiceFactory.java?rev=925604&r1=925603&r2=925604&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DefaultDirectoryServiceFactory.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DefaultDirectoryServiceFactory.java
Sat Mar 20 13:27:59 2010
@@ -20,22 +20,16 @@ package org.apache.directory.server.core
 
 
 import java.io.File;
-import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.DefaultDirectoryService;
 import org.apache.directory.server.core.DirectoryService;
-import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.partition.Partition;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
 import org.apache.directory.server.core.partition.ldif.LdifPartition;
 import org.apache.directory.server.core.schema.SchemaPartition;
 import org.apache.directory.server.i18n.I18n;
-import org.apache.directory.server.xdbm.Index;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.schema.SchemaManager;
 import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
@@ -44,17 +38,20 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
 import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
 import org.apache.directory.shared.ldap.util.ExceptionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
- * A Default factory for DirectoryService
+ * A Default factory for DirectoryService.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
 public class DefaultDirectoryServiceFactory implements DirectoryServiceFactory
 {
-    private DirectoryService directoryService;
+    /** A logger for this class */
+    private static final Logger LOG = LoggerFactory.getLogger( DefaultDirectoryServiceFactory.class
);
 
     /**
      * The default factory returns stock instances of a directory
@@ -62,6 +59,12 @@ public class DefaultDirectoryServiceFact
      */
     public static final DirectoryServiceFactory DEFAULT = new DefaultDirectoryServiceFactory();
 
+    /** The directory service. */
+    private DirectoryService directoryService;
+
+    /** The partition factory. */
+    private PartitionFactory partitionFactory;
+
 
     /* default access */DefaultDirectoryServiceFactory()
     {
@@ -76,12 +79,34 @@ public class DefaultDirectoryServiceFact
         {
             throw new RuntimeException( e );
         }
+
+        try
+        {
+            String typeName = System.getProperty( "apacheds.partition.factory" );
+            if ( typeName != null )
+            {
+                Class<? extends PartitionFactory> type = ( Class<? extends PartitionFactory>
) Class.forName( typeName );
+                partitionFactory = type.newInstance();
+            }
+            else
+            {
+                partitionFactory = new JdbmPartitionFactory();
+            }
+        }
+        catch ( Exception e )
+        {
+            LOG.error( "Error instantiating custom partiton factory", e );
+            throw new RuntimeException( e );
+        }
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public void init( String name ) throws Exception
     {
-        if ( ( directoryService != null ) && ( directoryService.isStarted() ) )
+        if ( directoryService != null && directoryService.isStarted() )
         {
             return;
         }
@@ -106,6 +131,9 @@ public class DefaultDirectoryServiceFact
     }
 
 
+    /**
+     * Inits the schema and schema partition.
+     */
     private void initSchema() throws Exception
     {
         SchemaPartition schemaPartition = directoryService.getSchemaService().getSchemaPartition();
@@ -142,6 +170,11 @@ public class DefaultDirectoryServiceFact
     }
 
 
+    /**
+     * Inits the system partition.
+     * 
+     * @throws Exception the exception
+     */
     private void initSystemPartition() throws Exception
     {
         // change the working directory to something that is unique
@@ -149,35 +182,22 @@ public class DefaultDirectoryServiceFact
         // or somewhere in a temp area of the machine.
 
         // Inject the System Partition
-        Partition systemPartition = new JdbmPartition();
-        systemPartition.setId( "system" );
-        ( ( JdbmPartition ) systemPartition ).setCacheSize( 500 );
-        systemPartition.setSuffix( ServerDNConstants.SYSTEM_DN );
+        Partition systemPartition = partitionFactory.createPartition( "system", ServerDNConstants.SYSTEM_DN,
500,
+            new File( directoryService.getWorkingDirectory(), "system" ) );
         systemPartition.setSchemaManager( directoryService.getSchemaManager() );
-        ( ( JdbmPartition ) systemPartition ).setPartitionDir( new File( directoryService.getWorkingDirectory(),
-            "system" ) );
 
-        // Add objectClass attribute for the system partition
-        Set<Index<?, ServerEntry, Long>> indexedAttrs = new HashSet<Index<?,
ServerEntry, Long>>();
-        indexedAttrs.add( new JdbmIndex<Object, ServerEntry>( SchemaConstants.OBJECT_CLASS_AT
) );
-        ( ( JdbmPartition ) systemPartition ).setIndexedAttributes( indexedAttrs );
+        partitionFactory.addIndex( systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100
);
 
         directoryService.setSystemPartition( systemPartition );
     }
 
 
-    public void initJdbmPartition( String name, String suffix ) throws Exception
-    {
-        Partition partition = new JdbmPartition();
-        partition.setId( name );
-        partition.setSuffix( suffix );
-        partition.setSchemaManager( directoryService.getSchemaManager() );
-        ( ( JdbmPartition ) partition ).setPartitionDir( new File( directoryService.getWorkingDirectory(),
name ) );
-        directoryService.addPartition( partition );
-    }
-
-
-    public void build( String name ) throws Exception
+    /**
+     * Builds the directory server instance.
+     * 
+     * @param name the instance name
+     */
+    private void build( String name ) throws Exception
     {
         directoryService.setInstanceId( name );
         buildWorkingDirectory( name );
@@ -196,8 +216,20 @@ public class DefaultDirectoryServiceFact
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public DirectoryService getDirectoryService() throws Exception
     {
         return directoryService;
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public PartitionFactory getPartitionFactory() throws Exception
+    {
+        return partitionFactory;
+    }
 }

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DirectoryServiceFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DirectoryServiceFactory.java?rev=925604&r1=925603&r2=925604&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DirectoryServiceFactory.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/DirectoryServiceFactory.java
Sat Mar 20 13:27:59 2010
@@ -34,8 +34,26 @@ import org.apache.directory.server.core.
 public interface DirectoryServiceFactory
 {
 
+    /**
+     * Inits the directory service factory.
+     * 
+     * @param name the name
+     */
     void init( String name ) throws Exception;
 
 
+    /**
+     * Gets the directory service.
+     * 
+     * @return the directory service
+     */
     DirectoryService getDirectoryService() throws Exception;
+
+
+    /**
+     * Gets the partition factory.
+     * 
+     * @return the partition factory
+     */
+    PartitionFactory getPartitionFactory() throws Exception;
 }

Added: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/JdbmPartitionFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/JdbmPartitionFactory.java?rev=925604&view=auto
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/JdbmPartitionFactory.java
(added)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/JdbmPartitionFactory.java
Sat Mar 20 13:27:59 2010
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.factory;
+
+
+import java.io.File;
+import java.util.Set;
+
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
+import org.apache.directory.server.xdbm.Index;
+
+
+/**
+ * A factory used to generate {@link JdbmPartition}s.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class JdbmPartitionFactory implements PartitionFactory
+{
+
+    /**
+     * {@inheritDoc}
+     */
+    public JdbmPartition createPartition( String id, String suffix, int cacheSize, File workingDirectory
)
+        throws Exception
+    {
+        JdbmPartition partition = new JdbmPartition();
+        partition.setId( id );
+        partition.setSuffix( suffix );
+        partition.setCacheSize( 500 );
+        partition.setPartitionDir( workingDirectory );
+        return partition;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addIndex( Partition partition, String attributeId, int cacheSize ) throws
Exception
+    {
+        if ( !( partition instanceof JdbmPartition ) )
+        {
+            throw new IllegalArgumentException( "Partition must be a JdbmPartition" );
+        }
+
+        JdbmPartition jdbmPartition = ( JdbmPartition ) partition;
+        Set<Index<? extends Object, ServerEntry, Long>> indexedAttributes = jdbmPartition.getIndexedAttributes();
+
+        JdbmIndex<Object, ServerEntry> index = new JdbmIndex<Object, ServerEntry>(
attributeId );
+        index.setCacheSize( cacheSize );
+
+        indexedAttributes.add( index );
+        jdbmPartition.setIndexedAttributes( indexedAttributes );
+    }
+
+}

Added: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/LdifPartitionFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/LdifPartitionFactory.java?rev=925604&view=auto
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/LdifPartitionFactory.java
(added)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/LdifPartitionFactory.java
Sat Mar 20 13:27:59 2010
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.factory;
+
+
+import java.io.File;
+import java.util.Set;
+
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.server.core.partition.avl.AvlIndex;
+import org.apache.directory.server.core.partition.ldif.LdifPartition;
+import org.apache.directory.server.xdbm.Index;
+
+
+/**
+ * A factory used to generate {@link LdifPartition}s.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class LdifPartitionFactory implements PartitionFactory
+{
+
+    /**
+     * {@inheritDoc}
+     */
+    public LdifPartition createPartition( String id, String suffix, int cacheSize, File workingDirectory
)
+        throws Exception
+    {
+        LdifPartition partition = new LdifPartition();
+        partition.setId( id );
+        partition.setSuffix( suffix );
+        partition.setCacheSize( 500 );
+        partition.setWorkingDirectory( workingDirectory.getAbsolutePath() );
+        partition.setPartitionDir( workingDirectory );
+        return partition;
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addIndex( Partition partition, String attributeId, int cacheSize ) throws
Exception
+    {
+        if ( !( partition instanceof LdifPartition ) )
+        {
+            throw new IllegalArgumentException( "Partition must be a LdifPartition" );
+        }
+
+        LdifPartition ldifPartition = ( LdifPartition ) partition;
+        Set<Index<? extends Object, ServerEntry, Long>> indexedAttributes = ldifPartition.getIndexedAttributes();
+
+        AvlIndex<Object, ServerEntry> index = new AvlIndex<Object, ServerEntry>(
attributeId );
+        //index.setCacheSize( cacheSize );
+
+        indexedAttributes.add( index );
+        ldifPartition.setIndexedAttributes( indexedAttributes );
+    }
+
+}

Added: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/PartitionFactory.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/PartitionFactory.java?rev=925604&view=auto
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/PartitionFactory.java
(added)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/factory/PartitionFactory.java
Sat Mar 20 13:27:59 2010
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.factory;
+
+
+import java.io.File;
+
+import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.server.xdbm.Index;
+
+
+/**
+ * A factory used to generate {@link Partition}s and their {@link Index}es.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface PartitionFactory
+{
+
+    /**
+     * Creates a new Partition.
+     * 
+     * @param id the partition id
+     * @param suffix the suffix
+     * @param cacheSize the cache size
+     * @param workingDirectory the working directory
+     * @return the partition
+     * @throws Exception the exception
+     */
+    Partition createPartition( String id, String suffix, int cacheSize, File workingDirectory
) throws Exception;
+
+
+    /**
+     * Adds a partition-specific index to the partition.
+     * 
+     * @param partition the partition
+     * @param attrbuteId the attribute id
+     * @param cacheSize the cache size
+     * @throws Exception the exception
+     */
+    void addIndex( Partition partition, String attributeId, int cacheSize ) throws Exception;
+
+}



Mime
View raw message