From 4fed0daa395855cd567621b0b38d405c9af254f4 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 26 Sep 2013 15:29:01 +0000
Subject: [PATCH] OPENDJ-1116 Introduce abstraction for the changelog DB

---
 opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java |   73 ++++++++++++++++++++++++++----------
 1 files changed, 52 insertions(+), 21 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java b/opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java
index ab85ba2..742dd06 100644
--- a/opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java
+++ b/opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java
@@ -45,6 +45,7 @@
 import org.opends.server.types.DN;
 import org.opends.server.types.DebugLogLevel;
 import org.opends.server.util.Pair;
+import org.opends.server.util.StaticUtils;
 
 import static org.opends.messages.ReplicationMessages.*;
 import static org.opends.server.loggers.ErrorLogger.*;
@@ -72,6 +73,37 @@
   /** The local replication server. */
   private final ReplicationServer replicationServer;
 
+  private static final ReplicaDBCursor EMPTY_CURSOR = new ReplicaDBCursor()
+  {
+
+    @Override
+    public int compareTo(ReplicaDBCursor o)
+    {
+      if (o == null)
+      {
+        throw new NullPointerException(); // as per javadoc
+      }
+      return o == this ? 0 : -1; // equal to self, but less than all the rest
+    }
+
+    @Override
+    public boolean next()
+    {
+      return false;
+    }
+
+    @Override
+    public UpdateMsg getChange()
+    {
+      return null;
+    }
+
+    @Override
+    public void close()
+    {
+    }
+  };
+
   /**
    * Builds an instance of this class.
    *
@@ -220,6 +252,13 @@
 
   /** {@inheritDoc} */
   @Override
+  public void removeDB()
+  {
+    StaticUtils.recursiveDelete(dbDirectory);
+  }
+
+  /** {@inheritDoc} */
+  @Override
   public Set<Integer> getDomainServerIds(DN baseDN)
   {
     return getDomainMap(baseDN).keySet();
@@ -298,7 +337,7 @@
 
   /** {@inheritDoc} */
   @Override
-  public void clearDomain(DN baseDN)
+  public void removeDomain(DN baseDN)
   {
     final Map<Integer, DbHandler> domainMap = getDomainMap(baseDN);
     synchronized (domainMap)
@@ -410,28 +449,20 @@
       CSN startAfterCSN)
   {
     DbHandler dbHandler = getDbHandler(baseDN, serverId);
-    if (dbHandler == null)
+    if (dbHandler != null)
     {
-      return null;
+      try
+      {
+        ReplicaDBCursor cursor = dbHandler.generateCursorFrom(startAfterCSN);
+        cursor.next();
+        return cursor;
+      }
+      catch (ChangelogException e)
+      {
+        // ignored
+      }
     }
-
-    ReplicaDBCursor cursor;
-    try
-    {
-      cursor = dbHandler.generateCursorFrom(startAfterCSN);
-    }
-    catch (Exception e)
-    {
-      return null;
-    }
-
-    if (!cursor.next())
-    {
-      close(cursor);
-      return null;
-    }
-
-    return cursor;
+    return EMPTY_CURSOR;
   }
 
   /** {@inheritDoc} */

--
Gitblit v1.10.0