diff options
author | Maria Odea B. Ching <oching@apache.org> | 2007-10-21 17:30:07 +0000 |
---|---|---|
committer | Maria Odea B. Ching <oching@apache.org> | 2007-10-21 17:30:07 +0000 |
commit | 21a61ab5f9c0a139bb25a64c7d8136af6a00dc96 (patch) | |
tree | a461952e7cada7b45eca459e7089262f1121adc0 /archiva-database/src | |
parent | 1d6c1b9d0aab92bf85ec37dc24900bf890410838 (diff) | |
download | archiva-21a61ab5f9c0a139bb25a64c7d8136af6a00dc96.tar.gz archiva-21a61ab5f9c0a139bb25a64c7d8136af6a00dc96.zip |
[MRM-265]
- added method for deleting the artifacts in the db when a repo is deleted
- also deleted repo scan statistics when the repo is deleted
- created DAO that does retrieving, deleting and adding of RepositoryContentStatistics to the db
- added and updated tests
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@586919 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-database/src')
6 files changed, 297 insertions, 2 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 18b1821d3..d38aea1a3 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 @@ -22,6 +22,8 @@ package org.apache.maven.archiva.database; import java.io.Serializable; import java.util.List; +import org.apache.maven.archiva.model.RepositoryContentStatistics; + /** * ArchivaDAO - The interface for all content within the database. * @@ -47,10 +49,12 @@ public interface ArchivaDAO * @return the post-serialized object. */ Object save( Serializable obj ); - + ArtifactDAO getArtifactDAO(); ProjectModelDAO getProjectModelDAO(); RepositoryProblemDAO getRepositoryProblemDAO(); + + RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO(); } diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraint.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraint.java new file mode 100644 index 000000000..dc3990980 --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraint.java @@ -0,0 +1,49 @@ +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. + */ + +/** + * RepositoryContentStatisticsByRepositoryConstraint + * + * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> + * @version + */ +public class RepositoryContentStatisticsByRepositoryConstraint + extends AbstractDeclarativeConstraint +{ + private String whereClause; + + public RepositoryContentStatisticsByRepositoryConstraint( String repoId ) + { + whereClause = "repositoryId == repoId"; + declParams = new String[] { "String repoId" }; + params = new Object[] { repoId }; + } + + public String getSortColumn() + { + return "whenGathered"; + } + + 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 639106184..680c395d8 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 @@ -22,6 +22,7 @@ package org.apache.maven.archiva.database.jdo; 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.RepositoryContentStatisticsDAO; import org.apache.maven.archiva.database.RepositoryProblemDAO; import org.apache.maven.archiva.database.SimpleConstraint; import org.codehaus.plexus.logging.AbstractLogEnabled; @@ -60,6 +61,12 @@ public class JdoArchivaDAO * @plexus.requirement role-hint="jdo" */ private RepositoryProblemDAO repositoryProblemDAO; + + /** + * @plexus.requirement role-hint="jdo" + */ + private RepositoryContentStatisticsDAO repositoryContentStatisticsDAO; + public List query( SimpleConstraint constraint ) { @@ -70,7 +77,7 @@ public class JdoArchivaDAO { return jdo.saveObject( obj ); } - + public ArtifactDAO getArtifactDAO() { return artifactDAO; @@ -85,4 +92,9 @@ public class JdoArchivaDAO { return repositoryProblemDAO; } + + public RepositoryContentStatisticsDAO getRepositoryContentStatisticsDAO() + { + return repositoryContentStatisticsDAO; + } } diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAO.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAO.java new file mode 100644 index 000000000..00475ed9e --- /dev/null +++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAO.java @@ -0,0 +1,67 @@ +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 java.util.List; + +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.RepositoryContentStatisticsDAO; +import org.apache.maven.archiva.model.RepositoryContentStatistics; + +/** + * JdoRepositoryContentStatisticsDAO + * + * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> + * @version + * + * @plexus.component role-hint="jdo" + */ +public class JdoRepositoryContentStatisticsDAO + implements RepositoryContentStatisticsDAO +{ + /** + * @plexus.requirement role-hint="archiva" + */ + private JdoAccess jdo; + + public void deleteRepositoryContentStatistics( RepositoryContentStatistics stats ) + throws ArchivaDatabaseException + { + jdo.removeObject( stats ); + } + + public List queryRepositoryContentStatistics( Constraint constraint ) + throws ObjectNotFoundException, ArchivaDatabaseException + { + List results = jdo.queryObjects( RepositoryContentStatistics.class, constraint ); + + return results; + } + + public RepositoryContentStatistics saveRepositoryContentStatistics( RepositoryContentStatistics stats ) + { + RepositoryContentStatistics savedStats = (RepositoryContentStatistics) jdo.saveObject( stats ); + + return savedStats; + } + +} diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraintTest.java new file mode 100644 index 000000000..3e036b554 --- /dev/null +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/RepositoryContentStatisticsByRepositoryConstraintTest.java @@ -0,0 +1,79 @@ +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 java.util.List; + +import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase; +import org.apache.maven.archiva.database.Constraint; +import org.apache.maven.archiva.model.RepositoryContentStatistics; + +/** + * RepositoryContentStatisticsByRepositoryConstraintTest + * + * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> + * @version + */ +public class RepositoryContentStatisticsByRepositoryConstraintTest + extends AbstractArchivaDatabaseTestCase +{ + private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles, + long newfiles ) + throws Exception + { + RepositoryContentStatistics stats = new RepositoryContentStatistics(); + stats.setRepositoryId( repoId ); + stats.setDuration( duration ); + stats.setNewFileCount( newfiles ); + stats.setTotalFileCount( totalfiles ); + stats.setWhenGathered( toDate( timestamp ) ); + + return stats; + } + + protected void setUp() + throws Exception + { + super.setUp(); + + dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( + createStats( "internal", "2007/10/21 8:00:00", 20000, 12000, 400 ) ); + dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( + createStats( "internal", "2007/10/20 8:00:00", 20000, 11800, 0 ) ); + dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( + createStats( "internal", "2007/10/19 8:00:00", 20000, 11800, 100 ) ); + dao.getRepositoryContentStatisticsDAO().saveRepositoryContentStatistics( + createStats( "internal", "2007/10/18 8:00:00", 20000, 11700, 320 ) ); + } + + public void testStats() + throws Exception + { + Constraint constraint = new RepositoryContentStatisticsByRepositoryConstraint( "internal" ); + List results = dao.getRepositoryContentStatisticsDAO().queryRepositoryContentStatistics( constraint ); + assertNotNull( "Stats: results (not null)", results ); + assertEquals( "Stats: results.size", 4, results.size() ); + + assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 0 ) ).getRepositoryId() ); + assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 1 ) ).getRepositoryId() ); + assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 2 ) ).getRepositoryId() ); + assertEquals( "internal", ( (RepositoryContentStatistics) results.get( 3 ) ).getRepositoryId() ); + } +} diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAOTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAOTest.java new file mode 100644 index 000000000..3989d72fe --- /dev/null +++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/jdo/JdoRepositoryContentStatisticsDAOTest.java @@ -0,0 +1,84 @@ +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 java.util.List; + +import javax.jdo.JDOHelper; + +import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase; +import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO; +import org.apache.maven.archiva.database.constraints.RepositoryContentStatisticsByRepositoryConstraint; +import org.apache.maven.archiva.model.RepositoryContentStatistics; + +/** + * JdoRepositoryContentStatisticsDAOTest + * + * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a> + * @version + */ +public class JdoRepositoryContentStatisticsDAOTest + extends AbstractArchivaDatabaseTestCase +{ + public void testCRUD() + throws Exception + { + RepositoryContentStatisticsDAO repoContentStatisticsDAO = dao.getRepositoryContentStatisticsDAO(); + + // create + RepositoryContentStatistics savedStats = + repoContentStatisticsDAO.saveRepositoryContentStatistics( createStats( "internal", "2007/10/21 8:00:00", + 20000, 12000, 400 ) ); + assertNotNull( savedStats ); + + String savedKeyId = JDOHelper.getObjectId( savedStats ).toString(); + assertEquals( "1[OID]org.apache.maven.archiva.model.RepositoryContentStatistics", savedKeyId ); + + // query + List results = + repoContentStatisticsDAO.queryRepositoryContentStatistics( new RepositoryContentStatisticsByRepositoryConstraint( + "internal" ) ); + assertNotNull( results ); + assertEquals( 1, results.size() ); + + RepositoryContentStatistics stats = (RepositoryContentStatistics) results.get( 0 ); + assertEquals( "internal", stats.getRepositoryId() ); + + // delete + repoContentStatisticsDAO.deleteRepositoryContentStatistics( stats ); + + assertEquals( 0, repoContentStatisticsDAO.queryRepositoryContentStatistics( + new RepositoryContentStatisticsByRepositoryConstraint( "internal" ) ).size() ); + } + + private RepositoryContentStatistics createStats( String repoId, String timestamp, long duration, long totalfiles, + long newfiles ) + throws Exception + { + RepositoryContentStatistics stats = new RepositoryContentStatistics(); + stats.setRepositoryId( repoId ); + stats.setDuration( duration ); + stats.setNewFileCount( newfiles ); + stats.setTotalFileCount( totalfiles ); + stats.setWhenGathered( toDate( timestamp ) ); + + return stats; + } +} |