aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-database/src
diff options
context:
space:
mode:
Diffstat (limited to 'archiva-database/src')
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/ArchivaDAO.java9
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentRepositoryScanStatistics.java54
-rw-r--r--archiva-database/src/main/java/org/apache/maven/archiva/database/jdo/JdoArchivaDAO.java18
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java57
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsProcessedConstraintTest.java8
-rw-r--r--archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/MostRecentRepositoryScanStatisticsTest.java86
6 files changed, 198 insertions, 34 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 d6675c6ed..bd64fb5da 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
@@ -19,6 +19,7 @@ package org.apache.maven.archiva.database;
* under the License.
*/
+import java.io.Serializable;
import java.util.List;
/**
@@ -39,6 +40,14 @@ public interface ArchivaDAO
*/
List query( SimpleConstraint constraint );
+ /**
+ * Perform a simple save of a peristable object to the database.
+ *
+ * @param o the serializable (persistable) object to save.
+ * @return the post-serialized object.
+ */
+ Object save( Serializable obj );
+
ArtifactDAO getArtifactDAO();
ProjectModelDAO getProjectModelDAO();
diff --git a/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentRepositoryScanStatistics.java b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentRepositoryScanStatistics.java
new file mode 100644
index 000000000..496f4f2af
--- /dev/null
+++ b/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/MostRecentRepositoryScanStatistics.java
@@ -0,0 +1,54 @@
+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.model.RepositoryContentStatistics;
+
+/**
+ * MostRecentRepositoryScanStatistics
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MostRecentRepositoryScanStatistics
+ extends AbstractSimpleConstraint
+{
+ private String sql;
+
+ public MostRecentRepositoryScanStatistics( String repoId )
+ {
+ sql = "SELECT FROM " + RepositoryContentStatistics.class.getName()
+ + " WHERE repositoryId == repoId PARAMETERS String repoId"
+ + " ORDER BY whenGathered DESCENDING"
+ + " RANGE 1,1";
+
+ super.params = new Object[] { repoId };
+ }
+
+ public Class getResultClass()
+ {
+ return RepositoryContentStatistics.class;
+ }
+
+ public String getSelectSql()
+ {
+ return sql;
+ }
+}
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 b1544de1d..7fbf79ad5 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
@@ -27,6 +27,7 @@ import org.apache.maven.archiva.database.RepositoryProblemDAO;
import org.apache.maven.archiva.database.SimpleConstraint;
import org.codehaus.plexus.logging.AbstractLogEnabled;
+import java.io.Serializable;
import java.util.List;
/**
@@ -45,37 +46,42 @@ public class JdoArchivaDAO
* @plexus.requirement role-hint="archiva"
*/
private JdoAccess jdo;
-
+
/**
* @plexus.requirement role-hint="jdo"
*/
private ArtifactDAO artifactDAO;
-
+
/**
* @plexus.requirement role-hint="jdo"
*/
private ProjectModelDAO projectModelDAO;
-
+
/**
* @plexus.requirement role-hint="jdo"
*/
private RepositoryDAO repositoryDAO;
-
+
/**
* @plexus.requirement role-hint="jdo"
*/
private RepositoryProblemDAO repositoryProblemDAO;
-
+
public List query( SimpleConstraint constraint )
{
return jdo.queryObjects( constraint );
}
+ public Object save( Serializable obj )
+ {
+ return jdo.saveObject( obj );
+ }
+
public ArtifactDAO getArtifactDAO()
{
return artifactDAO;
}
-
+
public ProjectModelDAO getProjectModelDAO()
{
return projectModelDAO;
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java
index f936bca5d..4deedfc9e 100644
--- a/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/AbstractArchivaDatabaseTestCase.java
@@ -26,6 +26,8 @@ import org.jpox.SchemaTool;
import java.io.File;
import java.net.URL;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
@@ -42,41 +44,43 @@ import javax.jdo.PersistenceManagerFactory;
public class AbstractArchivaDatabaseTestCase
extends PlexusTestCase
{
+ private static final String TIMESTAMP = "yyyy/MM/dd HH:mm:ss";
+
protected ArchivaDAO dao;
-
+
protected void setUp()
throws Exception
{
super.setUp();
-
+
DefaultConfigurableJdoFactory jdoFactory = (DefaultConfigurableJdoFactory) lookup( JdoFactory.ROLE, "archiva" );
assertEquals( DefaultConfigurableJdoFactory.class.getName(), jdoFactory.getClass().getName() );
- jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
+ jdoFactory.setPersistenceManagerFactoryClass( "org.jpox.PersistenceManagerFactoryImpl" );
/* derby version
- File derbyDbDir = new File( "target/plexus-home/testdb" );
- if ( derbyDbDir.exists() )
- {
- FileUtils.deleteDirectory( derbyDbDir );
- }
+ File derbyDbDir = new File( "target/plexus-home/testdb" );
+ if ( derbyDbDir.exists() )
+ {
+ FileUtils.deleteDirectory( derbyDbDir );
+ }
- jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.apache.derby.jdbc.EmbeddedDriver" ) );
- jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:derby:" + derbyDbDir.getAbsolutePath() + ";create=true" ) );
- */
+ jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.apache.derby.jdbc.EmbeddedDriver" ) );
+ jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:derby:" + derbyDbDir.getAbsolutePath() + ";create=true" ) );
+ */
- jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.hsqldb.jdbcDriver" ) );
+ jdoFactory.setDriverName( System.getProperty( "jdo.test.driver", "org.hsqldb.jdbcDriver" ) );
jdoFactory.setUrl( System.getProperty( "jdo.test.url", "jdbc:hsqldb:mem:" + getName() ) );
-
- jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) );
- jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) );
+ jdoFactory.setUserName( System.getProperty( "jdo.test.user", "sa" ) );
+
+ jdoFactory.setPassword( System.getProperty( "jdo.test.pass", "" ) );
- jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
+ jdoFactory.setProperty( "org.jpox.transactionIsolation", "READ_COMMITTED" );
- jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" );
+ jdoFactory.setProperty( "org.jpox.poid.transactionIsolation", "READ_COMMITTED" );
- jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" );
+ jdoFactory.setProperty( "org.jpox.autoCreateSchema", "true" );
jdoFactory.setProperty( "javax.jdo.option.RetainValues", "true" );
@@ -99,8 +103,7 @@ public class AbstractArchivaDatabaseTestCase
System.setProperty( (String) entry.getKey(), (String) entry.getValue() );
}
- URL jdoFileUrls[] = new URL[] { getClass()
- .getResource( "/org/apache/maven/archiva/model/package.jdo" ) };
+ URL jdoFileUrls[] = new URL[] { getClass().getResource( "/org/apache/maven/archiva/model/package.jdo" ) };
if ( ( jdoFileUrls == null ) || ( jdoFileUrls[0] == null ) )
{
@@ -123,4 +126,18 @@ public class AbstractArchivaDatabaseTestCase
this.dao = (ArchivaDAO) lookup( ArchivaDAO.class.getName(), "jdo" );
}
+
+ protected Date toDate( String txt )
+ throws Exception
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat( TIMESTAMP );
+ return sdf.parse( txt );
+ }
+
+ protected String fromDate( Date date )
+ throws Exception
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat( TIMESTAMP );
+ return sdf.format( date );
+ }
}
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsProcessedConstraintTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsProcessedConstraintTest.java
index 603fdca90..a76d9689b 100644
--- a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsProcessedConstraintTest.java
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactsProcessedConstraintTest.java
@@ -23,7 +23,6 @@ import org.apache.maven.archiva.database.AbstractArchivaDatabaseTestCase;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.model.ArchivaArtifact;
-import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
@@ -57,13 +56,6 @@ public class ArtifactsProcessedConstraintTest
return artifact;
}
- private Date toDate( String txt )
- throws Exception
- {
- SimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd HH:mm:ss" );
- return sdf.parse( txt );
- }
-
public void assertResults( String type, List results, String expectedArtifacts[] )
{
assertNotNull( "Results[" + type + "] should not be null.", results );
diff --git a/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/MostRecentRepositoryScanStatisticsTest.java b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/MostRecentRepositoryScanStatisticsTest.java
new file mode 100644
index 000000000..3ef84e8d2
--- /dev/null
+++ b/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/MostRecentRepositoryScanStatisticsTest.java
@@ -0,0 +1,86 @@
+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.model.RepositoryContentStatistics;
+
+import java.util.List;
+
+/**
+ * MostRecentRepositoryScanStatisticsTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MostRecentRepositoryScanStatisticsTest
+ 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.save( createStats( "internal", "2007/02/21 10:00:00", 20000, 12000, 400 ) );
+ dao.save( createStats( "internal", "2007/02/20 10:00:00", 20000, 11800, 0 ) );
+ dao.save( createStats( "internal", "2007/02/19 10:00:00", 20000, 11800, 100 ) );
+ dao.save( createStats( "internal", "2007/02/18 10:00:00", 20000, 11700, 320 ) );
+ }
+
+ public void testNotProcessedYet()
+ throws Exception
+ {
+ List results = dao.query( new MostRecentRepositoryScanStatistics( "central" ) );
+ assertNotNull( "Not Processed Yet", results );
+ assertTrue( "Not Processed Yet", results.isEmpty() );
+ }
+
+ public void testStats()
+ throws Exception
+ {
+ List results = dao.query( new MostRecentRepositoryScanStatistics( "internal" ) );
+ assertNotNull( "Stats: results (not null)", results );
+ assertEquals( "Stats: results.size", 1, results.size() );
+
+ Object o = results.get( 0 );
+ assertTrue( "Stats: result[0] instanceof RepositoryScanStatistics", o instanceof RepositoryContentStatistics );
+ RepositoryContentStatistics stats = (RepositoryContentStatistics) o;
+ assertEquals( "Stats: id", "internal", stats.getRepositoryId() );
+ assertEquals( "Stats: when gathered", "2007/02/21 10:00:00", fromDate( stats.getWhenGathered() ) );
+ assertEquals( "Stats: duration", 20000, stats.getDuration() );
+ assertEquals( "Stats: total file count", 12000, stats.getTotalFileCount() );
+ assertEquals( "Stats: new file count", 400, stats.getNewFileCount() );
+ }
+
+}