mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Matthew Swift
17.53.2014 7b11744dea26fe1d6d051fd68e7701a8b54f9d84
OPENDJ-1602 (CR-5566) New pluggable storage based backend

Add support for performing atomic updates to records.
1 files added
2 files modified
66 ■■■■■ changed files
opendj3-server-dev/src/server/org/opends/server/backends/persistit/PersistItStorage.java 22 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/UpdateFunction.java 42 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/WriteableStorage.java 2 ●●●●● patch | view | raw | blame | history
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) {
opendj3-server-dev/src/server/org/opends/server/backends/pluggable/spi/UpdateFunction.java
New file
@@ -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);
}
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);
}