From b506a6cd184bd8cf477f7d9a7f968c990f153528 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Mon, 23 Mar 2015 23:03:19 +0000
Subject: [PATCH] OPENDJ-1848 CR-6383: Remove Storage getRMW and putIfAbsent methods

---
 opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java |   45 +++++++++------------------------------------
 1 files changed, 9 insertions(+), 36 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java
index 92ada67..001aa36 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/persistit/PersistItStorage.java
@@ -346,12 +346,6 @@
     }
 
     @Override
-    public ByteString getRMW(final TreeName treeName, final ByteSequence key)
-    {
-      return read(treeName, key);
-    }
-
-    @Override
     public Cursor openCursor(final TreeName treeName)
     {
       try
@@ -388,34 +382,6 @@
     }
 
     @Override
-    public boolean putIfAbsent(final TreeName treeName, final ByteSequence key,
-        final ByteSequence value)
-    {
-      try
-      {
-        // There is no CAS (Compare And Swap) operation to do here :)
-        // Following code is fine because Persistit provides snapshot isolation.
-        // If another thread tries to update the same key, we'll get a RollbackException
-        // And the write operation will be retried (see write() method in this class)
-        final Exchange ex = getExchangeFromCache(treeName);
-        bytesToKey(ex.getKey(), key);
-        ex.fetch();
-        final Value exValue = ex.getValue();
-        if (exValue.isDefined())
-        {
-          return false;
-        }
-        bytesToValue(exValue, value);
-        ex.store();
-        return true;
-      }
-      catch (final Exception e)
-      {
-        throw new StorageRuntimeException(e);
-      }
-    }
-
-    @Override
     public ByteString read(final TreeName treeName, final ByteSequence key)
     {
       try
@@ -449,8 +415,15 @@
         final ByteSequence newValue = f.computeNewValue(oldValue);
         if (!equals(newValue, oldValue))
         {
-          ex.getValue().clear().putByteArray(newValue.toByteArray());
-          ex.store();
+          if (newValue == null)
+          {
+            ex.remove();
+          }
+          else
+          {
+            ex.getValue().clear().putByteArray(newValue.toByteArray());
+            ex.store();
+          }
           return true;
         }
         return false;

--
Gitblit v1.10.0