From d3464bd376de76eaf87d53723c04bef8c2a6f328 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 16 Jan 2015 15:37:02 +0000
Subject: [PATCH] Importer.java: More code cleanup

---
 opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java |   87 +++++++++++++++++++------------------------
 1 files changed, 38 insertions(+), 49 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
index 53f8c9f..6610e83 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
@@ -264,17 +264,7 @@
         new ArrayList<ScratchFileWriterTask>(indexCount);
     this.scratchFileWriterFutures = new CopyOnWriteArrayList<Future<Void>>();
 
-    File parentDir;
-    if (rebuildConfig.getTmpDirectory() != null)
-    {
-      parentDir = getFileForPath(rebuildConfig.getTmpDirectory());
-    }
-    else
-    {
-      parentDir = getFileForPath(DEFAULT_TMP_DIR);
-    }
-
-    this.tempDir = new File(parentDir, cfg.getBackendId());
+    this.tempDir = getTempDir(cfg, rebuildConfig.getTmpDirectory());
     recursiveDelete(tempDir);
     if (!tempDir.exists() && !tempDir.mkdirs())
     {
@@ -326,16 +316,8 @@
     this.scratchFileWriterList =
         new ArrayList<ScratchFileWriterTask>(indexCount);
     this.scratchFileWriterFutures = new CopyOnWriteArrayList<Future<Void>>();
-    File parentDir;
-    if (importConfiguration.getTmpDirectory() != null)
-    {
-      parentDir = getFileForPath(importConfiguration.getTmpDirectory());
-    }
-    else
-    {
-      parentDir = getFileForPath(DEFAULT_TMP_DIR);
-    }
-    this.tempDir = new File(parentDir, localDBBackendCfg.getBackendId());
+
+    this.tempDir = getTempDir(localDBBackendCfg, importConfiguration.getTmpDirectory());
     recursiveDelete(tempDir);
     if (!tempDir.exists() && !tempDir.mkdirs())
     {
@@ -357,6 +339,20 @@
     }
   }
 
+  private File getTempDir(LocalDBBackendCfg localDBBackendCfg, String tmpDirectory)
+  {
+    File parentDir;
+    if (tmpDirectory != null)
+    {
+      parentDir = getFileForPath(tmpDirectory);
+    }
+    else
+    {
+      parentDir = getFileForPath(DEFAULT_TMP_DIR);
+    }
+    return new File(parentDir, localDBBackendCfg.getBackendId());
+  }
+
   private int getTotalIndexCount(LocalDBBackendCfg localDBBackendCfg)
       throws ConfigException
   {
@@ -603,8 +599,7 @@
   {
     for (int i = 0; i < phaseOneBufferCount; i++)
     {
-      IndexOutputBuffer b = new IndexOutputBuffer(bufferSize);
-      freeBufferQueue.add(b);
+      freeBufferQueue.add(new IndexOutputBuffer(bufferSize));
     }
   }
 
@@ -781,10 +776,10 @@
   }
 
   /**
-   * Rebuild the indexes using the specified rootcontainer.
+   * Rebuild the indexes using the specified root container.
    *
    * @param rootContainer
-   *          The rootcontainer to rebuild indexes in.
+   *          The root container to rebuild indexes in.
    * @throws ConfigException
    *           If a configuration error occurred.
    * @throws InitializationException
@@ -1261,15 +1256,6 @@
     {
       for (Suffix suffix : dnSuffixMap.values())
       {
-        List<byte[]> includeBranches = new ArrayList<byte[]>(suffix.getIncludeBranches().size());
-        for (DN includeBranch : suffix.getIncludeBranches())
-        {
-          if (includeBranch.isDescendantOf(suffix.getBaseDN()))
-          {
-            includeBranches.add(JebFormat.dnToDNKey(includeBranch, suffix.getBaseDN().size()));
-          }
-        }
-
         EntryContainer entryContainer = suffix.getSrcEntryContainer();
         if (entryContainer != null && !suffix.getIncludeBranches().isEmpty())
         {
@@ -1280,6 +1266,7 @@
           Cursor cursor = entryContainer.getDN2ID().openCursor(null, null);
           try
           {
+            final List<byte[]> includeBranches = includeBranchesAsBytes(suffix);
             OperationStatus status = cursor.getFirst(key, data, lockMode);
             while (status == OperationStatus.SUCCESS
                 && !importConfiguration.isCancelled() && !isCanceled)
@@ -1329,6 +1316,19 @@
       return null;
     }
 
+    private List<byte[]> includeBranchesAsBytes(Suffix suffix)
+    {
+      List<byte[]> includeBranches = new ArrayList<byte[]>(suffix.getIncludeBranches().size());
+      for (DN includeBranch : suffix.getIncludeBranches())
+      {
+        if (includeBranch.isDescendantOf(suffix.getBaseDN()))
+        {
+          includeBranches.add(JebFormat.dnToDNKey(includeBranch, suffix.getBaseDN().size()));
+        }
+      }
+      return includeBranches;
+    }
+
     private boolean find(List<byte[]> arrays, byte[] arrayToFind)
     {
       for (byte[] array : arrays)
@@ -2182,8 +2182,7 @@
           {
             DatabaseEntry key = new DatabaseEntry(parentDN.array(), 0, parentDN.limit());
             DatabaseEntry value = new DatabaseEntry();
-            OperationStatus status;
-            status = entryContainer.getDN2ID().read(null, key, value, LockMode.DEFAULT);
+            OperationStatus status = entryContainer.getDN2ID().read(null, key, value, LockMode.DEFAULT);
             if (status == OperationStatus.SUCCESS)
             {
               parentID = new EntryID(value);
@@ -2277,8 +2276,7 @@
         }
         DatabaseEntry key = new DatabaseEntry(dn.array(), 0, dn.limit());
         DatabaseEntry value = new DatabaseEntry();
-        OperationStatus status;
-        status = entryContainer.getDN2ID().read(null, key, value, LockMode.DEFAULT);
+        OperationStatus status = entryContainer.getDN2ID().read(null, key, value, LockMode.DEFAULT);
         if (status == OperationStatus.SUCCESS)
         {
           return new EntryID(value);
@@ -3570,18 +3568,9 @@
         {
           AttributeIndex attributeIndex = entryContainer.getAttributeIndex(attrType);
           IndexingOptions options = attributeIndex.getIndexingOptions();
-          ImportIndexType indexType = key.getIndexType();
           Index index = mapEntry.getValue();
-          if (indexType == ImportIndexType.SUBSTRING)
-          {
-            processAttribute(index, entry, entryID, options,
-                new IndexKey(attrType, ImportIndexType.SUBSTRING, index.getIndexEntryLimit()));
-          }
-          else
-          {
-            processAttribute(index, entry, entryID, options,
-                new IndexKey(attrType, indexType, index.getIndexEntryLimit()));
-          }
+          processAttribute(index, entry, entryID, options,
+              new IndexKey(attrType, key.getIndexType(), index.getIndexEntryLimit()));
         }
       }
     }

--
Gitblit v1.10.0