manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1420606 - in /manifoldcf/trunk/framework: core/src/main/java/org/apache/manifoldcf/core/database/ core/src/main/java/org/apache/manifoldcf/core/interfaces/ pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/
Date Wed, 12 Dec 2012 10:20:19 GMT
Author: kwright
Date: Wed Dec 12 10:20:17 2012
New Revision: 1420606

URL: http://svn.apache.org/viewvc?rev=1420606&view=rev
Log:
Introduce abstraction for dealing with ORDER-BY clauses meant to read from an index. Part
of CONNECTORS-584.

Modified:
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
    manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
    manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java?rev=1420606&r1=1420605&r2=1420606&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
(original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
Wed Dec 12 10:20:17 2012
@@ -969,6 +969,33 @@ public class DBInterfaceHSQLDB extends D
     }
   }
 
+  /** Construct ORDER-BY clause meant for reading from an index.
+  * Supply the field names belonging to the index, in order.
+  * Also supply a corresponding boolean array, where TRUE means "ASC", and FALSE
+  * means "DESC".
+  *@param fieldNames are the names of the fields in the index that is to be used.
+  *@param direction is a boolean describing the sorting order of the first term.
+  *@return a query chunk, including "ORDER BY" text, which is appropriate for
+  * at least ordering by the FIRST column supplied.
+  */
+  public String constructIndexOrderByClause(String[] fieldNames, boolean direction)
+  {
+    if (fieldNames.length == 0)
+      return "";
+    StringBuilder sb = new StringBuilder("ORDER BY ");
+    for (int i = 0; i < fieldNames.length; i++)
+    {
+      if (i > 0)
+        sb.append(", ");
+      sb.append(fieldNames[i]);
+      if (direction)
+        sb.append(" ASC");
+      else
+        sb.append(" DESC");
+    }
+    return sb.toString();
+  }
+  
   /** Construct a cast to a double value.
   * On most databases this cast needs to be explicit, but on some it is implicit (and cannot
be in fact
   * specified).

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java?rev=1420606&r1=1420605&r2=1420606&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
(original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
Wed Dec 12 10:20:17 2012
@@ -495,6 +495,28 @@ public abstract class Database
     return "";
   }
 
+  /** Construct ORDER-BY clause meant for reading from an index.
+  * Supply the field names belonging to the index, in order.
+  * Also supply a corresponding boolean array, where TRUE means "ASC", and FALSE
+  * means "DESC".
+  *@param fieldNames are the names of the fields in the index that is to be used.
+  *@param direction is a boolean describing the sorting order of the first term.
+  *@return a query chunk, including "ORDER BY" text, which is appropriate for
+  * at least ordering by the FIRST column supplied.
+  */
+  public String constructIndexOrderByClause(String[] fieldNames, boolean direction)
+  {
+    if (fieldNames.length == 0)
+      return "";
+    StringBuilder sb = new StringBuilder("ORDER BY ");
+    sb.append(fieldNames[0]);
+    if (direction)
+      sb.append(" ASC");
+    else
+      sb.append(" DESC");
+    return sb.toString();
+  }
+  
   /** Construct an offset/limit clause.
   * This method constructs an offset/limit clause in the proper manner for the database in
question.
   *@param offset is the starting offset number.

Modified: manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java?rev=1420606&r1=1420605&r2=1420606&view=diff
==============================================================================
--- manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
(original)
+++ manifoldcf/trunk/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
Wed Dec 12 10:20:17 2012
@@ -263,6 +263,17 @@ public interface IDBInterface
   */
   public String constructIndexHintClause(String indexName);
   
+  /** Construct ORDER-BY clause meant for reading from an index.
+  * Supply the field names belonging to the index, in order.
+  * Also supply a corresponding boolean array, where TRUE means "ASC", and FALSE
+  * means "DESC".
+  *@param fieldNames are the names of the fields in the index that is to be used.
+  *@param direction is a boolean describing the sorting order of the first term.
+  *@return a query chunk, including "ORDER BY" text, which is appropriate for
+  * at least ordering by the FIRST column supplied.
+  */
+  public String constructIndexOrderByClause(String[] fieldNames, boolean direction);
+  
   /** Construct a cast to a double value.
   * On most databases this cast needs to be explicit, but on some it is implicit (and cannot
be in fact
   * specified).

Modified: manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java?rev=1420606&r1=1420605&r2=1420606&view=diff
==============================================================================
--- manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java
(original)
+++ manifoldcf/trunk/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java
Wed Dec 12 10:20:17 2012
@@ -2122,12 +2122,9 @@ public class JobManager implements IJobM
         new JoinClause("t1."+jobs.idField,"t0."+jobQueue.jobIDField)}))
       .append(") ");
       
-    sb.append(" ORDER BY ")
-      .append(jobQueue.docPriorityField).append(" ASC ")
-      // These match the where clause, but they break MySQL
-      //.append(jobQueue.statusField).append(" ASC,")
-      //.append(jobQueue.checkActionField).append(" ASC,")
-      //.append(jobQueue.checkTimeField).append(" ASC ")
+    sb.append(" ").append(database.constructIndexOrderByClause(new String[]{
+      jobQueue.docPriorityField, jobQueue.statusField, jobQueue.checkActionField, jobQueue.checkTimeField},
+      true)).append(" ")
       .append(database.constructOffsetLimitClause(0,1,true));
 
     IResultSet set = database.performQuery(sb.toString(),list,null,null,1,null);
@@ -2202,13 +2199,9 @@ public class JobManager implements IJobM
       .append(jobQueue.prereqEventManager.eventNameField).append("=t4.").append(eventManager.eventNameField)
       .append(")");
 
-    sb.append(" ORDER BY ")
-      .append("t0.").append(jobQueue.docPriorityField).append(" ASC ");
-      // These break MySQL
-      //.append("t0.").append(jobQueue.statusField).append(" ASC,")
-      //.append("t0.").append(jobQueue.checkActionField).append(" ASC,")
-      //.append("t0.").append(jobQueue.checkTimeField).append(" ASC ");
-
+    sb.append(" ").append(database.constructIndexOrderByClause(new String[]{
+      "t0."+jobQueue.docPriorityField, "t0."+jobQueue.statusField, "t0."+jobQueue.checkActionField,
"t0."+jobQueue.checkTimeField},
+      true)).append(" ");
 
     // Before entering the transaction, we must provide the throttlelimit object with all
the connector
     // instances it could possibly need.  The purpose for doing this is to prevent a deadlock
where



Mime
View raw message