directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1330743 - /directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
Date Thu, 26 Apr 2012 10:11:58 GMT
Author: elecharny
Date: Thu Apr 26 10:11:58 2012
New Revision: 1330743

URL: http://svn.apache.org/viewvc?rev=1330743&view=rev
Log:
Applied the trunk modifications to make the index be correctly built at startup

Modified:
    directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java

Modified: directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java?rev=1330743&r1=1330742&r2=1330743&view=diff
==============================================================================
--- directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
(original)
+++ directory/apacheds/branches/index-work/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
Thu Apr 26 10:11:58 2012
@@ -164,6 +164,8 @@ public class JdbmPartition extends Abstr
             {
                 allIndices.add( index.getAttribute().getOid() );
             }
+            
+            List<Index<?, Entry, Long>> indexToBuild = new ArrayList<Index<?,
Entry, Long>>();
 
             // this loop is used for two purposes
             // one for collecting all user indices
@@ -171,18 +173,24 @@ public class JdbmPartition extends Abstr
             // just to avoid another iteration for determining which is the new index
             for ( Index<?, Entry, Long> index : userIndices.values() )
             {
-                allIndices.add( index.getAttributeId() );
-
+                String indexOid = index.getAttribute().getOid();
+                allIndices.add( indexOid );
+                
                 // take the part after removing .db from the
-                String name = index.getAttributeId() + JDBM_DB_FILE_EXTN;
+                String name = indexOid + JDBM_DB_FILE_EXTN;
 
                 // if the name doesn't exist in the list of index DB files
                 // this is a new index and we need to build it
                 if ( !indexDbFileNameList.contains( name ) )
                 {
-                    buildUserIndex( index );
+                    indexToBuild.add( index );
                 }
             }
+            
+            if ( indexToBuild.size() > 0 )
+            {
+                buildUserIndex( indexToBuild );
+            }
 
             deleteUnusedIndexFiles( allIndices, allIndexDbFiles );
 
@@ -241,40 +249,43 @@ public class JdbmPartition extends Abstr
 
 
     /**
-     * builds a user defined index on a attribute by browsing all the entries present in
master db
+     * Builds user defined indexes on a attributes by browsing all the entries present in
master db
      * 
-     * @param userIdx then user defined index
+     * @param userIndexes then user defined indexes to create
      * @throws Exception in case of any problems while building the index
      */
-    private void buildUserIndex( Index userIdx ) throws Exception
+    private void buildUserIndex( List<Index<?, Entry, Long>> userIndexes ) throws
Exception
     {
-        AttributeType atType = userIdx.getAttribute();
-
-        LOG.info( "building the index for attribute type {}", atType );
-
         Cursor<Tuple<Long, Entry>> cursor = master.cursor();
         cursor.beforeFirst();
 
-        String attributeOid = userIdx.getAttribute().getOid();
-
         while ( cursor.next() )
         {
-            Tuple<Long, Entry> tuple = cursor.get();
-
-            Long id = tuple.getKey();
-            Entry entry = tuple.getValue();
-
-            Attribute entryAttr = entry.get( atType );
-
-            if ( entryAttr != null )
+            for ( Index index : userIndexes )
             {
-                for ( Value<?> value : entryAttr )
+                AttributeType atType = index.getAttribute();
+  
+                String attributeOid = index.getAttribute().getOid();
+  
+                LOG.info( "building the index for attribute type {}", atType );
+          
+                Tuple<Long, Entry> tuple = cursor.get();            
+
+                Long id = tuple.getKey();
+                Entry entry = tuple.getValue();
+    
+                Attribute entryAttr = entry.get( atType );
+    
+                if ( entryAttr != null )
                 {
-                    userIdx.add( value.getValue(), id );
+                    for ( Value<?> value : entryAttr )
+                    {
+                        index.add( value.getValue(), id );
+                    }
+    
+                    // Adds only those attributes that are indexed
+                    presenceIdx.add( attributeOid, id );
                 }
-
-                // Adds only those attributes that are indexed
-                presenceIdx.add( attributeOid, id );
             }
         }
 



Mime
View raw message