From b8d5ff44d76b120e90630e321482bf14721ea54f Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 28 Jan 2015 15:18:33 +0000
Subject: [PATCH] Code cleanup: - removed dead code - made code more explicit

---
 opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java |   46 +++++++++++-----------
 opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Suffix.java   |   60 ++++--------------------------
 2 files changed, 31 insertions(+), 75 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 e3b49b4..debf086 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
@@ -732,9 +732,7 @@
           // This entire base DN is explicitly included in the import with
           // no exclude branches that we need to migrate. Just clear the entry
           // container.
-          entryContainer.lock();
-          entryContainer.clear();
-          entryContainer.unlock();
+          clearSuffix(entryContainer);
         }
         else
         {
@@ -745,8 +743,14 @@
         }
       }
     }
-    return Suffix.createSuffixContext(entryContainer, sourceEntryContainer,
-        includeBranches, excludeBranches);
+    return new Suffix(entryContainer, sourceEntryContainer, includeBranches, excludeBranches);
+  }
+
+  private void clearSuffix(EntryContainer entryContainer)
+  {
+    entryContainer.lock();
+    entryContainer.clear();
+    entryContainer.unlock();
   }
 
   private boolean isAnyNotEqualAndAncestorOf(List<DN> dns, DN childDN)
@@ -895,7 +899,7 @@
       final long phaseTwoFinishTime = System.currentTimeMillis();
 
       setIndexesTrusted(true);
-      switchContainers();
+      switchEntryContainers();
       recursiveDelete(tempDir);
       final long finishTime = System.currentTimeMillis();
       final long importTime = finishTime - startTime;
@@ -963,28 +967,25 @@
     dir.delete();
   }
 
-  private void switchContainers() throws DatabaseException, JebException,
-      InitializationException
+  private void switchEntryContainers() throws DatabaseException, JebException, InitializationException
   {
-
     for (Suffix suffix : dnSuffixMap.values())
     {
       DN baseDN = suffix.getBaseDN();
       EntryContainer entryContainer = suffix.getSrcEntryContainer();
       if (entryContainer != null)
       {
-        EntryContainer needRegisterContainer =
-            rootContainer.unregisterEntryContainer(baseDN);
+        final EntryContainer toDelete = rootContainer.unregisterEntryContainer(baseDN);
+        toDelete.lock();
+        toDelete.close();
+        toDelete.delete();
+        toDelete.unlock();
 
-        needRegisterContainer.lock();
-        needRegisterContainer.close();
-        needRegisterContainer.delete();
-        needRegisterContainer.unlock();
-        EntryContainer newEC = suffix.getEntryContainer();
-        newEC.lock();
-        newEC.setDatabasePrefix(baseDN.toIrreversibleReadableString());
-        newEC.unlock();
-        rootContainer.registerEntryContainer(baseDN, newEC);
+        final EntryContainer replacement = suffix.getEntryContainer();
+        replacement.lock();
+        replacement.setDatabasePrefix(baseDN.toIrreversibleReadableString());
+        replacement.unlock();
+        rootContainer.registerEntryContainer(baseDN, replacement);
       }
     }
   }
@@ -2908,9 +2909,8 @@
      */
     public void initialize() throws ConfigException, InitializationException
     {
-      entryContainer =
-          rootContainer.getEntryContainer(rebuildConfig.getBaseDN());
-      suffix = Suffix.createSuffixContext(entryContainer, null, null, null);
+      entryContainer = rootContainer.getEntryContainer(rebuildConfig.getBaseDN());
+      suffix = new Suffix(entryContainer, null, null, null);
       if (suffix == null)
       {
         throw new InitializationException(
diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Suffix.java b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Suffix.java
index f23d200..19f6c4d 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Suffix.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Suffix.java
@@ -34,12 +34,10 @@
 import java.util.concurrent.CountDownLatch;
 
 import org.forgerock.i18n.slf4j.LocalizedLogger;
-import org.forgerock.opendj.config.server.ConfigException;
 import org.opends.server.backends.jeb.*;
 import org.opends.server.backends.jeb.importLDIF.Importer.DNCache;
 import org.opends.server.types.AttributeType;
 import org.opends.server.types.DN;
-import org.opends.server.types.InitializationException;
 
 import com.sleepycat.je.DatabaseException;
 import com.sleepycat.je.LockMode;
@@ -65,12 +63,17 @@
           new ConcurrentHashMap<DN, CountDownLatch>();
   private final Set<DN> parentSet = new HashSet<DN>(PARENT_ID_SET_SIZE);
   private DN parentDN;
-  private ArrayList<EntryID> IDs;
 
-  private
+  /**
+   * Creates a suffix instance using the specified parameters.
+   *
+   * @param entryContainer The entry container pertaining to the suffix.
+   * @param srcEntryContainer The original entry container.
+   * @param includeBranches The include branches.
+   * @param excludeBranches The exclude branches.
+   */
   Suffix(EntryContainer entryContainer, EntryContainer srcEntryContainer,
          List<DN> includeBranches, List<DN> excludeBranches)
-          throws InitializationException, ConfigException
   {
     this.entryContainer = entryContainer;
     this.srcEntryContainer = srcEntryContainer;
@@ -93,30 +96,6 @@
     }
   }
 
-
-  /**
-   * Creates a suffix instance using the specified parameters.
-   *
-   * @param entryContainer The entry container pertaining to the suffix.
-   * @param srcEntryContainer The original entry container.
-   * @param includeBranches The include branches.
-   * @param excludeBranches The exclude branches.
-   *
-   * @return A suffix instance.
-   * @throws InitializationException If the suffix cannot be initialized.
-   * @throws ConfigException If an error occurred reading the configuration.
-   */
-  public static Suffix
-  createSuffixContext(EntryContainer entryContainer,
-                      EntryContainer srcEntryContainer,
-                      List<DN> includeBranches, List<DN> excludeBranches)
-          throws InitializationException, ConfigException
-  {
-    return new Suffix(entryContainer, srcEntryContainer,
-            includeBranches, excludeBranches);
-  }
-
-
   /**
    * Returns the DN2ID instance pertaining to a suffix instance.
    *
@@ -346,29 +325,6 @@
     this.parentDN = parentDN;
   }
 
-
-  /**
-   * Get the entry ID list of the last entry added to a suffix.
-   *
-   * @return Return the entry ID list of the last entry added to a suffix.
-   */
-  public ArrayList<EntryID> getIDs()
-  {
-    return IDs;
-  }
-
-
-  /**
-   * Set the entry ID list of the last entry added to a suffix.
-   *
-   * @param IDs The entry ID list to save.
-   */
-  public void setIDs(ArrayList<EntryID> IDs)
-  {
-    this.IDs = IDs;
-  }
-
-
   /**
    * Return a src entry container.
    *

--
Gitblit v1.10.0