From: Brett Porter Date: Thu, 30 Dec 2010 11:38:35 +0000 (+0000) Subject: [MRM-1443, MRM-1327] change to JSR-170's SQL queries to avoid the problem in JackRabb... X-Git-Tag: archiva-1.4-M1~839 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8aacc3cd0b9612a39e7cc5ffded984c845330f3e;p=archiva.git [MRM-1443, MRM-1327] change to JSR-170's SQL queries to avoid the problem in JackRabbit 2.2.0 with ISDESCENDANTNODE and a large number of nodes git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1053857 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java index 96f48f99c..540df56d1 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java @@ -162,9 +162,15 @@ public class DefaultRepositoryStatisticsManager try { QueryManager queryManager = session.getWorkspace().getQueryManager(); - String whereClause = "WHERE ISDESCENDANTNODE([/repositories/" + repositoryId + "/content])"; - Query query = queryManager.createQuery( "SELECT size FROM [archiva:artifact] " + whereClause, - Query.JCR_SQL2 ); + + // TODO: JCR-SQL2 query will not complete on a large repo in Jackrabbit 2.2.0 - see JCR-2835 + // Using the JCR-SQL2 variants gives + // "org.apache.lucene.search.BooleanQuery$TooManyClauses: maxClauseCount is set to 1024" +// String whereClause = "WHERE ISDESCENDANTNODE([/repositories/" + repositoryId + "/content])"; +// Query query = queryManager.createQuery( "SELECT size FROM [archiva:artifact] " + whereClause, +// Query.JCR_SQL2 ); + String whereClause = "WHERE jcr:path LIKE '/repositories/" + repositoryId + "/content/%'"; + Query query = queryManager.createQuery( "SELECT size FROM archiva:artifact " + whereClause, Query.SQL ); QueryResult queryResult = query.execute(); @@ -173,25 +179,22 @@ public class DefaultRepositoryStatisticsManager for ( Row row : JcrUtils.getRows( queryResult ) ) { Node n = row.getNode(); -// if ( n.getPath().startsWith( "/repositories/" + repositoryId + "/content/" ) ) - { - totalSize += row.getValue( "size" ).getLong(); + totalSize += row.getValue( "size" ).getLong(); - String type; - if ( n.hasNode( MavenArtifactFacet.FACET_ID ) ) - { - Node facetNode = n.getNode( MavenArtifactFacet.FACET_ID ); - type = facetNode.getProperty( "type" ).getString(); - } - else - { - type = "Other"; - } - Integer prev = totalByType.get( type ); - totalByType.put( type, prev != null ? prev + 1 : 1 ); - - totalArtifacts++; + String type; + if ( n.hasNode( MavenArtifactFacet.FACET_ID ) ) + { + Node facetNode = n.getNode( MavenArtifactFacet.FACET_ID ); + type = facetNode.getProperty( "type" ).getString(); } + else + { + type = "Other"; + } + Integer prev = totalByType.get( type ); + totalByType.put( type, prev != null ? prev + 1 : 1 ); + + totalArtifacts++; } repositoryStatistics.setTotalArtifactCount( totalArtifacts ); @@ -201,11 +204,17 @@ public class DefaultRepositoryStatisticsManager repositoryStatistics.setTotalCountForType( entry.getKey(), entry.getValue() ); } - query = queryManager.createQuery( "SELECT * FROM [archiva:project] " + whereClause, Query.JCR_SQL2 ); + // The query ordering is a trick to ensure that the size is correct, otherwise due to lazy init it will be -1 +// query = queryManager.createQuery( "SELECT * FROM [archiva:project] " + whereClause, Query.JCR_SQL2 ); + query = queryManager.createQuery( "SELECT * FROM archiva:project " + whereClause + " ORDER BY jcr:score", + Query.SQL ); repositoryStatistics.setTotalProjectCount( query.execute().getRows().getSize() ); +// query = queryManager.createQuery( +// "SELECT * FROM [archiva:namespace] " + whereClause + " AND namespace IS NOT NULL", Query.JCR_SQL2 ); query = queryManager.createQuery( - "SELECT * FROM [archiva:namespace] " + whereClause + " AND namespace IS NOT NULL", Query.JCR_SQL2 ); + "SELECT * FROM archiva:namespace " + whereClause + " AND namespace IS NOT NULL ORDER BY jcr:score", + Query.SQL ); repositoryStatistics.setTotalGroupCount( query.execute().getRows().getSize() ); } catch ( RepositoryException e )