From a927b05eeea7066e7df7e73c6283ca44ced10e51 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 9 Dec 2010 07:58:00 +0000 Subject: [PATCH] [MRM-1443] count the repository statistics directly git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@1043850 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/stubs/ArchivaDAOStub.java | 11 +- .../archiva/proxy/stubs/ArchivaDAOStub.java | 11 +- .../maven/archiva/database/ArchivaDAO.java | 2 + .../maven/archiva/database/ArtifactDAO.java | 2 + .../archiva/database/SimpleConstraint.java | 2 + .../constraints/AbstractSimpleConstraint.java | 5 + .../UniqueArtifactIdConstraint.java | 36 ++++- .../constraints/UniqueGroupIdConstraint.java | 18 ++- .../maven/archiva/database/jdo/JdoAccess.java | 135 ++++++++++++++++-- .../archiva/database/jdo/JdoArchivaDAO.java | 5 + .../archiva/database/jdo/JdoArtifactDAO.java | 26 ++-- ...ArchivaRepositoryScanningTaskExecutor.java | 36 ++--- .../archiva/rss/stubs/ArtifactDAOStub.java | 10 +- ...stractManagedRepositoryArchivaDAOStub.java | 11 +- .../admin/repositories/ArchivaDAOStub.java | 13 +- .../admin/repositories/ArtifactDAOStub.java | 13 +- .../archiva/web/rss/ArtifactDAOStub.java | 19 +-- 17 files changed, 276 insertions(+), 79 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/stubs/ArchivaDAOStub.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/stubs/ArchivaDAOStub.java index 47ebdce62..0d6b59805 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/stubs/ArchivaDAOStub.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/stubs/ArchivaDAOStub.java @@ -19,9 +19,6 @@ package org.apache.archiva.consumers.lucene.stubs; * under the License. */ -import java.io.Serializable; -import java.util.List; - import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.ProjectModelDAO; @@ -29,6 +26,9 @@ import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO; import org.apache.maven.archiva.database.RepositoryProblemDAO; import org.apache.maven.archiva.database.SimpleConstraint; +import java.io.Serializable; +import java.util.List; + /** * Using a stub for faster tests! Not really used for the unit tests, just for dependency injection. */ @@ -54,6 +54,11 @@ public class ArchivaDAOStub return null; } + public long count( SimpleConstraint constraint ) + { + return 0; //To change body of implemented methods use File | Settings | File Templates. + } + public RepositoryProblemDAO getRepositoryProblemDAO() { // TODO Auto-generated method stub diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/stubs/ArchivaDAOStub.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/stubs/ArchivaDAOStub.java index e6a67a8ff..912b0daa6 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/stubs/ArchivaDAOStub.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/stubs/ArchivaDAOStub.java @@ -19,9 +19,6 @@ package org.apache.maven.archiva.proxy.stubs; * under the License. */ -import java.io.Serializable; -import java.util.List; - import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.ProjectModelDAO; @@ -29,6 +26,9 @@ import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO; import org.apache.maven.archiva.database.RepositoryProblemDAO; import org.apache.maven.archiva.database.SimpleConstraint; +import java.io.Serializable; +import java.util.List; + /** * Using a stub for faster tests! Not really used for the unit tests, just for dependency injection. */ @@ -54,6 +54,11 @@ public class ArchivaDAOStub return null; } + public long count( SimpleConstraint constraint ) + { + return 0; //To change body of implemented methods use File | Settings | File Templates. + } + public RepositoryProblemDAO getRepositoryProblemDAO() { // TODO Auto-generated method stub diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java index 76566b4d7..b51802668 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java @@ -54,4 +54,6 @@ public interface ArchivaDAO RepositoryProblemDAO getRepositoryProblemDAO(); RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO(); + + long count( SimpleConstraint constraint ); } diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArtifactDAO.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArtifactDAO.java index 2c8d901fe..d205bcce4 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArtifactDAO.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArtifactDAO.java @@ -66,4 +66,6 @@ public interface ArtifactDAO public void deleteArtifact( ArchivaArtifact artifact ) throws ArchivaDatabaseException; + + long countArtifacts( DeclarativeConstraint constraint ); } diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/SimpleConstraint.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/SimpleConstraint.java index bdfb09926..9edea1baa 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/SimpleConstraint.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/SimpleConstraint.java @@ -56,4 +56,6 @@ public interface SimpleConstraint extends Constraint * @return true if result classes are persistable. */ public boolean isResultsPersistable(); + + String getCountSql(); } diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/AbstractSimpleConstraint.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/AbstractSimpleConstraint.java index 9cb4acc99..0f9666899 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/AbstractSimpleConstraint.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/AbstractSimpleConstraint.java @@ -45,4 +45,9 @@ public abstract class AbstractSimpleConstraint { return false; } + + public String getCountSql() + { + throw new UnsupportedOperationException( "count not supported" ); + } } diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueArtifactIdConstraint.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueArtifactIdConstraint.java index 1449352af..f5a8654c3 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueArtifactIdConstraint.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueArtifactIdConstraint.java @@ -34,7 +34,9 @@ public class UniqueArtifactIdConstraint implements Constraint { private StringBuffer sql = new StringBuffer(); - + + private StringBuffer countSql = new StringBuffer(); + private Class resultClass; /** @@ -51,6 +53,13 @@ public class UniqueArtifactIdConstraint appendWhereSelectedGroupId( sql ); appendGroupBy( sql ); + countSql.append( "SELECT count(artifactId) FROM " ).append( ArchivaArtifactModel.class.getName() ); + countSql.append( " WHERE " ); + SqlBuilder.appendWhereSelectedRepositories( countSql, "repositoryId", selectedRepositoryIds ); + countSql.append( " && " ); + appendWhereSelectedGroupId( countSql ); + appendGroupBy( countSql ); + super.params = new Object[] { groupId }; } @@ -66,6 +75,11 @@ public class UniqueArtifactIdConstraint appendWhereSelectedGroupId( sql ); appendGroupBy( sql ); + countSql.append( "SELECT count(artifactId) FROM " ).append( ArchivaArtifactModel.class.getName() ); + countSql.append( " WHERE " ); + appendWhereSelectedGroupId( countSql ); + appendGroupBy( countSql ); + super.params = new Object[] { groupId }; } @@ -79,7 +93,19 @@ public class UniqueArtifactIdConstraint { appendSelect( sql, isUnique ); sql.append( " WHERE repositoryId == \"" + repoId + "\"" ); - + + if( isUnique ) + { + countSql.append( "SELECT count(this) FROM " ).append( ArchivaArtifactModel.class.getName() ); + countSql.append( " WHERE repositoryId == \"" ).append( repoId ).append( "\"" ); + countSql.append( " GROUP BY groupId, artifactId" ); + } + else + { + countSql.append( "SELECT count(artifactId) FROM " ).append( ArchivaArtifactModel.class.getName() ); + countSql.append( " WHERE repositoryId == \"" ).append( repoId ).append( "\"" ); + } + resultClass = Object[].class; } @@ -99,6 +125,12 @@ public class UniqueArtifactIdConstraint return sql.toString(); } + @Override + public String getCountSql() + { + return countSql.toString(); + } + private void appendGroupBy( StringBuffer buf ) { buf.append( " GROUP BY artifactId ORDER BY artifactId ASCENDING" ); diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueGroupIdConstraint.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueGroupIdConstraint.java index 459cb1bcc..1f0374706 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueGroupIdConstraint.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueGroupIdConstraint.java @@ -38,13 +38,11 @@ public class UniqueGroupIdConstraint public UniqueGroupIdConstraint() { /* this assumes search for no groupId prefix */ - appendSelect( sql ); appendGroupBy( sql ); } public UniqueGroupIdConstraint( List selectedRepositories ) { - appendSelect( sql ); sql.append( " WHERE " ); SqlBuilder.appendWhereSelectedRepositories( sql, "repositoryId", selectedRepositories ); appendGroupBy( sql ); @@ -52,7 +50,6 @@ public class UniqueGroupIdConstraint public UniqueGroupIdConstraint( List selectedRepositories, String groupIdPrefix ) { - appendSelect( sql ); sql.append( " WHERE " ); SqlBuilder.appendWhereSelectedRepositories( sql, "repositoryId", selectedRepositories ); sql.append( " && " ); @@ -64,7 +61,6 @@ public class UniqueGroupIdConstraint public UniqueGroupIdConstraint( String groupIdPrefix ) { - appendSelect( sql ); sql.append( " WHERE " ); appendWhereGroupIdStartsWith( sql ); appendGroupBy( sql ); @@ -80,7 +76,19 @@ public class UniqueGroupIdConstraint public String getSelectSql() { - return sql.toString(); + StringBuffer buf = new StringBuffer(); + appendSelect( buf ); + buf.append( sql ); + return buf.toString(); + } + + @Override + public String getCountSql() + { + StringBuffer buf = new StringBuffer(); + buf.append( "SELECT count(groupId) FROM " ).append( ArchivaArtifactModel.class.getName() ); + buf.append( sql ); + return buf.toString(); } private void appendGroupBy( StringBuffer buf ) diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java index dd38dfe52..0ea0e0b84 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java @@ -34,7 +34,6 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExce import java.io.PrintStream; import java.util.ArrayList; import java.util.List; - import javax.jdo.Extent; import javax.jdo.JDOException; import javax.jdo.JDOHelper; @@ -210,12 +209,12 @@ public class JdoAccess PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); + List result = null; + try { tx.begin(); - List result = null; - if ( constraint != null ) { if ( constraint instanceof DeclarativeConstraint ) @@ -239,13 +238,13 @@ public class JdoAccess result = (List) pm.detachCopyAll( result ); tx.commit(); - - return result; } finally { rollbackIfActive( tx ); } + + return result; } public List queryObjects( SimpleConstraint constraint ) @@ -304,12 +303,16 @@ public class JdoAccess pm.getFetchPlan().addGroup( constraint.getFetchLimits() ); } + List objects; if ( constraint.getParameters() != null ) { - return processParameterizedQuery( query, constraint.getParameters() ); + objects = processParameterizedQuery( query, constraint.getParameters() ); } - - return (List) query.execute(); + else + { + objects = (List) query.execute(); + } + return objects; } private List processConstraint( PersistenceManager pm, Class clazz, DeclarativeConstraint constraint ) @@ -595,4 +598,120 @@ public class JdoAccess return jdoFactory; } + public long countObjects( SimpleConstraint constraint ) + { + PersistenceManager pm = getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + + try + { + tx.begin(); + + Query query = pm.newQuery( constraint.getCountSql() ); + + if ( constraint.getFetchLimits() != null ) + { + pm.getFetchPlan().addGroup( constraint.getFetchLimits() ); + } + + List objects; + if ( constraint.getParameters() != null ) + { + objects = processParameterizedQuery( query, constraint.getParameters() ); + } + else + { + objects = (List) query.execute(); + } + + Long result = !objects.isEmpty() ? (Long) objects.get( 0 ) : 0; + + tx.commit(); + + return result; + } + finally + { + rollbackIfActive( tx ); + } + } + + public long countObjects( Class clazz, DeclarativeConstraint constraint ) + { + PersistenceManager pm = getPersistenceManager(); + Transaction tx = pm.currentTransaction(); + + Long result = null; + + try + { + tx.begin(); + + Extent extent = pm.getExtent( clazz, true ); + Query query = pm.newQuery( extent ); + + if ( constraint.getFilter() != null ) + { + query.setFilter( constraint.getFilter() ); + } + + if ( constraint.getVariables() != null ) + { + query.declareVariables( StringUtils.join( constraint.getVariables(), "; " ) ); + } + + if ( constraint.getFetchLimits() != null ) + { + pm.getFetchPlan().addGroup( constraint.getFetchLimits() ); + } + + if ( constraint.getWhereCondition() != null ) + { + query.setFilter( constraint.getWhereCondition() ); + } + + if ( constraint.getDeclaredImports() != null ) + { + query.declareImports( StringUtils.join( constraint.getDeclaredImports(), ", " ) ); + } + + if ( constraint.getRange() != null ) + { + query.setRange( constraint.getRange()[0], constraint.getRange()[1] ); + } + + query.setResult( "count(this)" ); + + if ( constraint.getDeclaredParameters() != null ) + { + if ( constraint.getParameters() == null ) + { + throw new JDOException( "Unable to use query, there are declared parameters, " + + "but no parameter objects to use." ); + } + + if ( constraint.getParameters().length != constraint.getDeclaredParameters().length ) + { + throw new JDOException( "Unable to use query, there are <" + constraint.getDeclaredParameters().length + + "> declared parameters, yet there are <" + constraint.getParameters().length + + "> parameter objects to use. This should be equal." ); + } + + query.declareParameters( StringUtils.join( constraint.getDeclaredParameters(), ", " ) ); + + result = (Long) query.executeWithArray( constraint.getParameters() ); + } + else + { + result = (Long) query.execute(); + } + tx.commit(); + } + finally + { + rollbackIfActive( tx ); + } + + return result; + } } diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java index 54d30af86..1f66068ff 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java @@ -94,4 +94,9 @@ public class JdoArchivaDAO { return repositoryContentStatisticsDAO; } + + public long count( SimpleConstraint constraint ) + { + return jdo.countObjects( constraint ); + } } diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java index 8380d9e1d..ae29bfa00 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java @@ -19,17 +19,18 @@ package org.apache.maven.archiva.database.jdo; * under the License. */ -import java.util.ArrayList; -import java.util.List; - import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.Constraint; +import org.apache.maven.archiva.database.DeclarativeConstraint; import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaArtifactModel; import org.apache.maven.archiva.model.jpox.ArchivaArtifactModelKey; +import java.util.ArrayList; +import java.util.List; + /** * JdoArtifactDAO * @@ -86,15 +87,15 @@ public class JdoArtifactDAO throws ObjectNotFoundException, ArchivaDatabaseException { List results = (List) jdo.queryObjects( ArchivaArtifactModel.class, constraint ); - if ( results == null ) - { - return null; - } - List ret = new ArrayList(); - for ( ArchivaArtifactModel model : results ) + List ret = null; + if ( results != null ) { - ret.add( new ArchivaArtifact( model ) ); + ret = new ArrayList(); + for ( ArchivaArtifactModel model : results ) + { + ret.add( new ArchivaArtifact( model ) ); + } } return ret; @@ -117,4 +118,9 @@ public class JdoArtifactDAO { jdo.removeObject( artifact.getModel() ); } + + public long countArtifacts( DeclarativeConstraint constraint ) + { + return jdo.countObjects( ArchivaArtifactModel.class, constraint ); + } } diff --git a/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java b/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java index d775068f4..f4c048320 100644 --- a/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java +++ b/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java @@ -19,23 +19,16 @@ package org.apache.maven.archiva.scheduled.executors; * under the License. */ -import java.io.File; -import java.util.ArrayList; -import java.util.List; - import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.database.ArchivaDAO; -import org.apache.maven.archiva.database.ArchivaDatabaseException; -import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.database.constraints.ArtifactsByRepositoryConstraint; import org.apache.maven.archiva.database.constraints.MostRecentRepositoryScanStatistics; import org.apache.maven.archiva.database.constraints.UniqueArtifactIdConstraint; import org.apache.maven.archiva.database.constraints.UniqueGroupIdConstraint; -import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.RepositoryContentStatistics; import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers; @@ -50,6 +43,10 @@ import org.codehaus.plexus.taskqueue.execution.TaskExecutor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.util.ArrayList; +import java.util.List; + /** * ArchivaRepositoryScanningTaskExecutor * @@ -171,21 +168,9 @@ public class ArchivaRepositoryScanningTaskExecutor dbstats.setWhenGathered( stats.getWhenGathered() ); // total artifact count - try - { - // note that when gathered is the end of the scan, so we look for all those before that time - List artifacts = dao.getArtifactDAO().queryArtifacts( - new ArtifactsByRepositoryConstraint( arepo.getId(), stats.getWhenGathered(), "groupId", true ) ); - dbstats.setTotalArtifactCount( artifacts.size() ); - } - catch ( ObjectNotFoundException oe ) - { - log.error( "Object not found in the database : " + oe.getMessage() ); - } - catch ( ArchivaDatabaseException ae ) - { - log.error( "Error occurred while querying artifacts for artifact count : " + ae.getMessage() ); - } + // note that when gathered is the end of the scan, so we look for all those before that time + dbstats.setTotalArtifactCount( dao.getArtifactDAO().countArtifacts( + new ArtifactsByRepositoryConstraint( arepo.getId(), stats.getWhenGathered(), "groupId", true ) ) ); // total repo size -- TODO: needs to exclude ignored files (eg .svn) long size = FileUtils.sizeOfDirectory( new File( arepo.getLocation() ) ); @@ -195,12 +180,9 @@ public class ArchivaRepositoryScanningTaskExecutor List repos = new ArrayList(); repos.add( arepo.getId() ); - List groupIds = (List) dao.query( new UniqueGroupIdConstraint( repos ) ); - dbstats.setTotalGroupCount( groupIds.size() ); + dbstats.setTotalGroupCount( dao.count( new UniqueGroupIdConstraint( repos ) ) ); - List artifactIds = - (List) dao.query( new UniqueArtifactIdConstraint( arepo.getId(), true ) ); - dbstats.setTotalProjectCount( artifactIds.size() ); + dbstats.setTotalProjectCount( dao.count( new UniqueArtifactIdConstraint( arepo.getId(), true ) ) ); return dbstats; } diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java index 9eade4d65..3d57e50d5 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java +++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java @@ -19,14 +19,15 @@ package org.apache.archiva.rss.stubs; * under the License. */ -import java.util.List; - import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.Constraint; +import org.apache.maven.archiva.database.DeclarativeConstraint; import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.model.ArchivaArtifact; +import java.util.List; + /** * ArtifactDAO stub. * @@ -51,6 +52,11 @@ public class ArtifactDAOStub } + public long countArtifacts( DeclarativeConstraint constraint ) + { + return artifacts.size(); + } + public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier, String type, String repositoryId ) throws ObjectNotFoundException, ArchivaDatabaseException diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryArchivaDAOStub.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryArchivaDAOStub.java index 0f17dd28c..ea6752d4c 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryArchivaDAOStub.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryArchivaDAOStub.java @@ -19,9 +19,6 @@ package org.apache.maven.archiva.web.action.admin.repositories; * under the License. */ -import java.io.Serializable; -import java.util.List; - import org.apache.maven.archiva.database.ArchivaDAO; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.ProjectModelDAO; @@ -30,6 +27,9 @@ import org.apache.maven.archiva.database.RepositoryProblemDAO; import org.apache.maven.archiva.database.SimpleConstraint; import org.apache.maven.archiva.model.RepositoryContentStatistics; +import java.io.Serializable; +import java.util.List; + /** * AbstractManagedRepositoryArchivaDAOStub * @@ -82,4 +82,9 @@ public class AbstractManagedRepositoryArchivaDAOStub { return repoContentStatisticsDAO; } + + public long count( SimpleConstraint constraint ) + { + return query( constraint ).size(); + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java index 2e9b97e58..d34394c9c 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java @@ -1,9 +1,5 @@ package org.apache.maven.archiva.web.action.admin.repositories; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - import junit.framework.Assert; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.database.ArchivaDAO; @@ -18,6 +14,10 @@ import org.apache.maven.archiva.database.constraints.UniqueGroupIdConstraint; import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; import org.apache.maven.archiva.model.RepositoryContentStatistics; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -121,6 +121,11 @@ public class ArchivaDAOStub return repositoryContentStatisticsDAO; } + public long count( SimpleConstraint constraint ) + { + return query( constraint ).size(); + } + public void setArtifactDao( ArtifactDAO artifactDao ) { this.artifactDao = artifactDao; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java index 3efb1ec6b..8a298b7ff 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java @@ -19,16 +19,17 @@ package org.apache.maven.archiva.web.action.admin.repositories; * under the License. */ -import java.util.ArrayList; -import java.util.List; - import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.Constraint; +import org.apache.maven.archiva.database.DeclarativeConstraint; import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.model.ArchivaArtifact; import org.apache.maven.archiva.model.ArchivaArtifactModel; +import java.util.ArrayList; +import java.util.List; + /** * ArtifactDAOStub * @@ -52,6 +53,11 @@ public class ArtifactDAOStub } + public long countArtifacts( DeclarativeConstraint constraint ) + { + return queryArtifacts( constraint ).size(); + } + public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier, String type, String repositoryId ) throws ObjectNotFoundException, ArchivaDatabaseException @@ -61,7 +67,6 @@ public class ArtifactDAOStub } public List queryArtifacts( Constraint constraint ) - throws ObjectNotFoundException, ArchivaDatabaseException { List artifacts = new ArrayList(); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/ArtifactDAOStub.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/ArtifactDAOStub.java index 3a4f66c84..faa19ed9b 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/ArtifactDAOStub.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/ArtifactDAOStub.java @@ -19,17 +19,17 @@ package org.apache.maven.archiva.web.rss; * under the License. */ -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - import org.apache.maven.archiva.database.ArchivaDatabaseException; import org.apache.maven.archiva.database.ArtifactDAO; import org.apache.maven.archiva.database.Constraint; -import org.apache.maven.archiva.database.ObjectNotFoundException; +import org.apache.maven.archiva.database.DeclarativeConstraint; import org.apache.maven.archiva.model.ArchivaArtifact; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + /** * Stub used for RssFeedServlet unit test. * @@ -53,16 +53,19 @@ public class ArtifactDAOStub } + public long countArtifacts( DeclarativeConstraint constraint ) + { + return queryArtifacts( constraint ).size(); + } + public ArchivaArtifact getArtifact( String groupId, String artifactId, String version, String classifier, String type, String repositoryId ) - throws ObjectNotFoundException, ArchivaDatabaseException { // TODO Auto-generated method stub return null; } public List queryArtifacts( Constraint constraint ) - throws ObjectNotFoundException, ArchivaDatabaseException { List artifacts = new ArrayList(); -- 2.39.5