From 172ae4c6e63be576376b32a68c8e8218f202fa22 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Fri, 27 Apr 2007 20:43:17 +0000
Subject: [PATCH] Add initial support for server-side sorting in OpenDS.  This implementation will only work for indexed searches, and it operates by sorting the ID list before iterating through the entries to return them to the client.

---
 opends/src/server/org/opends/server/tools/LDAPSearch.java |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/LDAPSearch.java b/opends/src/server/org/opends/server/tools/LDAPSearch.java
index c3c7ae4..adbb71c 100644
--- a/opends/src/server/org/opends/server/tools/LDAPSearch.java
+++ b/opends/src/server/org/opends/server/tools/LDAPSearch.java
@@ -45,6 +45,7 @@
 import org.opends.server.controls.PagedResultsControl;
 import org.opends.server.controls.PersistentSearchChangeType;
 import org.opends.server.controls.PersistentSearchControl;
+import org.opends.server.controls.ServerSideSortRequestControl;
 import org.opends.server.core.DirectoryServer;
 import org.opends.server.util.Base64;
 import org.opends.server.util.PasswordReader;
@@ -602,6 +603,7 @@
     StringArgument    pSearchInfo              = null;
     StringArgument    saslOptions              = null;
     StringArgument    searchScope              = null;
+    StringArgument    sortOrder                = null;
     StringArgument    trustStorePath           = null;
     StringArgument    trustStorePassword       = null;
 
@@ -788,6 +790,11 @@
                                      MSGID_DESCRIPTION_MATCHED_VALUES_FILTER);
       argParser.addArgument(matchedValuesFilter);
 
+      sortOrder = new StringArgument("sortorder", 'S', "sortOrder", false,
+                                     false, true, "{sortOrder}", null, null,
+                                     MSGID_DESCRIPTION_SORT_ORDER);
+      argParser.addArgument(sortOrder);
+
       controlStr =
            new StringArgument("control", 'J', "control", false, true, true,
                     "{controloid[:criticality[:value|::b64value|:<fileurl]]}",
@@ -1260,6 +1267,23 @@
       searchOptions.getControls().add(new LDAPControl(mvc));
     }
 
+    if (sortOrder.isPresent())
+    {
+      try
+      {
+        searchOptions.getControls().add(
+             new LDAPControl(new ServerSideSortRequestControl(
+                                      sortOrder.getValue())));
+      }
+      catch (LDAPException le)
+      {
+        int    msgID   = MSGID_LDAP_SORTCONTROL_INVALID_ORDER;
+        String message = getMessage(msgID, le.getErrorMessage());
+        err.println(wrapText(message, MAX_LINE_WIDTH));
+        return 1;
+      }
+    }
+
     // Set the connection options.
     connectionOptions.setSASLExternal(saslExternal.isPresent());
     if(saslOptions.isPresent())
@@ -1535,6 +1559,5 @@
       }
     }
   }
-
 }
 

--
Gitblit v1.10.0