From 58afcb111487f09821d20ce25015352ee5140b65 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 19 Dec 2012 15:19:53 +0000 Subject: [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 --- .../repository/jcr/JcrMetadataRepository.java | 20 ++++++++++++++++++++ .../repository/jcr/JcrMetadataRepositoryTest.java | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'archiva-modules/plugins/metadata-store-jcr/src') 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 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(); } + + } -- cgit v1.2.3