You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2011/12/19 16:12:49 UTC
svn commit: r1220785 - in /incubator/lcf/branches/CONNECTORS-314/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/ p...
Author: kwright
Date: Mon Dec 19 15:12:48 2011
New Revision: 1220785
URL: http://svn.apache.org/viewvc?rev=1220785&view=rev
Log:
Pull the COUNT() clause into the database abstraction, to support MySQL
Modified:
incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/BaseTable.java
incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java
incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
incubator/lcf/branches/CONNECTORS-314/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java
incubator/lcf/branches/CONNECTORS-314/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/repository/RepositoryHistoryManager.java
Modified: incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/BaseTable.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/BaseTable.java?rev=1220785&r1=1220784&r2=1220785&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/BaseTable.java (original)
+++ incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/BaseTable.java Mon Dec 19 15:12:48 2011
@@ -307,6 +307,17 @@ public class BaseTable
return CacheKeyFactory.makeTableKey(null,tableName,dbInterface.getDatabaseName());
}
+ /** Construct a count clause.
+ * On most databases this will be COUNT(col), but on some the count needs to be cast to a BIGINT, so
+ * CAST(COUNT(col) AS BIGINT) will be emitted instead.
+ *@param column is the column string to be counted.
+ *@return the query chunk needed.
+ */
+ public String constructCountClause(String column)
+ {
+ return dbInterface.constructCountClause(column);
+ }
+
/** Construct a regular-expression match clause.
* This method builds both the text part of a regular-expression match.
*@param column is the column specifier string.
Modified: incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java?rev=1220785&r1=1220784&r2=1220785&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java (original)
+++ incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java Mon Dec 19 15:12:48 2011
@@ -1027,6 +1027,17 @@ public class DBInterfaceDerby extends Da
}
}
+ /** Construct a count clause.
+ * On most databases this will be COUNT(col), but on some the count needs to be cast to a BIGINT, so
+ * CAST(COUNT(col) AS BIGINT) will be emitted instead.
+ *@param column is the column string to be counted.
+ *@return the query chunk needed.
+ */
+ public String constructCountClause(String column)
+ {
+ return "CAST(COUNT("+column+") AS bigint)";
+ }
+
/** Construct a regular-expression match clause.
* This method builds both the text part of a regular-expression match.
*@param column is the column specifier string.
Modified: incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java?rev=1220785&r1=1220784&r2=1220785&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java (original)
+++ incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceHSQLDB.java Mon Dec 19 15:12:48 2011
@@ -983,6 +983,17 @@ public class DBInterfaceHSQLDB extends D
}
}
+ /** Construct a count clause.
+ * On most databases this will be COUNT(col), but on some the count needs to be cast to a BIGINT, so
+ * CAST(COUNT(col) AS BIGINT) will be emitted instead.
+ *@param column is the column string to be counted.
+ *@return the query chunk needed.
+ */
+ public String constructCountClause(String column)
+ {
+ return "CAST(COUNT("+column+") AS bigint)";
+ }
+
/** Construct a regular-expression match clause.
* This method builds both the text part of a regular-expression match.
*@param column is the column specifier string.
Modified: incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java?rev=1220785&r1=1220784&r2=1220785&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java (original)
+++ incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceMySQL.java Mon Dec 19 15:12:48 2011
@@ -754,6 +754,17 @@ rval = null;
return executeQuery(query,params,cacheKeys,null,queryClass,true,maxResults,resultSpec,returnLimit);
}
+ /** Construct a count clause.
+ * On most databases this will be COUNT(col), but on some the count needs to be cast to a BIGINT, so
+ * CAST(COUNT(col) AS BIGINT) will be emitted instead.
+ *@param column is the column string to be counted.
+ *@return the query chunk needed.
+ */
+ public String constructCountClause(String column)
+ {
+ return "COUNT("+column+")";
+ }
+
/** Construct a regular-expression match clause.
* This method builds both the text part of a regular-expression match.
*@param column is the column specifier string.
Modified: incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java?rev=1220785&r1=1220784&r2=1220785&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java (original)
+++ incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java Mon Dec 19 15:12:48 2011
@@ -865,6 +865,17 @@ public class DBInterfacePostgreSQL exten
}
}
+ /** Construct a count clause.
+ * On most databases this will be COUNT(col), but on some the count needs to be cast to a BIGINT, so
+ * CAST(COUNT(col) AS BIGINT) will be emitted instead.
+ *@param column is the column string to be counted.
+ *@return the query chunk needed.
+ */
+ public String constructCountClause(String column)
+ {
+ return "COUNT("+column+")";
+ }
+
/** Construct a regular-expression match clause.
* This method builds both the text part of a regular-expression match.
*@param column is the column specifier string.
Modified: incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java?rev=1220785&r1=1220784&r2=1220785&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java (original)
+++ incubator/lcf/branches/CONNECTORS-314/framework/core/src/main/java/org/apache/manifoldcf/core/interfaces/IDBInterface.java Mon Dec 19 15:12:48 2011
@@ -258,6 +258,14 @@ public interface IDBInterface
int maxResults, ResultSpecification resultSpec, ILimitChecker returnLimit)
throws ManifoldCFException;
+ /** Construct a count clause.
+ * On most databases this will be COUNT(col), but on some the count needs to be cast to a BIGINT, so
+ * CAST(COUNT(col) AS BIGINT) will be emitted instead.
+ *@param column is the column string to be counted.
+ *@return the query chunk needed.
+ */
+ public String constructCountClause(String column);
+
/** Construct a regular-expression match clause.
* This method builds a regular-expression match expression.
*@param column is the column specifier string.
Modified: incubator/lcf/branches/CONNECTORS-314/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-314/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java?rev=1220785&r1=1220784&r2=1220785&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-314/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java (original)
+++ incubator/lcf/branches/CONNECTORS-314/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/jobs/JobManager.java Mon Dec 19 15:12:48 2011
@@ -6532,8 +6532,7 @@ public class JobManager implements IJobM
ArrayList list = new ArrayList();
sb.append(JobQueue.jobIDField).append(",")
-// .append("CAST(COUNT(").append(JobQueue.docHashField).append(") AS BIGINT) AS doccount")
- .append("COUNT(").append(JobQueue.docHashField).append(") AS doccount")
+ .append(database.constructCountClause(JobQueue.docHashField)).append(" AS doccount")
.append(" FROM ").append(jobQueue.getTableName()).append(" t1");
if (whereClause != null)
@@ -6554,8 +6553,7 @@ public class JobManager implements IJobM
list.clear();
sb.append(JobQueue.jobIDField).append(",")
-// .append("CAST(COUNT(").append(JobQueue.docHashField).append(") AS BIGINT) AS doccount")
- .append("COUNT(").append(JobQueue.docHashField).append(") AS doccount")
+ .append(database.constructCountClause(JobQueue.docHashField)).append(" AS doccount")
.append(" FROM ").append(jobQueue.getTableName()).append(" t1 WHERE ")
.append(database.buildConjunctionClause(list,new ClauseDescription[]{
new MultiClause(JobQueue.statusField,new Object[]{
@@ -6583,8 +6581,7 @@ public class JobManager implements IJobM
list.clear();
sb.append(JobQueue.jobIDField).append(",")
-// .append("CAST(COUNT(").append(JobQueue.docHashField).append(") AS BIGINT) AS doccount")
- .append("COUNT(").append(JobQueue.docHashField).append(") AS doccount")
+ .append(database.constructCountClause(JobQueue.docHashField)).append(" AS doccount")
.append(" FROM ").append(jobQueue.getTableName()).append(" t1 WHERE ")
.append(database.buildConjunctionClause(list,new ClauseDescription[]{
new MultiClause(JobQueue.statusField,new Object[]{
Modified: incubator/lcf/branches/CONNECTORS-314/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/repository/RepositoryHistoryManager.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-314/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/repository/RepositoryHistoryManager.java?rev=1220785&r1=1220784&r2=1220785&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-314/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/repository/RepositoryHistoryManager.java (original)
+++ incubator/lcf/branches/CONNECTORS-314/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/repository/RepositoryHistoryManager.java Mon Dec 19 15:12:48 2011
@@ -298,15 +298,16 @@ public class RepositoryHistoryManager ex
public long countHistoryRows(String connectionName, FilterCriteria criteria)
throws ManifoldCFException
{
- StringBuilder sb = new StringBuilder("SELECT COUNT(*) AS countcol FROM ");
+ StringBuilder sb = new StringBuilder("SELECT ");
ArrayList list = new ArrayList();
+ sb.append(constructCountClause("*")).append(" AS countcol FROM ");
sb.append(getTableName());
addCriteria(sb,list,"",connectionName,criteria,false);
IResultSet set = performQuery(sb.toString(),list,null,null);
if (set.getRowCount() < 1)
throw new ManifoldCFException("Expected at least one row");
IResultRow row = set.getRow(0);
- Long value = new Long(row.getValue("countcol").toString());
+ Long value = (Long)row.getValue("countcol");
return value.longValue();
}
@@ -552,8 +553,9 @@ System.out.println("RepositoryHistoryMan
// GROUP BY t1.resultcodebucket,t1.idbucket
// ORDER BY xxx LIMIT yyy OFFSET zzz
- StringBuilder sb = new StringBuilder("SELECT t1.resultcodebucket,t1.idbucket,COUNT('x') AS eventcount FROM (SELECT ");
+ StringBuilder sb = new StringBuilder("SELECT t1.resultcodebucket,t1.idbucket,");
ArrayList list = new ArrayList();
+ sb.append(constructCountClause("'x'")).append(" AS eventcount FROM (SELECT ");
addBucketExtract(sb,list,"",resultCodeField,resultCodeBucket);
sb.append(" AS resultcodebucket, ");
addBucketExtract(sb,list,"",entityIdentifierField,idBucket);