From 7b11744dea26fe1d6d051fd68e7701a8b54f9d84 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 17 Dec 2014 10:53:46 +0000
Subject: [PATCH] OPENDJ-1602 (CR-5566) New pluggable storage based backend
---
opendj3-server-dev/src/server/org/opends/server/backends/persistit/PersistItStorage.java | 22 +++++++++++
opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/WriteableStorage.java | 2 +
opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/UpdateFunction.java | 42 +++++++++++++++++++++
3 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/persistit/PersistItStorage.java b/opendj3-server-dev/src/server/org/opends/server/backends/persistit/PersistItStorage.java
index 6e4377a..8c680b1 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/persistit/PersistItStorage.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/persistit/PersistItStorage.java
@@ -43,6 +43,7 @@
import org.opends.server.backends.pluggable.spi.Storage;
import org.opends.server.backends.pluggable.spi.StorageRuntimeException;
import org.opends.server.backends.pluggable.spi.TreeName;
+import org.opends.server.backends.pluggable.spi.UpdateFunction;
import org.opends.server.backends.pluggable.spi.WriteOperation;
import org.opends.server.backends.pluggable.spi.WriteableStorage;
import org.opends.server.types.DN;
@@ -171,6 +172,27 @@
throw new StorageRuntimeException(e);
}
}
+
+ @Override
+ public void update(TreeName treeName, ByteSequence key, UpdateFunction f)
+ {
+ try
+ {
+ final Exchange ex = getExchange(treeName);
+ ex.getKey().clear().append(key.toByteArray());
+ ex.fetch();
+ final Value value = ex.getValue();
+ final ByteSequence oldValue = value.isDefined() ? ByteString.wrap(value
+ .getByteArray()) : null;
+ final ByteSequence newValue = f.computeNewValue(oldValue);
+ ex.getValue().clear().putByteArray(newValue.toByteArray());
+ ex.store();
+ }
+ catch (Exception e)
+ {
+ throw new StorageRuntimeException(e);
+ }
+ }
@Override
public boolean delete(TreeName treeName, ByteSequence key) {
diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/UpdateFunction.java b/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/UpdateFunction.java
new file mode 100644
index 0000000..79e8b16
--- /dev/null
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/UpdateFunction.java
@@ -0,0 +1,42 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
+ * or http://forgerock.org/license/CDDLv1.0.html.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at legal-notices/CDDLv1_0.txt.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information:
+ * Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ * Copyright 2014 ForgeRock AS
+ */
+package org.opends.server.backends.pluggable.spi;
+
+import org.forgerock.opendj.ldap.ByteSequence;
+
+public interface UpdateFunction {
+ /**
+ * Computes the new value for a record based on the record's existing
+ * content.
+ *
+ * @param oldValue
+ * The record's existing content, or {@code null} if the record
+ * does not exist at the moment and is about to be created.
+ * @return The new value for the record, or {@code null} if the record
+ * should be completely removed.
+ */
+ ByteSequence computeNewValue(ByteSequence oldValue);
+}
diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/WriteableStorage.java b/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/WriteableStorage.java
index 9fadb7a..20fbe9f 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/WriteableStorage.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/WriteableStorage.java
@@ -36,5 +36,7 @@
boolean putIfAbsent(TreeName treeName, ByteSequence key, ByteSequence value);
+ void update(TreeName treeName, ByteSequence key, UpdateFunction f);
+
boolean delete(TreeName name, ByteSequence key);
}
\ No newline at end of file
--
Gitblit v1.10.0