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

Jean-Noel Rouvignac
22.11.2014 dfd25f72080d735e0ac96d98298355c154a53a84
OPENDJ-1707 Persistit: various import problems
Code review: Matthew Swift

Added support for merge/replace of entries.


RootContainer.java:
In importLDIF():
- simplified the logic for removing database files: got rid of JE legacy code
- when adding entries, supported replacing entries if config permits

EntryContainer.java:
Better exception handling / respect declared exceptions.
2 files modified
69 ■■■■ changed files
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/EntryContainer.java 30 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/RootContainer.java 39 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/EntryContainer.java
@@ -27,6 +27,13 @@
 */
package org.opends.server.backends.pluggable;
import static org.opends.messages.JebMessages.*;
import static org.opends.server.backends.pluggable.JebFormat.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.protocols.ldap.LDAPResultCode.*;
import static org.opends.server.types.AdditionalLogItem.*;
import static org.opends.server.util.StaticUtils.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -96,13 +103,6 @@
import org.opends.server.util.ServerConstants;
import org.opends.server.util.StaticUtils;
import static org.opends.messages.JebMessages.*;
import static org.opends.server.backends.pluggable.JebFormat.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.protocols.ldap.LDAPResultCode.*;
import static org.opends.server.types.AdditionalLogItem.*;
import static org.opends.server.util.StaticUtils.*;
/**
 * Storage container for LDAP entries.  Each base DN of a JE backend is given
 * its own entry container.  The entry container is the object that implements
@@ -1669,7 +1669,7 @@
    }
    catch (Exception e)
    {
      throw new StorageRuntimeException(e);
      throwAllowedExceptionTypes(e, DirectoryException.class, CanceledOperationException.class);
    }
  }
@@ -1848,7 +1848,7 @@
    }
    catch (Exception e)
    {
      throw new StorageRuntimeException(e);
      throwAllowedExceptionTypes(e, DirectoryException.class, CanceledOperationException.class);
    }
  }
@@ -2021,9 +2021,10 @@
    }
    catch (Exception e)
    {
      throw new StorageRuntimeException(e);
      // it is not very clean to specify twice the same exception but it saves me some code for now
      throwAllowedExceptionTypes(e, DirectoryException.class, DirectoryException.class);
      return null; // it can never happen
    }
  }
  private Entry getEntry0(ReadableStorage txn, final DN entryDN) throws StorageRuntimeException, DirectoryException
@@ -2070,7 +2071,8 @@
      }
      catch (Exception e)
      {
        throw new StorageRuntimeException(e);
        // it is not very clean to specify twice the same exception but it saves me some code for now
        throwAllowedExceptionTypes(e, DirectoryException.class, DirectoryException.class);
      }
    }
@@ -2193,7 +2195,7 @@
    }
    catch (Exception e)
    {
      throw new StorageRuntimeException(e);
      throwAllowedExceptionTypes(e, DirectoryException.class, CanceledOperationException.class);
    }
  }
@@ -2445,7 +2447,7 @@
    }
    catch (Exception e)
    {
      throw new StorageRuntimeException(e);
      throwAllowedExceptionTypes(e, DirectoryException.class, CanceledOperationException.class);
    }
  }
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/RootContainer.java
@@ -26,6 +26,13 @@
 */
package org.opends.server.backends.pluggable;
import static org.opends.messages.BackendMessages.*;
import static org.opends.messages.ConfigMessages.*;
import static org.opends.messages.JebMessages.*;
import static org.opends.messages.UtilityMessages.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.util.StaticUtils.*;
import java.io.File;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@@ -58,13 +65,6 @@
import org.opends.server.util.LDIFReader;
import org.opends.server.util.RuntimeInformation;
import static org.opends.messages.BackendMessages.*;
import static org.opends.messages.ConfigMessages.*;
import static org.opends.messages.JebMessages.*;
import static org.opends.messages.UtilityMessages.*;
import static org.opends.server.core.DirectoryServer.*;
import static org.opends.server.util.StaticUtils.*;
/**
 * Wrapper class for the JE environment. Root container holds all the entry
 * containers for each base DN. It also maintains all the openings and closings
@@ -126,12 +126,10 @@
    return storage;
  }
  LDIFImportResult importLDIF(LDIFImportConfig importConfig)
      throws DirectoryException
  LDIFImportResult importLDIF(LDIFImportConfig importConfig) throws DirectoryException
  {
    RuntimeInformation.logInfo();
    if (!importConfig.appendToExistingData()
        && (importConfig.clearBackend() || config.getBaseDN().size() <= 1))
    if (importConfig.clearBackend())
    {
      removeFiles();
    }
@@ -195,12 +193,18 @@
            switch (e.getResultCode().asEnum())
            {
            case ENTRY_ALREADY_EXISTS:
              // TODO: support replace of existing entries.
              reader.rejectLastEntry(WARN_JEB_IMPORT_ENTRY_EXISTS.get());
              if (importConfig.replaceExistingEntries())
              {
                final Entry oldEntry = ec.getEntry(entry.getName());
                ec.replaceEntry(oldEntry, entry, null);
              }
              else
              {
                reader.rejectLastEntry(WARN_JEB_IMPORT_ENTRY_EXISTS.get());
              }
              break;
            case NO_SUCH_OBJECT:
              reader.rejectLastEntry(ERR_JEB_IMPORT_PARENT_NOT_FOUND.get(dn
                  .parent()));
              reader.rejectLastEntry(ERR_JEB_IMPORT_PARENT_NOT_FOUND.get(dn.parent()));
              break;
            default:
              // Not sure why it failed.
@@ -240,9 +244,8 @@
  {
    if (!backendDirectory.isDirectory())
    {
      LocalizableMessage message = ERR_JEB_DIRECTORY_INVALID
          .get(backendDirectory.getPath());
      throw new StorageRuntimeException(message.toString());
      LocalizableMessage msg = ERR_JEB_DIRECTORY_INVALID.get(backendDirectory.getPath());
      throw new StorageRuntimeException(msg.toString());
    }
    try