manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r998576 - in /incubator/lcf/trunk/modules/framework: core/src/main/java/org/apache/acf/core/database/ core/src/main/java/org/apache/acf/core/interfaces/ pull-agent/src/main/java/org/apache/acf/crawler/jobs/ pull-agent/src/main/java/org/apac...
Date Sun, 19 Sep 2010 01:11:02 GMT
Author: kwright
Date: Sun Sep 19 01:11:02 2010
New Revision: 998576

URL: http://svn.apache.org/viewvc?rev=998576&view=rev
Log:
Partial fix for CONNECTORS-109.  The full fix requires a feature in Derby that is on Derby's
trunk but not yet in a release.  Fix the report queries for queue status and result report
that were due to use of the postgresql-only function 'SUBSTRING'.  I also needed to restructure
these queries because the GROUP BY columns are not allowed to be return column names in Derby.

Modified:
    incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/BaseTable.java
    incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfaceDerby.java
    incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfaceMySQL.java
    incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfacePostgreSQL.java
    incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/interfaces/IDBInterface.java
    incubator/lcf/trunk/modules/framework/pull-agent/src/main/java/org/apache/acf/crawler/jobs/JobManager.java
    incubator/lcf/trunk/modules/framework/pull-agent/src/main/java/org/apache/acf/crawler/repository/RepositoryHistoryManager.java

Modified: incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/BaseTable.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/BaseTable.java?rev=998576&r1=998575&r2=998576&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/BaseTable.java
(original)
+++ incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/BaseTable.java
Sun Sep 19 01:11:02 2010
@@ -294,7 +294,20 @@ public class BaseTable
   {
     return dbInterface.constructRegexpClause(column,regularExpression,caseInsensitive);
   }
-  
+
+  /** Construct a regular-expression substring clause.
+  * This method builds an expression that extracts a specified string section from a field,
based on
+  * a regular expression.
+  *@param column is the column specifier string.
+  *@param regularExpression is the properly-quoted regular expression string, or "?" if a
parameterized value is to be used.
+  *@param caseInsensitive is true if the regular expression match is to be case insensitive.
+  *@return the expression chunk needed, not padded with spaces on either side.
+  */
+  public String constructSubstringClause(String column, String regularExpression, boolean
caseInsensitive)
+  {
+    return dbInterface.constructSubstringClause(column,regularExpression,caseInsensitive);
+  }
+
   /** 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: incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfaceDerby.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfaceDerby.java?rev=998576&r1=998575&r2=998576&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfaceDerby.java
(original)
+++ incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfaceDerby.java
Sun Sep 19 01:11:02 2010
@@ -22,6 +22,7 @@ import org.apache.acf.core.interfaces.*;
 import org.apache.acf.core.system.ACF;
 import org.apache.acf.core.system.Logging;
 import java.util.*;
+import java.util.regex.*;
 import java.io.*;
 import java.sql.*;
 
@@ -531,6 +532,15 @@ public class DBInterfaceDerby extends Da
     {
       rootDatabase.executeQuery("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user."+userName+"',
'"+password+"')",null,invalidateKeys,null,null,false,0,null,null);
       rootDatabase.executeQuery("CREATE SCHEMA "+userName+" AUTHORIZATION "+userName,null,invalidateKeys,null,null,false,0,null,null);
+      // Create user-defined functions
+      rootDatabase.executeQuery("CREATE FUNCTION caseInsensitiveRegularExpressionCompare
(value varchar(255), regexp varchar(255)) returns varchar(255) "+
+        "language java parameter style java no sql external name 'org.apache.acf.core.database.DBInterfaceDerby.caseInsensitiveRegularExpressionCompare",null,invalidateKeys,null,null,false,0,null,null);
+      rootDatabase.executeQuery("CREATE FUNCTION caseSensitiveRegularExpressionCompare (value
varchar(255), regexp varchar(255)) returns varchar(255) "+
+        "language java parameter style java no sql external name 'org.apache.acf.core.database.DBInterfaceDerby.caseSensitiveRegularExpressionCompare",null,invalidateKeys,null,null,false,0,null,null);
+      rootDatabase.executeQuery("CREATE FUNCTION caseInsensitiveSubstring (value varchar(255),
regexp varchar(255)) returns varchar(255) "+
+        "language java parameter style java no sql external name 'org.apache.acf.core.database.DBInterfaceDerby.caseInsensitiveSubstring",null,invalidateKeys,null,null,false,0,null,null);
+      rootDatabase.executeQuery("CREATE FUNCTION caseSensitiveSubstring (value varchar(255),
regexp varchar(255)) returns varchar(255) "+
+        "language java parameter style java no sql external name 'org.apache.acf.core.database.DBInterfaceDerby.caseSensitiveSubstring",null,invalidateKeys,null,null,false,0,null,null);
     }
   }
 
@@ -790,8 +800,30 @@ public class DBInterfaceDerby extends Da
   */
   public String constructRegexpClause(String column, String regularExpression, boolean caseInsensitive)
   {
-    // MHL to invoke a stored procedure
     return column + " LIKE " + regularExpression;
+    // Waiting for DERBY-4066 to be resolved in a release for the following:
+    //if (caseInsensitive)
+    //  return "caseInsensitiveRegularExpressionCompare("+column+","+regularExpression+")='true'";
+    //else
+    //  return "caseSensitiveRegularExpressionCompare("+column+","+regularExpression+")='true'";
+  }
+
+  /** Construct a regular-expression substring clause.
+  * This method builds an expression that extracts a specified string section from a field,
based on
+  * a regular expression.
+  *@param column is the column specifier string.
+  *@param regularExpression is the properly-quoted regular expression string, or "?" if a
parameterized value is to be used.
+  *@param caseInsensitive is true if the regular expression match is to be case insensitive.
+  *@return the expression chunk needed, not padded with spaces on either side.
+  */
+  public String constructSubstringClause(String column, String regularExpression, boolean
caseInsensitive)
+  {
+    return "''";
+    // Waiting for DERBY-4066 to be resolved in a release for the following:
+    //if (caseInsensitive)
+    //  return "caseInsensitiveSubstring("+column+","+regularExpression+")";
+    //else
+    //  return "caseSensitiveSubstring("+column+","+regularExpression+")";
   }
 
   /** Construct an offset/limit clause.
@@ -1048,5 +1080,89 @@ public class DBInterfaceDerby extends Da
     return rawColumnName.toLowerCase();
   }
 
+  // Functions that correspond to user-defined functions in Derby
+  
+  /** Method to compare a value using a case-insensitive regular expression.
+  */
+  public static String caseInsensitiveRegularExpressionCompare(String value, String regularExpression)
+    throws SQLException
+  {
+    try
+    {
+      Pattern p = Pattern.compile(regularExpression,Pattern.CASE_INSENSITIVE);
+      Matcher m = p.matcher(value);
+      if (m.find())
+        return "true";
+      else
+        return "false";
+    }
+    catch (PatternSyntaxException e)
+    {
+      throw new SQLException("Pattern syntax exception: "+e.getMessage());
+    }
+  }
+  
+  /** Method to compare a value using a case-sensitive regular expression.
+  */
+  public static String caseSensitiveRegularExpressionCompare(String value, String regularExpression)
+    throws SQLException
+  {
+    try
+    {
+      Pattern p = Pattern.compile(regularExpression,0);
+      Matcher m = p.matcher(value);
+      if (m.find())
+        return "true";
+      else
+        return "false";
+    }
+    catch (PatternSyntaxException e)
+    {
+      throw new SQLException("Pattern syntax exception: "+e.getMessage());
+    }
+  }
+
+  /** Method to get a substring out of a case-insensitive regular expression group.
+  */
+  public static String caseInsensitiveSubstring(String value, String regularExpression)
+    throws SQLException
+  {
+    try
+    {
+      Pattern p = Pattern.compile(regularExpression,Pattern.CASE_INSENSITIVE);
+      Matcher m = p.matcher(value);
+      return m.group(1);
+    }
+    catch (IndexOutOfBoundsException e)
+    {
+      return value;
+    }
+    catch (PatternSyntaxException e)
+    {
+      throw new SQLException("Pattern syntax exception: "+e.getMessage());
+    }
+  }
+  
+  /** Method to get a substring out of a case-sensitive regular expression group.
+  */
+  public static String caseSensitiveSubstring(String value, String regularExpression)
+    throws SQLException
+  {
+    try
+    {
+      Pattern p = Pattern.compile(regularExpression,0);
+      Matcher m = p.matcher(value);
+      return m.group(1);
+    }
+    catch (IndexOutOfBoundsException e)
+    {
+      return value;
+    }
+    catch (PatternSyntaxException e)
+    {
+      throw new SQLException("Pattern syntax exception: "+e.getMessage());
+    }
+  }
+
 }
 

Modified: incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfaceMySQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfaceMySQL.java?rev=998576&r1=998575&r2=998576&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfaceMySQL.java
(original)
+++ incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfaceMySQL.java
Sun Sep 19 01:11:02 2010
@@ -549,6 +549,20 @@ public class DBInterfaceMySQL extends Da
     return column + " LIKE " + regularExpression;
   }
 
+  /** Construct a regular-expression substring clause.
+  * This method builds an expression that extracts a specified string section from a field,
based on
+  * a regular expression.
+  *@param column is the column specifier string.
+  *@param regularExpression is the properly-quoted regular expression string, or "?" if a
parameterized value is to be used.
+  *@param caseInsensitive is true if the regular expression match is to be case insensitive.
+  *@return the expression chunk needed, not padded with spaces on either side.
+  */
+  public String constructSubstringClause(String column, String regularExpression, boolean
caseInsensitive)
+  {
+    // MHL for mysql
+    return quoteSQLString("");
+  }
+
   /** 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: incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfacePostgreSQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfacePostgreSQL.java?rev=998576&r1=998575&r2=998576&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfacePostgreSQL.java
(original)
+++ incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/database/DBInterfacePostgreSQL.java
Sun Sep 19 01:11:02 2010
@@ -820,6 +820,31 @@ public class DBInterfacePostgreSQL exten
     return column + "~" + (caseInsensitive?"*":"") + regularExpression;
   }
 
+  /** Construct a regular-expression substring clause.
+  * This method builds an expression that extracts a specified string section from a field,
based on
+  * a regular expression.
+  *@param column is the column specifier string.
+  *@param regularExpression is the properly-quoted regular expression string, or "?" if a
parameterized value is to be used.
+  *@param caseInsensitive is true if the regular expression match is to be case insensitive.
+  *@return the expression chunk needed, not padded with spaces on either side.
+  */
+  public String constructSubstringClause(String column, String regularExpression, boolean
caseInsensitive)
+  {
+    StringBuffer sb = new StringBuffer();
+    sb.append("SUBSTRING(");
+    if (caseInsensitive)
+      sb.append("LOWER(").append(column).append(")");
+    else
+      sb.append(column);
+    sb.append(" FROM ");
+    if (caseInsensitive)
+      sb.append("LOWER(").append(regularExpression).append(")");
+    else
+      sb.append(regularExpression);
+    sb.append(")");
+    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: incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/interfaces/IDBInterface.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/interfaces/IDBInterface.java?rev=998576&r1=998575&r2=998576&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/interfaces/IDBInterface.java
(original)
+++ incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/acf/core/interfaces/IDBInterface.java
Sun Sep 19 01:11:02 2010
@@ -257,14 +257,24 @@ public interface IDBInterface
     throws ACFException;
 
   /** Construct a regular-expression match clause.
-  * This method builds both the text part of a regular-expression match.
+  * This method builds a regular-expression match expression.
   *@param column is the column specifier string.
   *@param regularExpression is the properly-quoted regular expression string, or "?" if a
parameterized value is to be used.
-  *@param caseInsensitive is true of the regular expression match is to be case insensitive.
+  *@param caseInsensitive is true if the regular expression match is to be case insensitive.
   *@return the query chunk needed, not padded with spaces on either side.
   */
   public String constructRegexpClause(String column, String regularExpression, boolean caseInsensitive);
   
+  /** Construct a regular-expression substring clause.
+  * This method builds an expression that extracts a specified string section from a field,
based on
+  * a regular expression.
+  *@param column is the column specifier string.
+  *@param regularExpression is the properly-quoted regular expression string, or "?" if a
parameterized value is to be used.
+  *@param caseInsensitive is true if the regular expression match is to be case insensitive.
+  *@return the expression chunk needed, not padded with spaces on either side.
+  */
+  public String constructSubstringClause(String column, String regularExpression, boolean
caseInsensitive);
+  
   /** 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: incubator/lcf/trunk/modules/framework/pull-agent/src/main/java/org/apache/acf/crawler/jobs/JobManager.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/src/main/java/org/apache/acf/crawler/jobs/JobManager.java?rev=998576&r1=998575&r2=998576&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/src/main/java/org/apache/acf/crawler/jobs/JobManager.java
(original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/src/main/java/org/apache/acf/crawler/jobs/JobManager.java
Sun Sep 19 01:11:02 2010
@@ -5894,17 +5894,21 @@ public class JobManager implements IJobM
 
     Long currentTime = new Long(System.currentTimeMillis());
 
-    StringBuffer sb = new StringBuffer("SELECT ");
+    StringBuffer sb = new StringBuffer();
+    sb.append("SELECT t1.idbucket,SUM(t1.inactive) AS inactive,SUM(t1.processing) AS processing,SUM(t1.expiring)
AS expiring,SUM(t1.deleting) AS deleting,")
+      .append("SUM(t1.processready) AS processready,SUM(t1.expireready) AS expireready,SUM(t1.processwaiting)
AS processwaiting,SUM(t1.expirewaiting) AS expirewaiting,")
+      .append("SUM(t1.waitingforever) AS waitingforever FROM (SELECT ");
     addBucketExtract(sb,"",jobQueue.docIDField,idBucketDescription);
     sb.append(" AS idbucket,")
-      .append("SUM(CASE")
+      .append("CASE")
       .append(" WHEN ")
       .append("(").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_COMPLETE)))
       .append(" OR ").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_PURGATORY)))
       .append(")")
       .append(" THEN 1 ELSE 0")
-      .append(" END) AS inactive,")
-      .append("SUM(CASE")
+      .append(" END")
+      .append(" AS inactive,")
+      .append("CASE")
       .append(" WHEN ")
       .append("(").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_ACTIVE)))
       .append(" OR ").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_ACTIVENEEDRESCAN)))
@@ -5913,8 +5917,9 @@ public class JobManager implements IJobM
       .append(")")
       .append(" AND (").append(jobQueue.checkActionField).append(" IS NULL OR ").append(jobQueue.checkActionField).append("=").append(database.quoteSQLString(jobQueue.actionToString(jobQueue.ACTION_RESCAN))).append(")")
       .append(" THEN 1 ELSE 0")
-      .append(" END) as processing,")
-      .append("SUM(CASE")
+      .append(" END")
+      .append(" as processing,")
+      .append("CASE")
       .append(" WHEN ")
       .append("(").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_ACTIVE)))
       .append(" OR ").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_ACTIVENEEDRESCAN)))
@@ -5923,13 +5928,15 @@ public class JobManager implements IJobM
       .append(")")
       .append(" AND ").append(jobQueue.checkActionField).append("=").append(database.quoteSQLString(jobQueue.actionToString(jobQueue.ACTION_REMOVE)))
       .append(" THEN 1 ELSE 0")
-      .append(" END) as expiring,")
-      .append("SUM(CASE")
+      .append(" END")
+      .append(" as expiring,")
+      .append("CASE")
       .append(" WHEN ")
       .append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_BEINGDELETED)))
       .append(" THEN 1 ELSE 0")
-      .append(" END) as deleting,")
-      .append("SUM(CASE")
+      .append(" END")
+      .append(" as deleting,")
+      .append("CASE")
       .append(" WHEN ")
       .append("(").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_PENDING)))
       .append(" OR ").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_PENDINGPURGATORY)))
@@ -5937,8 +5944,9 @@ public class JobManager implements IJobM
       .append(" AND ").append(jobQueue.checkTimeField).append("<=").append(currentTime.toString())
       .append(" AND (").append(jobQueue.checkActionField).append(" IS NULL OR ").append(jobQueue.checkActionField).append("=").append(database.quoteSQLString(jobQueue.actionToString(jobQueue.ACTION_RESCAN))).append(")")
       .append(" THEN 1 ELSE 0")
-      .append(" END) as processready,")
-      .append("SUM(CASE")
+      .append(" END")
+      .append(" as processready,")
+      .append("CASE")
       .append(" WHEN ")
       .append("(").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_PENDING)))
       .append(" OR ").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_PENDINGPURGATORY)))
@@ -5946,8 +5954,9 @@ public class JobManager implements IJobM
       .append(" AND ").append(jobQueue.checkTimeField).append("<=").append(currentTime.toString())
       .append(" AND ").append(jobQueue.checkActionField).append("=").append(database.quoteSQLString(jobQueue.actionToString(jobQueue.ACTION_REMOVE)))
       .append(" THEN 1 ELSE 0")
-      .append(" END) as expireready,")
-      .append("SUM(CASE")
+      .append(" END")
+      .append(" as expireready,")
+      .append("CASE")
       .append(" WHEN ")
       .append("(").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_PENDING)))
       .append(" OR ").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_PENDINGPURGATORY)))
@@ -5955,8 +5964,9 @@ public class JobManager implements IJobM
       .append(" AND ").append(jobQueue.checkTimeField).append(">").append(currentTime.toString())
       .append(" AND (").append(jobQueue.checkActionField).append(" IS NULL OR ").append(jobQueue.checkActionField).append("=").append(database.quoteSQLString(jobQueue.actionToString(jobQueue.ACTION_RESCAN))).append(")")
       .append(" THEN 1 ELSE 0")
-      .append(" END) as processwaiting,")
-      .append("SUM(CASE")
+      .append(" END")
+      .append(" as processwaiting,")
+      .append("CASE")
       .append(" WHEN ")
       .append("(").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_PENDING)))
       .append(" OR ").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_PENDINGPURGATORY)))
@@ -5964,18 +5974,20 @@ public class JobManager implements IJobM
       .append(" AND ").append(jobQueue.checkTimeField).append(">").append(currentTime.toString())
       .append(" AND ").append(jobQueue.checkActionField).append("=").append(database.quoteSQLString(jobQueue.actionToString(jobQueue.ACTION_REMOVE)))
       .append(" THEN 1 ELSE 0")
-      .append(" END) as expirewaiting,")
-      .append("SUM(CASE")
+      .append(" END")
+      .append(" as expirewaiting,")
+      .append("CASE")
       .append(" WHEN ")
       .append("(").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_PENDING)))
       .append(" OR ").append(jobQueue.statusField).append("=").append(database.quoteSQLString(jobQueue.statusToString(jobQueue.STATUS_PENDINGPURGATORY)))
       .append(")")
       .append(" AND ").append(jobQueue.checkTimeField).append(" IS NULL")
       .append(" THEN 1 ELSE 0")
-      .append(" END) as waitingforever");
+      .append(" END")
+      .append(" as waitingforever");
     sb.append(" FROM ").append(jobQueue.getTableName());
     addCriteria(sb,"",connectionName,filterCriteria,false);
-    sb.append(" GROUP BY idbucket");
+    sb.append(") t1 GROUP BY idbucket");
     addOrdering(sb,new String[]{"idbucket","inactive","processing","expiring","deleting","processready","expireready","processwaiting","expirewaiting","waitingforever"},sortOrder);
     addLimits(sb,startRow,rowCount);
     return database.performQuery(sb.toString(),null,null,null,rowCount,null);
@@ -5990,17 +6002,7 @@ public class JobManager implements IJobM
   protected void addBucketExtract(StringBuffer sb, String columnPrefix, String columnName,
BucketDescription bucketDesc)
   {
     boolean isSensitive = bucketDesc.isSensitive();
-    sb.append("SUBSTRING(");
-    if (!isSensitive)
-      sb.append("LOWER(").append(columnPrefix).append(columnName).append(")");
-    else
-      sb.append(columnPrefix).append(columnName);
-    sb.append(" FROM ");
-    if (!isSensitive)
-      sb.append("LOWER(").append(database.quoteSQLString(bucketDesc.getRegexp())).append(")");
-    else
-      sb.append(database.quoteSQLString(bucketDesc.getRegexp()));
-    sb.append(")");
+    sb.append(database.constructSubstringClause(columnPrefix+columnName,database.quoteSQLString(bucketDesc.getRegexp()),!isSensitive));
   }
 
   /** Add criteria clauses to query.

Modified: incubator/lcf/trunk/modules/framework/pull-agent/src/main/java/org/apache/acf/crawler/repository/RepositoryHistoryManager.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/pull-agent/src/main/java/org/apache/acf/crawler/repository/RepositoryHistoryManager.java?rev=998576&r1=998575&r2=998576&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/pull-agent/src/main/java/org/apache/acf/crawler/repository/RepositoryHistoryManager.java
(original)
+++ incubator/lcf/trunk/modules/framework/pull-agent/src/main/java/org/apache/acf/crawler/repository/RepositoryHistoryManager.java
Sun Sep 19 01:11:02 2010
@@ -287,7 +287,7 @@ public class RepositoryHistoryManager ex
     if (set.getRowCount() < 1)
       throw new ACFException("Expected at least one row");
     IResultRow row = set.getRow(0);
-    Long value = (Long)row.getValue("countcol");
+    Long value = new Long(row.getValue("countcol").toString());
     return value.longValue();
   }
 
@@ -477,19 +477,19 @@ public class RepositoryHistoryManager ex
   {
     // The query we'll use here will be:
     //
-    // SELECT substring(resultcode FROM '<result_regexp>') AS resultcodebucket,
+    // SELECT * FROM (SELECT substring(resultcode FROM '<result_regexp>') AS resultcodebucket,
     //        substring(entityidentifier FROM '<id_regexp>') AS idbucket,
-    //        COUNT('x') AS eventcount FROM repohistory WHERE <criteria>
-    //              GROUP BY resultcodebucket,idbucket
+    //        COUNT('x') AS eventcount FROM repohistory WHERE <criteria>) t1
+    //              GROUP BY t1.resultcodebucket,t1.idbucket
     //                      ORDER BY xxx LIMIT yyy OFFSET zzz
 
-    StringBuffer sb = new StringBuffer("SELECT ");
+    StringBuffer sb = new StringBuffer("SELECT t1.resultcodebucket,t1.idbucket,COUNT('x')
AS eventcount FROM (SELECT ");
     addBucketExtract(sb,"",resultCodeField,resultCodeBucket);
     sb.append(" AS resultcodebucket, ");
     addBucketExtract(sb,"",entityIdentifierField,idBucket);
-    sb.append(" AS idbucket, COUNT('x') AS eventcount FROM ").append(getTableName());
+    sb.append(" AS idbucket FROM ").append(getTableName());
     addCriteria(sb,"",connectionName,filterCriteria,false);
-    sb.append(" GROUP BY resultcodebucket,idbucket");
+    sb.append(") t1 GROUP BY resultcodebucket,idbucket");
     addOrdering(sb,new String[]{"eventcount","resultcodebucket","idbucket"},sort);
     addLimits(sb,startRow,maxRowCount);
     return performQuery(sb.toString(),null,null,null,maxRowCount);
@@ -502,17 +502,7 @@ public class RepositoryHistoryManager ex
   protected void addBucketExtract(StringBuffer sb, String columnPrefix, String columnName,
BucketDescription bucketDesc)
   {
     boolean isSensitive = bucketDesc.isSensitive();
-    sb.append("SUBSTRING(");
-    if (!isSensitive)
-      sb.append("LOWER(").append(columnPrefix).append(columnName).append(")");
-    else
-      sb.append(columnPrefix).append(columnName);
-    sb.append(" FROM ");
-    if (!isSensitive)
-      sb.append("LOWER(").append(quoteSQLString(bucketDesc.getRegexp())).append(")");
-    else
-      sb.append(quoteSQLString(bucketDesc.getRegexp()));
-    sb.append(")");
+    sb.append(constructSubstringClause(columnPrefix+columnName,quoteSQLString(bucketDesc.getRegexp()),!isSensitive));
   }
 
   /** Add criteria clauses to query.



Mime
View raw message