From c1aec34e50f3d7a387bdd9da9860b3cd06f398c5 Mon Sep 17 00:00:00 2001
From: dugan <dugan@localhost>
Date: Thu, 12 Oct 2006 20:27:35 +0000
Subject: [PATCH] Re-write entries in sorted order. Andy suggested changes
---
opendj-sdk/opends/src/server/org/opends/server/tools/LDIFModify.java | 14 ++++++++------
opendj-sdk/opends/src/server/org/opends/server/util/LDIFWriter.java | 28 ++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDIFModify.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDIFModify.java
index e84f2ea..55cde7f 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDIFModify.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDIFModify.java
@@ -129,7 +129,8 @@
DNComparator comparator = new DNComparator();
TreeMap<DN,AddChangeRecordEntry> adds =
new TreeMap<DN,AddChangeRecordEntry>(comparator);
-
+ TreeMap<DN,Entry> ldifEntries =
+ new TreeMap<DN,Entry>(comparator);
HashMap<DN,DeleteChangeRecordEntry> deletes =
new HashMap<DN,DeleteChangeRecordEntry>();
HashMap<DN,LinkedList<Modification>> modifications =
@@ -306,8 +307,8 @@
// If we've gotten here, then the (possibly updated) entry should be
- // written to the output LDIF.
- targetWriter.writeEntry(entry);
+ // written to the LDIF entry Map.
+ ldifEntries.put(entry.getDN(),entry);
}
@@ -358,7 +359,8 @@
Entry e = new Entry(add.getDN(), objectClasses, userAttributes,
operationalAttributes);
- targetWriter.writeEntry(e);
+ //Put the entry to be added into the LDIF entry map.
+ ldifEntries.put(e.getDN(),e);
}
@@ -381,8 +383,8 @@
errorList.add(getMessage(msgID, String.valueOf(dn)));
}
}
-
- return errorList.isEmpty();
+ return targetWriter.writeEntries(ldifEntries.values()) &&
+ errorList.isEmpty();
}
diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/LDIFWriter.java b/opendj-sdk/opends/src/server/org/opends/server/util/LDIFWriter.java
index c32412f..686075e 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/LDIFWriter.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/util/LDIFWriter.java
@@ -33,6 +33,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
+import java.util.Collection;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
@@ -204,6 +205,33 @@
}
}
+ /**
+ * Iterates over each entry contained in the map and writes out the entry in
+ * LDIF format. The main benefit of this method is that the entries can be
+ * sorted by DN and output in sorted order.
+ *
+ * @param entries The Map containing the entries keyed by DN.
+ *
+ * @return <CODE>true</CODE>of all of the entries were
+ * written out, <CODE>false</CODE>if it was not
+ * because of the export configuration.
+ *
+ * @throws IOException If a problem occurs while writing the entry to LDIF.
+ *
+ * @throws LDIFException If a problem occurs while trying to determine
+ * whether to include the entry in the export.
+ */
+public boolean writeEntries(Collection <Entry> entries)
+ throws IOException, LDIFException {
+ assert debugEnter(CLASS_NAME, "writeEntry", String.valueOf(entries));
+
+ boolean ret=true;
+ Iterator<Entry> i = entries.iterator();
+ while(ret && i.hasNext()) {
+ ret=writeEntry(i.next());
+ }
+ return ret;
+ }
/**
--
Gitblit v1.10.0