From 5c3196a7dc35588f22aa086e4e5cf6a563ec0de0 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Wed, 08 Nov 2006 20:19:03 +0000
Subject: [PATCH] This fix removes the static nextId property as well as the getters and setters for it out of the EntryID class. The nextId property is now a non static property in the RootContainer class. Each RootContainer is responsible for keeping track of the next ID and assigning new entry IDs to all entries in its EntryContainers. 

---
 opends/src/server/org/opends/server/backends/jeb/RootContainer.java |   67 ++++++++++++++++++++++++++++++++-
 1 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/jeb/RootContainer.java b/opends/src/server/org/opends/server/backends/jeb/RootContainer.java
index efeb9d3..e184040 100644
--- a/opends/src/server/org/opends/server/backends/jeb/RootContainer.java
+++ b/opends/src/server/org/opends/server/backends/jeb/RootContainer.java
@@ -40,6 +40,7 @@
 import com.sleepycat.je.CheckpointConfig;
 
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.*;
 import java.io.File;
 import java.io.FilenameFilter;
@@ -108,6 +109,11 @@
   private ConcurrentHashMap<DN, EntryContainer> entryContainers;
 
   /**
+   * The cached value of the next entry identifier to be assigned.
+   */
+  private AtomicLong nextid = new AtomicLong(1);
+
+  /**
    * Creates a new RootContainer object. Each root container represents a JE
    * environment.
    *
@@ -238,7 +244,7 @@
    */
   public EntryContainer openEntryContainer(DN baseDN) throws DatabaseException
   {
-    EntryContainer ec = new EntryContainer(baseDN, backend, config, env);
+    EntryContainer ec = new EntryContainer(baseDN, backend, config, env, this);
     EntryContainer ec1=this.entryContainers.get(baseDN);
     //If an entry container for this baseDN is already open we don't allow
     //another to be opened.
@@ -271,10 +277,19 @@
    */
   public void openEntryContainers(DN[] baseDNs) throws DatabaseException
   {
+    EntryID id = null;
+    EntryID highestID = null;
     for(DN baseDN : baseDNs)
     {
-      openEntryContainer(baseDN);
+      EntryContainer ec = openEntryContainer(baseDN);
+      id = ec.getHighestEntryID();
+      if(highestID == null || id.compareTo(highestID) > 0)
+      {
+        highestID = id;
+      }
     }
+
+    nextid = new AtomicLong(highestID.longValue() + 1);
   }
 
   /**
@@ -625,4 +640,52 @@
   {
     return env.getConfig();
   }
+
+  /**
+   * Get the total number of entries in this root container.
+   *
+   * @return The number of entries in this root container
+   * @throws DatabaseException If an error occurs while retriving the entry
+   *                           count.
+   */
+  public long getEntryCount() throws DatabaseException
+  {
+    long entryCount = 0;
+    for(EntryContainer ec : this.entryContainers.values())
+    {
+      entryCount += ec.getEntryCount();
+    }
+
+    return entryCount;
+  }
+
+  /**
+   * Assign the next entry ID.
+   *
+   * @return The assigned entry ID.
+   */
+  public EntryID getNextEntryID()
+  {
+    return new EntryID(nextid.getAndIncrement());
+  }
+
+  /**
+   * Return the lowest entry ID assigned.
+   *
+   * @return The lowest entry ID assigned.
+   */
+  public Long getLowestEntryID()
+  {
+    return 1L;
+  }
+
+  /**
+   * Return the highest entry ID assigned.
+   *
+   * @return The highest entry ID assigned.
+   */
+  public Long getHighestEntryID()
+  {
+    return (nextid.get() - 1);
+  }
 }

--
Gitblit v1.10.0