aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-database/src
diff options
context:
space:
mode:
authorJoakim Erdfelt <joakime@apache.org>2007-04-19 12:25:11 +0000
committerJoakim Erdfelt <joakime@apache.org>2007-04-19 12:25:11 +0000
commit8b0319bf628d8ba366d2c12791db67c340dc0076 (patch)
tree06240146f2f875508c60b11908f5d7c4fdc597c4 /archiva-database/src
parent346583093493614302e3761b3de1c2d8ff67a806 (diff)
downloadarchiva-8b0319bf628d8ba366d2c12791db67c340dc0076.tar.gz
archiva-8b0319bf628d8ba366d2c12791db67c340dc0076.zip
Refactoring of reporting. One step closer to an end-to-end compile.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@530395 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-database/src')
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java2
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryProblemDAO.java63
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraint.java52
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/OlderArtifactsByAgeConstraint.java60
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/OlderSnapshotArtifactsByAgeConstraint.java60
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RecentArtifactsByAgeConstraint.java61
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByTypeConstraint.java52
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java11
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryProblemDAO.java63
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraintTest.java112
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/OlderArtifactsByAgeConstraintTest.java103
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/OlderSnapshotArtifactsByAgeConstraintTest.java118
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RecentArtifactsByAgeConstraintTest.java104
13 files changed, 861 insertions, 0 deletions
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java
index 7d62c93e1..fab48a554 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java
@@ -34,4 +34,6 @@ public interface ArchivaDAO
ProjectModelDAO getProjectModelDAO();
RepositoryDAO getRepositoryDAO();
+
+ RepositoryProblemDAO getRepositoryProblemDAO();
}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryProblemDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryProblemDAO.java
new file mode 100644
index 000000000..f4aecd2f4
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/RepositoryProblemDAO.java
@@ -0,0 +1,63 @@
+package org.apache.maven.archiva.database;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.model.RepositoryProblem;
+
+import java.util.List;
+
+/**
+ * RepositoryProblemDAO
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public interface RepositoryProblemDAO
+{
+ /* NOTE TO ARCHIVA DEVELOPERS.
+ *
+ * Please keep this interface clean and lean.
+ * We don't want a repeat of the Continuum Store.
+ * You should have the following methods per object type ...
+ *
+ * (Required Methods)
+ *
+ * List .queryDatabaseObject( Constraint ) throws ObjectNotFoundException, DatabaseException;
+ * DatabaseObject .saveDatabaseObject( DatabaseObject ) throws DatabaseException;
+ *
+ * (Optional Methods)
+ *
+ * DatabaseObject .createDatabaseObject( Required Params ) ;
+ * DatabaseObject .getDatabaseObject( Id ) throws ObjectNotFoundException, DatabaseException;
+ * List .getDatabaseObjects() throws ObjectNotFoundException, DatabaseException;
+ * void .deleteDatabaseObject( DatabaseObject ) throws DatabaseException;
+ *
+ * This is the only list of options created in this DAO.
+ */
+
+ public List /*<RepositoryProblem>*/queryRepositoryProblems( Constraint constraint )
+ throws ObjectNotFoundException, ArchivaDatabaseException;
+
+ public RepositoryProblem saveRepositoryProblem( RepositoryProblem problem )
+ throws ArchivaDatabaseException;
+
+ public void deleteRepositoryProblem( RepositoryProblem problem )
+ throws ArchivaDatabaseException;
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraint.java
new file mode 100644
index 000000000..464f75c02
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraint.java
@@ -0,0 +1,52 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.Constraint;
+
+/**
+ * ArtifactsBySha1ChecksumConstraint
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArtifactsBySha1ChecksumConstraint
+ extends AbstractConstraint
+ implements Constraint
+{
+ private String whereClause;
+
+ public ArtifactsBySha1ChecksumConstraint( String desiredChecksum )
+ {
+ whereClause = "this.checksumSHA1 == desiredChecksum";
+ declParams = new String[] { "String desiredChecksum" };
+ params = new Object[] { desiredChecksum };
+ }
+
+ public String getSortColumn()
+ {
+ return "groupId";
+ }
+
+ public String getWhereCondition()
+ {
+ return whereClause;
+ }
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/OlderArtifactsByAgeConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/OlderArtifactsByAgeConstraint.java
new file mode 100644
index 000000000..b893e690c
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/OlderArtifactsByAgeConstraint.java
@@ -0,0 +1,60 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.Constraint;
+
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * Constraint for artifacts that are of a certain age (in days) or older.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class OlderArtifactsByAgeConstraint
+ extends AbstractConstraint
+ implements Constraint
+{
+ private String whereClause;
+
+ public OlderArtifactsByAgeConstraint( int daysOld )
+ {
+ Calendar cal = Calendar.getInstance();
+ cal.add( Calendar.DAY_OF_MONTH, ( -1 ) * daysOld );
+ Date cutoffDate = cal.getTime();
+
+ whereClause = "this.lastModified <= cutoffDate";
+ declImports = new String[] { "import java.util.Date" };
+ declParams = new String[] { "java.util.Date cutoffDate" };
+ params = new Object[] { cutoffDate };
+ }
+
+ public String getSortColumn()
+ {
+ return "groupId";
+ }
+
+ public String getWhereCondition()
+ {
+ return whereClause;
+ }
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/OlderSnapshotArtifactsByAgeConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/OlderSnapshotArtifactsByAgeConstraint.java
new file mode 100644
index 000000000..a55907b14
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/OlderSnapshotArtifactsByAgeConstraint.java
@@ -0,0 +1,60 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.Constraint;
+
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * Constraint for snapshot artifacts that are of a certain age (in days) or older.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class OlderSnapshotArtifactsByAgeConstraint
+ extends AbstractConstraint
+ implements Constraint
+{
+ private String whereClause;
+
+ public OlderSnapshotArtifactsByAgeConstraint( int daysOld )
+ {
+ Calendar cal = Calendar.getInstance();
+ cal.add( Calendar.DAY_OF_MONTH, ( -1 ) * daysOld );
+ Date cutoffDate = cal.getTime();
+
+ whereClause = "this.lastModified <= cutoffDate && this.snapshot == true";
+ declImports = new String[] { "import java.util.Date" };
+ declParams = new String[] { "java.util.Date cutoffDate" };
+ params = new Object[] { cutoffDate };
+ }
+
+ public String getSortColumn()
+ {
+ return "groupId";
+ }
+
+ public String getWhereCondition()
+ {
+ return whereClause;
+ }
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RecentArtifactsByAgeConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RecentArtifactsByAgeConstraint.java
new file mode 100644
index 000000000..e590b015f
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RecentArtifactsByAgeConstraint.java
@@ -0,0 +1,61 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.Constraint;
+
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * Constraint for artifacts that are of a certain age (in days) or newer.
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RecentArtifactsByAgeConstraint
+ extends AbstractConstraint
+ implements Constraint
+{
+ private String whereClause;
+
+ public RecentArtifactsByAgeConstraint( int daysOld )
+ {
+ Calendar cal = Calendar.getInstance();
+ // Extra subtraction of 1 done to allow for lastModified that occur on the day represented by 'daysOld'.
+ cal.add( Calendar.DAY_OF_MONTH, (( -1 ) * daysOld) - 1 );
+ Date cutoffDate = cal.getTime();
+
+ whereClause = "this.lastModified >= cutoffDate";
+ declImports = new String[] { "import java.util.Date" };
+ declParams = new String[] { "java.util.Date cutoffDate" };
+ params = new Object[] { cutoffDate };
+ }
+
+ public String getSortColumn()
+ {
+ return "groupId";
+ }
+
+ public String getWhereCondition()
+ {
+ return whereClause;
+ }
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByTypeConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByTypeConstraint.java
new file mode 100644
index 000000000..6de7788b3
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryProblemByTypeConstraint.java
@@ -0,0 +1,52 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.Constraint;
+
+/**
+ * RepositoryProblemByTypeConstraint
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryProblemByTypeConstraint
+ extends AbstractConstraint
+ implements Constraint
+{
+ private String whereClause;
+
+ public RepositoryProblemByTypeConstraint( String desiredType )
+ {
+ whereClause = "type == desiredType";
+ declParams = new String[] { "String desiredType" };
+ params = new Object[] { desiredType };
+ }
+
+ public String getSortColumn()
+ {
+ return "groupId";
+ }
+
+ public String getWhereCondition()
+ {
+ return whereClause;
+ }
+}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java
index 18b26f032..5c87e91dd 100644
--- a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java
@@ -23,6 +23,7 @@ import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.ProjectModelDAO;
import org.apache.maven.archiva.database.RepositoryDAO;
+import org.apache.maven.archiva.database.RepositoryProblemDAO;
import org.codehaus.plexus.logging.AbstractLogEnabled;
/**
@@ -51,6 +52,11 @@ public class JdoArchivaDAO
* @plexus.requirement role-hint="jdo"
*/
private RepositoryDAO repositoryDAO;
+
+ /**
+ * @plexus.requirement role-hint="jdo"
+ */
+ private RepositoryProblemDAO repositoryProblemDAO;
public ArtifactDAO getArtifactDAO()
{
@@ -66,4 +72,9 @@ public class JdoArchivaDAO
{
return repositoryDAO;
}
+
+ public RepositoryProblemDAO getRepositoryProblemDAO()
+ {
+ return repositoryProblemDAO;
+ }
}
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryProblemDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryProblemDAO.java
new file mode 100644
index 000000000..ead2bfda3
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryProblemDAO.java
@@ -0,0 +1,63 @@
+package org.apache.maven.archiva.database.jdo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.database.ObjectNotFoundException;
+import org.apache.maven.archiva.database.RepositoryProblemDAO;
+import org.apache.maven.archiva.model.RepositoryProblem;
+
+import java.util.List;
+
+/**
+ * JdoRepositoryProblemDAO
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ *
+ * @plexus.component role-hint="jdo"
+ */
+public class JdoRepositoryProblemDAO
+ implements RepositoryProblemDAO
+{
+ /**
+ * @plexus.requirement role-hint="archiva"
+ */
+ private JdoAccess jdo;
+
+ public List queryRepositoryProblems( Constraint constraint )
+ throws ObjectNotFoundException, ArchivaDatabaseException
+ {
+ return jdo.getAllObjects( RepositoryProblem.class, constraint );
+ }
+
+ public RepositoryProblem saveRepositoryProblem( RepositoryProblem problem )
+ throws ArchivaDatabaseException
+ {
+ return (RepositoryProblem) jdo.saveObject( problem );
+ }
+
+ public void deleteRepositoryProblem( RepositoryProblem problem )
+ throws ArchivaDatabaseException
+ {
+ jdo.removeObject( problem );
+ }
+}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraintTest.java
new file mode 100644
index 000000000..f958384ae
--- /dev/null
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsBySha1ChecksumConstraintTest.java
@@ -0,0 +1,112 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.ArtifactDAO;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * ArtifactsBySha1ChecksumConstraintTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class ArtifactsBySha1ChecksumConstraintTest
+ extends AbstractArchivaDatabaseTestCase
+{
+ private static final String HASH3 = "f3f653289f3217c65324830ab3415bc92feddefa";
+
+ private static final String HASH2 = "a49810ad3eba8651677ab57cd40a0f76fdef9538";
+
+ private static final String HASH1 = "232f01b24b1617c46a3d4b0ab3415bc9237dcdec";
+
+ private ArtifactDAO artifactDao;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
+ artifactDao = dao.getArtifactDAO();
+ }
+
+ public ArchivaArtifact createArtifact( String artifactId, String version )
+ {
+ ArchivaArtifact artifact = artifactDao.createArtifact( "org.apache.maven.archiva.test", artifactId, version,
+ "", "jar" );
+ artifact.getModel().setLastModified( new Date() );
+ artifact.getModel().setRepositoryId( "testable_repo" );
+ return artifact;
+ }
+
+ public void testConstraint()
+ throws Exception
+ {
+ ArchivaArtifact artifact;
+
+ // Setup artifacts in fresh DB.
+ artifact = createArtifact( "test-one", "1.0" );
+ artifact.getModel().setChecksumSHA1( HASH1 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-one", "1.1" );
+ artifact.getModel().setChecksumSHA1( HASH1 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-one", "1.2" );
+ artifact.getModel().setChecksumSHA1( HASH1 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "1.0" );
+ artifact.getModel().setChecksumSHA1( HASH1 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "2.0" );
+ artifact.getModel().setChecksumSHA1( HASH3 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "2.1" );
+ artifact.getModel().setChecksumSHA1( HASH2 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "3.0" );
+ artifact.getModel().setChecksumSHA1( HASH2 );
+ artifactDao.saveArtifact( artifact );
+
+ assertConstraint( "Artifacts by SHA1 Checksum", 4, new ArtifactsBySha1ChecksumConstraint( HASH1 ) );
+ assertConstraint( "Artifacts by SHA1 Checksum", 2, new ArtifactsBySha1ChecksumConstraint( HASH2 ) );
+ assertConstraint( "Artifacts by SHA1 Checksum", 1, new ArtifactsBySha1ChecksumConstraint( HASH3 ) );
+ }
+
+ private void assertConstraint( String msg, int count, ArtifactsBySha1ChecksumConstraint constraint )
+ throws Exception
+ {
+ List results = artifactDao.queryArtifacts( constraint );
+ assertNotNull( msg + ": Not Null", results );
+ assertEquals( msg + ": Results.size", count, results.size() );
+ }
+
+}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/OlderArtifactsByAgeConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/OlderArtifactsByAgeConstraintTest.java
new file mode 100644
index 000000000..a306b7ba4
--- /dev/null
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/OlderArtifactsByAgeConstraintTest.java
@@ -0,0 +1,103 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.ArtifactDAO;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+
+import java.util.Calendar;
+import java.util.List;
+
+/**
+ * OlderArtifactsByAgeConstraintTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class OlderArtifactsByAgeConstraintTest
+ extends AbstractArchivaDatabaseTestCase
+{
+ private ArtifactDAO artifactDao;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
+ artifactDao = dao.getArtifactDAO();
+ }
+
+ public ArchivaArtifact createArtifact( String artifactId, String version, int daysOld )
+ {
+ ArchivaArtifact artifact = artifactDao.createArtifact( "org.apache.maven.archiva.test", artifactId, version,
+ "", "jar" );
+ Calendar cal = Calendar.getInstance();
+ cal.add( Calendar.DAY_OF_MONTH, ( -1 ) * daysOld );
+ artifact.getModel().setLastModified( cal.getTime() );
+ artifact.getModel().setRepositoryId( "testable_repo" );
+ return artifact;
+ }
+
+ public void testConstraint()
+ throws Exception
+ {
+ ArchivaArtifact artifact;
+
+ // Setup artifacts in fresh DB.
+ artifact = createArtifact( "test-one", "1.0", 200 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-one", "1.1", 100 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-one", "1.2", 50 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "1.0", 200 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "2.0", 150 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "2.1", 100 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "3.0", 5 );
+ artifactDao.saveArtifact( artifact );
+
+ assertConstraint( 6, new OlderArtifactsByAgeConstraint( 7 ) );
+ assertConstraint( 5, new OlderArtifactsByAgeConstraint( 90 ) );
+ assertConstraint( 5, new OlderArtifactsByAgeConstraint( 100 ) );
+ assertConstraint( 3, new OlderArtifactsByAgeConstraint( 150 ) );
+ assertConstraint( 0, new OlderArtifactsByAgeConstraint( 9000 ) );
+ }
+
+ private void assertConstraint( int expectedHits, Constraint constraint )
+ throws Exception
+ {
+ List results = artifactDao.queryArtifacts( constraint );
+ assertNotNull( "Older Artifacts By Age: Not Null", results );
+ assertEquals( "Older Artifacts By Age: Results.size", expectedHits, results.size() );
+ }
+}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/OlderSnapshotArtifactsByAgeConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/OlderSnapshotArtifactsByAgeConstraintTest.java
new file mode 100644
index 000000000..88838ea72
--- /dev/null
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/OlderSnapshotArtifactsByAgeConstraintTest.java
@@ -0,0 +1,118 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.ArtifactDAO;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+
+import java.util.Calendar;
+import java.util.List;
+
+/**
+ * OlderArtifactsByAgeConstraintTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class OlderSnapshotArtifactsByAgeConstraintTest
+ extends AbstractArchivaDatabaseTestCase
+{
+ private ArtifactDAO artifactDao;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
+ artifactDao = dao.getArtifactDAO();
+ }
+
+ public ArchivaArtifact createArtifact( String artifactId, String version, int daysOld )
+ {
+ ArchivaArtifact artifact = artifactDao.createArtifact( "org.apache.maven.archiva.test", artifactId, version,
+ "", "jar" );
+ Calendar cal = Calendar.getInstance();
+ cal.add( Calendar.DAY_OF_MONTH, ( -1 ) * daysOld );
+ artifact.getModel().setLastModified( cal.getTime() );
+ artifact.getModel().setRepositoryId( "testable_repo" );
+ return artifact;
+ }
+
+ public void testConstraint()
+ throws Exception
+ {
+ ArchivaArtifact artifact;
+
+ // Setup artifacts in fresh DB.
+ artifact = createArtifact( "test-one", "1.0", 200 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-one", "1.1-SNAPSHOT", 110 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-one", "1.1", 100 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-one", "1.2-20060923.005752-2", 55 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-one", "1.2-SNAPSHOT", 52 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-one", "1.2", 50 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "1.0-20060828.144210-1", 220 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "1.0-SNAPSHOT", 210 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "1.0", 200 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "2.0", 150 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "2.1", 100 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "3.0", 5 );
+ artifactDao.saveArtifact( artifact );
+
+ assertConstraint( 5, new OlderSnapshotArtifactsByAgeConstraint( 7 ) );
+ assertConstraint( 3, new OlderSnapshotArtifactsByAgeConstraint( 90 ) );
+ assertConstraint( 3, new OlderSnapshotArtifactsByAgeConstraint( 100 ) );
+ assertConstraint( 2, new OlderSnapshotArtifactsByAgeConstraint( 150 ) );
+ assertConstraint( 0, new OlderSnapshotArtifactsByAgeConstraint( 500 ) );
+ }
+
+ private void assertConstraint( int expectedHits, Constraint constraint )
+ throws Exception
+ {
+ List results = artifactDao.queryArtifacts( constraint );
+ assertNotNull( "Older Snapshot Artifacts By Age: Not Null", results );
+ assertEquals( "Older Snapshot Artifacts By Age: Results.size", expectedHits, results.size() );
+ }
+}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RecentArtifactsByAgeConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RecentArtifactsByAgeConstraintTest.java
new file mode 100644
index 000000000..4512264f3
--- /dev/null
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RecentArtifactsByAgeConstraintTest.java
@@ -0,0 +1,104 @@
+package org.apache.maven.archiva.database.constraints;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.ArtifactDAO;
+import org.apache.maven.archiva.database.Constraint;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+
+import java.util.Calendar;
+import java.util.List;
+
+/**
+ * RecentArtifactsByAgeConstraintTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RecentArtifactsByAgeConstraintTest
+ extends AbstractArchivaDatabaseTestCase
+{
+ private ArtifactDAO artifactDao;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ ArchivaDAO dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
+ artifactDao = dao.getArtifactDAO();
+ }
+
+ public ArchivaArtifact createArtifact( String artifactId, String version, int daysOld )
+ {
+ ArchivaArtifact artifact = artifactDao.createArtifact( "org.apache.maven.archiva.test", artifactId, version,
+ "", "jar" );
+ Calendar cal = Calendar.getInstance();
+ cal.add( Calendar.DAY_OF_MONTH, ( -1 ) * daysOld );
+ artifact.getModel().setLastModified( cal.getTime() );
+ artifact.getModel().setRepositoryId( "testable_repo" );
+ return artifact;
+ }
+
+ public void testConstraint()
+ throws Exception
+ {
+ ArchivaArtifact artifact;
+
+ // Setup artifacts in fresh DB.
+ artifact = createArtifact( "test-one", "1.0", 200 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-one", "1.1", 100 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-one", "1.2", 50 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "1.0", 200 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "2.0", 150 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "2.1", 100 );
+ artifactDao.saveArtifact( artifact );
+
+ artifact = createArtifact( "test-two", "3.0", 5 );
+ artifactDao.saveArtifact( artifact );
+
+ assertConstraint( 0, new RecentArtifactsByAgeConstraint( 2 ) );
+ assertConstraint( 1, new RecentArtifactsByAgeConstraint( 7 ) );
+ assertConstraint( 2, new RecentArtifactsByAgeConstraint( 90 ) );
+ assertConstraint( 4, new RecentArtifactsByAgeConstraint( 100 ) );
+ assertConstraint( 5, new RecentArtifactsByAgeConstraint( 150 ) );
+ assertConstraint( 7, new RecentArtifactsByAgeConstraint( 9000 ) );
+ }
+
+ private void assertConstraint( int expectedHits, Constraint constraint )
+ throws Exception
+ {
+ List results = artifactDao.queryArtifacts( constraint );
+ assertNotNull( "Recent Artifacts By Age: Not Null", results );
+ assertEquals( "Recent Artifacts By Age: Results.size", expectedHits, results.size() );
+ }
+}