]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5359: findDocs now accepts an ORDER BY statement, while still defaulting to...
authorAron Roberts <aron@socrates.berkeley.edu>
Tue, 10 Jul 2012 23:56:27 +0000 (16:56 -0700)
committerAron Roberts <aron@socrates.berkeley.edu>
Tue, 10 Jul 2012 23:56:27 +0000 (16:56 -0700)
services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java
services/common/src/main/java/org/collectionspace/services/common/vocabulary/RefNameServiceUtils.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/util/NuxeoUtils.java

index f23e1786b3f357ed8b374c040d8339a252608796..b316d3c1bd1e6963e86e7d304496d3fa9b839c1a 100644 (file)
@@ -68,6 +68,22 @@ public class QueryContext {
         this(ctx);\r
         whereClause = theWhereClause;\r
     }\r
+    \r
+    /**\r
+     * Instantiates a new query context.\r
+     *\r
+     * @param ctx the ctx\r
+     * @param theWhereClause the where clause\r
+     * @param theOrderByClause the order by clause\r
+     * @throws DocumentNotFoundException the document not found exception\r
+     * @throws DocumentException the document exception\r
+     */\r
+    public QueryContext(ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,\r
+            String theWhereClause, String theOrderByClause) throws DocumentNotFoundException, DocumentException {\r
+        this(ctx);\r
+        whereClause = theWhereClause;\r
+        orderByClause = theOrderByClause;\r
+    }\r
 \r
     /**\r
      * Instantiates a new query context.\r
index 009605de287903120a36171a425ca3ceced4c67c..1c86715beb33cd8bed41d710abed5922973c3c3e 100644 (file)
@@ -291,9 +291,8 @@ public class RefNameServiceUtils {
         return refNameServiceTypes;\r
     }\r
     // Seems like a good value - no real data to set this well.\r
-    // private static final int N_OBJS_TO_UPDATE_PER_LOOP = 100;\r
-    // FIXME: This value is set to 3 during debugging; needs to be set higher during production - ADR 2012-07-10\r
-    private static final int N_OBJS_TO_UPDATE_PER_LOOP = 3;\r
+    // Note: can set this value lower; e.g. to 3 during debugging; - ADR 2012-07-10\r
+    private static final int N_OBJS_TO_UPDATE_PER_LOOP = 100;\r
 \r
     public static int updateAuthorityRefDocs(\r
             ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,\r
@@ -404,7 +403,7 @@ public class RefNameServiceUtils {
         // Now we have to issue the search\r
         RepositoryJavaClientImpl nuxeoRepoClient = (RepositoryJavaClientImpl) repoClient;\r
         DocumentWrapper<DocumentModelList> docListWrapper = nuxeoRepoClient.findDocs(ctx, repoSession,\r
-                docTypes, query, pageSize, pageNum, computeTotal);\r
+                docTypes, query, orderByClause, pageSize, pageNum, computeTotal);\r
         // Now we gather the info for each document into the list and return\r
         DocumentModelList docList = docListWrapper.getWrappedObject();\r
         return docList;\r
index 99d590ee7f5ed3624854fc87af9356072fa14bd0..349f676363edfe9bd8dce9dca7fb4e31c5ddaaac 100644 (file)
@@ -475,7 +475,10 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             RepositoryInstance repoSession,
             List<String> docTypes,
             String whereClause,
-            int pageSize, int pageNum, boolean computeTotal)
+            String orderByClause,
+            int pageSize,
+            int pageNum,
+            boolean computeTotal)
                        throws DocumentNotFoundException, DocumentException {
         DocumentWrapper<DocumentModelList> wrapDoc = null;
 
@@ -485,7 +488,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                         "The findDocs() method must specify at least one DocumentType.");
             }
             DocumentModelList docList = null;
-            QueryContext queryContext = new QueryContext(ctx, whereClause);
+            QueryContext queryContext = new QueryContext(ctx, whereClause, orderByClause);
             String query = NuxeoUtils.buildNXQLQuery(docTypes, queryContext);
             if (logger.isDebugEnabled()) {
                 logger.debug("findDocs() NXQL: "+query);
@@ -587,7 +590,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
 
         try {
             repoSession = getRepositorySession(ctx);
-            wrapDoc = findDocs(ctx, repoSession, docTypes, whereClause,
+            wrapDoc = findDocs(ctx, repoSession, docTypes, whereClause, null,
                        pageSize, pageNum, computeTotal);
         } catch (IllegalArgumentException iae) {
             throw iae;
index 0ba58c3d8031c0137a9ac99aa96ca0b9de580c27..b18bdf78a21af7389d13effca3243f119864db22 100644 (file)
@@ -424,8 +424,12 @@ public class NuxeoUtils {
             query.append(docType);
         }
         appendNXQLWhere(query, queryContext);
-        // For a set of DocTypes, there is no sensible ordering other than by updatedAt
-        appendNXQLOrderBy(query, DocumentFilter.ORDER_BY_LAST_UPDATED, null);
+        if (Tools.notBlank(queryContext.getOrderByClause())) {
+            appendNXQLOrderBy(query, queryContext.getOrderByClause(), null);
+        } else {
+            // Across a set of mixed DocTypes, updatedAt is the most sensible default ordering
+            appendNXQLOrderBy(query, DocumentFilter.ORDER_BY_LAST_UPDATED, null);
+        }
         // FIXME add 'order by' clause here, if appropriate
         return query.toString();
     }