directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r897273 - in /directory/apacheds/trunk/core-annotations/src: main/java/org/apache/directory/server/core/annotations/ main/java/org/apache/directory/server/core/factory/ test/java/org/apache/directory/server/core/factory/
Date Fri, 08 Jan 2010 17:38:59 GMT
Author: seelmann
Date: Fri Jan  8 17:38:59 2010
New Revision: 897273

URL: http://svn.apache.org/viewvc?rev=897273&view=rev
Log:
o Added support to create non-jdbm partitions
o Added type parameter to @CreateDS annotation which defaults to JdbmPartion.class
o Added test that initialzes and AvlPartition

Modified:
    directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateDS.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/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java

Modified: directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateDS.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateDS.java?rev=897273&r1=897272&r2=897273&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateDS.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/main/java/org/apache/directory/server/core/annotations/CreateDS.java
Fri Jan  8 17:38:59 2010
@@ -47,7 +47,7 @@
     /** flag to enable/disable anonymous access, default is false */
     boolean allowAnonAccess() default false;
     
-    /** flag to enable/disable changelog */
+    /** flag to enable/disable changelog, default is true */
     boolean enableChangeLog() default true;
     
     /** The list of partitions to create */

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=897273&r1=897272&r2=897273&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
Fri Jan  8 17:38:59 2010
@@ -23,6 +23,9 @@
 import java.lang.annotation.RetentionPolicy;
 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
  * a name and a suffix, plus some other characteristics. Here is an example :
@@ -51,6 +54,9 @@
 @Target( {ElementType.METHOD, ElementType.TYPE } )
 public @interface CreatePartition
 {
+    /** The partition implementation class */
+    Class<? extends Partition> type() default JdbmPartition.class;
+    
     /** The partition name */
     String name();
     
@@ -58,7 +64,7 @@
     String suffix();
     
     /** The context entry */
-    ContextEntry contextEntry();
+    ContextEntry contextEntry() default @ContextEntry( entryLdif = "" );
     
     /** The associated indexes */
     CreateIndex[] indexes() default {};

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=897273&r1=897272&r2=897273&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
Fri Jan  8 17:38:59 2010
@@ -86,23 +86,27 @@
             for ( CreatePartition createPartition : dsBuilder.partitions() )
             {
                 // Create the partition
-                Partition partition = new JdbmPartition();
+                Partition partition = createPartition.type().newInstance();
                 partition.setId( createPartition.name() );
                 partition.setSuffix( createPartition.suffix() );
                 partition.setSchemaManager( service.getSchemaManager() );
-                ( ( JdbmPartition ) partition ).setCacheSize( createPartition.cacheSize()
);
-                ( ( JdbmPartition ) partition ).setPartitionDir( 
-                    new File( service.getWorkingDirectory(), createPartition.name() ) );
-                
-                // Process the indexes if any
-                CreateIndex[] indexes = createPartition.indexes();
 
-                for ( CreateIndex createIndex : indexes )
+                if ( partition instanceof JdbmPartition )
                 {
-                    Index<String, ServerEntry> index = new JdbmIndex<String, ServerEntry>(
createIndex.attribute() );
-                    index.setCacheSize( createIndex.cacheSize() );
-                    
-                    ( ( JdbmPartition ) partition ).addIndexedAttributes( index );
+                    JdbmPartition jdbmPartition = ( JdbmPartition ) partition;
+                    jdbmPartition.setCacheSize( createPartition.cacheSize() );
+                    jdbmPartition.setPartitionDir( new File( service.getWorkingDirectory(),
createPartition.name() ) );
+
+                    // Process the indexes if any
+                    CreateIndex[] indexes = createPartition.indexes();
+
+                    for ( CreateIndex createIndex : indexes )
+                    {
+                        Index<String, ServerEntry> index = new JdbmIndex<String,
ServerEntry>( createIndex.attribute() );
+                        index.setCacheSize( createIndex.cacheSize() );
+
+                        jdbmPartition.addIndexedAttributes( index );
+                    }
                 }
                 
                 partition.setSchemaManager( service.getSchemaManager() );

Modified: directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java?rev=897273&r1=897272&r2=897273&view=diff
==============================================================================
--- directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java
(original)
+++ directory/apacheds/trunk/core-annotations/src/test/java/org/apache/directory/server/core/factory/DirectoryServiceAnnotationTest.java
Fri Jan  8 17:38:59 2010
@@ -33,6 +33,8 @@
 import org.apache.directory.server.core.annotations.CreateIndex;
 import org.apache.directory.server.core.annotations.CreatePartition;
 import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.server.core.partition.avl.AvlPartition;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
 import org.junit.Test;
 
 
@@ -115,6 +117,7 @@
             {
                 assertTrue( partition.isInitialized() );
                 assertEquals( "dc=example,dc=com", partition.getSuffixDn().getName() );
+                assertTrue( partition instanceof JdbmPartition );
             }
             else if ( "schema".equalsIgnoreCase( partition.getId() ) )
             {
@@ -126,4 +129,51 @@
         service.shutdown();
         FileUtils.deleteDirectory( service.getWorkingDirectory() );
     }
+    
+    
+    @Test
+    @CreateDS( 
+        name = "MethodDSWithAvlPartition",
+        partitions =
+            {
+            @CreatePartition(
+                type = AvlPartition.class,
+                name = "example",
+                suffix = "dc=example,dc=com" )
+            } )
+    public void testCreateMethodDSWithAvlPartition() throws Exception
+    {
+        DirectoryService service = DSAnnotationProcessor.getDirectoryService();
+
+        assertTrue( service.isStarted() );
+        assertEquals( "MethodDSWithAvlPartition", service.getInstanceId() );
+
+        Set<String> expectedNames = new HashSet<String>();
+
+        expectedNames.add( "example" );
+        expectedNames.add( "schema" );
+
+        assertEquals( 2, service.getPartitions().size() );
+
+        for ( Partition partition : service.getPartitions() )
+        {
+            assertTrue( expectedNames.contains( partition.getId() ) );
+
+            if ( "example".equalsIgnoreCase( partition.getId() ) )
+            {
+                assertTrue( partition.isInitialized() );
+                assertEquals( "dc=example,dc=com", partition.getSuffixDn().getName() );
+                assertTrue( partition instanceof AvlPartition );
+            }
+            else if ( "schema".equalsIgnoreCase( partition.getId() ) )
+            {
+                assertTrue( partition.isInitialized() );
+                assertEquals( "ou=schema", partition.getSuffixDn().getName() );
+            }
+        }
+
+        service.shutdown();
+        FileUtils.deleteDirectory( service.getWorkingDirectory() );
+    }
+
 }



Mime
View raw message