]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1443] count the repository statistics directly
authorBrett Porter <brett@apache.org>
Thu, 9 Dec 2010 07:58:00 +0000 (07:58 +0000)
committerBrett Porter <brett@apache.org>
Thu, 9 Dec 2010 07:58:00 +0000 (07:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@1043850 13f79535-47bb-0310-9956-ffa450edef68

17 files changed:
archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/stubs/ArchivaDAOStub.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/stubs/ArchivaDAOStub.java
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/ArtifactDAO.java
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/SimpleConstraint.java
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/AbstractSimpleConstraint.java
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueArtifactIdConstraint.java
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/UniqueGroupIdConstraint.java
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoAccess.java
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java
archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArtifactDAO.java
archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java
archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/stubs/ArtifactDAOStub.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoryArchivaDAOStub.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArtifactDAOStub.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/rss/ArtifactDAOStub.java

index 47ebdce6269e577518d034a2952b8adb0e5632e6..0d6b598053dc11bc6efd0d104d068b90486d85d6 100644 (file)
@@ -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
index e6a67a8ff4d799a1f7554d9fdac4e14cca968243..912b0daa61d1a896808f86b05509c2b706d278b6 100644 (file)
@@ -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
index 76566b4d7afe0cdb2c8a1bbe7cfdc69b3d1107c9..b51802668928cb70d69d1166e40542ac6e14e860 100644 (file)
@@ -54,4 +54,6 @@ public interface ArchivaDAO
     RepositoryProblemDAO getRepositoryProblemDAO();
     
     RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO();
+
+    long count( SimpleConstraint constraint );
 }
index 2c8d901fe9e45afd043f3bb4cb6702dd06ebdd87..d205bcce4a03d7b40ebb02dda3facbc5a0201c3d 100644 (file)
@@ -66,4 +66,6 @@ public interface ArtifactDAO
 
     public void deleteArtifact( ArchivaArtifact artifact )
         throws ArchivaDatabaseException;
+
+    long countArtifacts( DeclarativeConstraint constraint );
 }
index bdfb0992683619071074eade299bcfb28d619183..9edea1baa19e2c4b8d2f977b99c17169a4240c96 100644 (file)
@@ -56,4 +56,6 @@ public interface SimpleConstraint extends Constraint
      * @return true if result classes are persistable.
      */
     public boolean isResultsPersistable();
+
+    String getCountSql();
 }
index 9cb4acc995dd4e48f5aec0c3f7a00edcdbcc1fbc..0f966689976baa56adc7913d26609e573f6b5986 100644 (file)
@@ -45,4 +45,9 @@ public abstract class AbstractSimpleConstraint
     {
         return false;
     }
+
+    public String getCountSql()
+    {
+        throw new UnsupportedOperationException( "count not supported" );
+    }
 }
index 1449352afdbb19082d4e8775eff75e75c1050aaf..f5a8654c3e817352aacb5fbf322ee873a18c2d71 100644 (file)
@@ -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" );
index 459cb1bcc3b200cfbb1fbfcab1c24a6848406e05..1f0374706a4c73ac14baa4f8d522da267f9ccefc 100644 (file)
@@ -38,13 +38,11 @@ public class UniqueGroupIdConstraint
     public UniqueGroupIdConstraint()
     {
         /* this assumes search for no groupId prefix */
-        appendSelect( sql );
         appendGroupBy( sql );
     }
 
     public UniqueGroupIdConstraint( List<String> selectedRepositories )
     {
-        appendSelect( sql );
         sql.append( " WHERE " );
         SqlBuilder.appendWhereSelectedRepositories( sql, "repositoryId", selectedRepositories );
         appendGroupBy( sql );
@@ -52,7 +50,6 @@ public class UniqueGroupIdConstraint
 
     public UniqueGroupIdConstraint( List<String> 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 )
index dd38dfe52a8a000b7c71afc032f4da49d2af1870..0ea0e0b84f1707a6ff956d73fe4f078633f540cf 100644 (file)
@@ -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;
+    }
 }
index 54d30af86a1ea9679fd0f78e8c5522601886255d..1f66068ff21872320cda2ea7cedc5a8991725bcf 100644 (file)
@@ -94,4 +94,9 @@ public class JdoArchivaDAO
     {
         return repositoryContentStatisticsDAO;
     }
+
+    public long count( SimpleConstraint constraint )
+    {
+        return jdo.countObjects( constraint );
+    }
 }
index 8380d9e1df7fdda390c93ff175573f6a56a56fa0..ae29bfa003c114da63d5abbe144e11c68ea9ebff 100644 (file)
@@ -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<ArchivaArtifactModel> results = (List<ArchivaArtifactModel>) jdo.queryObjects( ArchivaArtifactModel.class, constraint );
-        if ( results == null )
-        {
-            return null;
-        }
 
-        List<ArchivaArtifact> ret = new ArrayList<ArchivaArtifact>();
-        for ( ArchivaArtifactModel model : results )
+        List<ArchivaArtifact> ret = null;
+        if ( results != null )
         {
-            ret.add( new ArchivaArtifact( model ) );
+            ret = new ArrayList<ArchivaArtifact>();
+            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 );
+    }
 }
index d775068f4034397b4b8491bbe624c68354be5c5b..f4c0483201429c20d8b6e44b7892a8a51642eb94 100644 (file)
@@ -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<ArchivaArtifact> 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<String> repos = new ArrayList<String>();
         repos.add( arepo.getId() );
 
-        List<String> groupIds = (List<String>) dao.query( new UniqueGroupIdConstraint( repos ) );
-        dbstats.setTotalGroupCount( groupIds.size() );
+        dbstats.setTotalGroupCount( dao.count( new UniqueGroupIdConstraint( repos ) ) );
 
-        List<Object[]> artifactIds =
-            (List<Object[]>) dao.query( new UniqueArtifactIdConstraint( arepo.getId(), true ) );
-        dbstats.setTotalProjectCount( artifactIds.size() );
+        dbstats.setTotalProjectCount( dao.count( new UniqueArtifactIdConstraint( arepo.getId(), true ) ) );
 
         return dbstats;
     }
index 9eade4d6511d888d6fa891f6cbeacc8f54d59637..3d57e50d51104463b21584b082d206a33e7cb7b3 100644 (file)
@@ -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
index 0f17dd28cc1bb28efd6db564ccba4ed31a38e443..ea6752d4c4b8f2c4f72c3def2c558d36c967ab9f 100644 (file)
@@ -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();
+    }
 }
index 2e9b97e5813ed6060f61d93d0e81e30abfeaa715..d34394c9c259d330344021e6ffe573fa7d137767 100644 (file)
@@ -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;
index 3efb1ec6b1856d0501bd90df8ac1d2b81b3d1f81..8a298b7ffdc19b7e0280fc12e4e5dc68ff4fcaaa 100644 (file)
@@ -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<ArchivaArtifact> queryArtifacts( Constraint constraint )
-        throws ObjectNotFoundException, ArchivaDatabaseException
     {
 
         List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
index 3a4f66c840b215fc68e0cc49f648e29f1aab17db..faa19ed9b2c4ac2d7e9a62114805f88387cfbdc1 100644 (file)
@@ -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<ArchivaArtifact> queryArtifacts( Constraint constraint )
-        throws ObjectNotFoundException, ArchivaDatabaseException
     {
         List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();