diff options
author | Olivier Lamy <olamy@apache.org> | 2012-12-19 15:19:53 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-12-19 15:19:53 +0000 |
commit | 58afcb111487f09821d20ce25015352ee5140b65 (patch) | |
tree | f0cfeabeff964ca1b7cc6cdac092288c749e57c4 /archiva-modules/plugins | |
parent | 31438032029fe54269ae1b349d40f49d8c73c5d3 (diff) | |
download | archiva-58afcb111487f09821d20ce25015352ee5140b65.tar.gz archiva-58afcb111487f09821d20ce25015352ee5140b65.zip |
[MRM-1729] add MetadataRepository#hasMetadataFacet to prevent slow startup time.
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1423878 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/plugins')
5 files changed, 40 insertions, 1 deletions
diff --git a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java index a53a176f2..7bff556f6 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java @@ -400,6 +400,26 @@ public class JcrMetadataRepository } + + public boolean hasMetadataFacet( String repositoryId, String facetId ) + throws MetadataRepositoryException + { + try + { + Node node = getJcrSession().getRootNode().getNode( getFacetPath( repositoryId, facetId ) ); + return JcrUtils.getChildNodes( node ).iterator().hasNext(); + } + catch ( PathNotFoundException e ) + { + // ignored - the facet doesn't exist, so return false + return false; + } + catch ( RepositoryException e ) + { + throw new MetadataRepositoryException( e.getMessage(), e ); + } + } + public List<String> getMetadataFacets( String repositoryId, String facetId ) throws MetadataRepositoryException { diff --git a/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java index 1123eb30a..12c106ef5 100644 --- a/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java +++ b/archiva-modules/plugins/metadata-store-jcr/src/test/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepositoryTest.java @@ -24,6 +24,7 @@ import org.apache.archiva.metadata.repository.AbstractMetadataRepositoryTest; import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Before; +import org.junit.Test; import org.springframework.context.ApplicationContext; import java.io.File; @@ -48,7 +49,7 @@ public class JcrMetadataRepositoryTest super.setUp(); File directory = new File( "target/test-repositories" ); - if (directory.exists()) + if ( directory.exists() ) { FileUtils.deleteDirectory( directory ); } @@ -86,4 +87,6 @@ public class JcrMetadataRepositoryTest super.tearDown(); } + + } diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java index f75a53147..c0ed85a16 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java @@ -59,6 +59,12 @@ public class DefaultRepositoryStatisticsManager private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" ); + public boolean hasStatistics( MetadataRepository metadataRepository, String repositoryId ) + throws MetadataRepositoryException + { + return metadataRepository.hasMetadataFacet( repositoryId, RepositoryStatistics.FACET_ID ); + } + public RepositoryStatistics getLastStatistics( MetadataRepository metadataRepository, String repositoryId ) throws MetadataRepositoryException { diff --git a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java index a1e1a03ec..18332647a 100644 --- a/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java +++ b/archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/RepositoryStatisticsManager.java @@ -30,6 +30,9 @@ public interface RepositoryStatisticsManager RepositoryStatistics getLastStatistics( MetadataRepository metadataRepository, String repositoryId ) throws MetadataRepositoryException; + boolean hasStatistics( MetadataRepository metadataRepository, String repositoryId ) + throws MetadataRepositoryException; + void addStatisticsAfterScan( MetadataRepository metadataRepository, String repositoryId, Date startTime, Date endTime, long totalFiles, long newFiles ) throws MetadataRepositoryException; diff --git a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java index 189e2cf20..1a46b8727 100644 --- a/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java +++ b/archiva-modules/plugins/repository-statistics/src/test/java/org/apache/archiva/metadata/repository/stats/JcrRepositoryStatisticsGatheringTest.java @@ -21,10 +21,12 @@ package org.apache.archiva.metadata.repository.stats; import junit.framework.TestCase; import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.commons.JcrUtils; import org.apache.jackrabbit.core.TransientRepository; +import javax.inject.Inject; import javax.jcr.ImportUUIDBehavior; import javax.jcr.NamespaceRegistry; import javax.jcr.Node; @@ -39,6 +41,7 @@ import java.io.IOException; import java.util.Calendar; import java.util.Date; import java.util.zip.GZIPInputStream; + import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; import org.junit.After; import org.junit.Before; @@ -46,6 +49,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import static org.mockito.Mockito.*; + @RunWith( ArchivaBlockJUnit4ClassRunner.class ) public class JcrRepositoryStatisticsGatheringTest extends TestCase @@ -60,6 +64,9 @@ public class JcrRepositoryStatisticsGatheringTest private MetadataRepository metadataRepository; + @Inject + private RepositorySessionFactory repositorySessionFactory; + private Session session; @Override |