From 578d4c98587d0882f1b089d07840c37c66e4dee2 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 25 Feb 2012 20:45:46 +0000 Subject: [PATCH] correctlt close jcr session in case of exception git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1293682 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/RepositorySession.java | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySession.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySession.java index 64ff4077a..84ac9fdcd 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySession.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySession.java @@ -19,6 +19,9 @@ package org.apache.archiva.metadata.repository; * under the License. */ +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * The repository session provides a single interface to accessing Archiva repositories. It provides access to three * resources: @@ -40,6 +43,8 @@ public class RepositorySession private boolean dirty; + private Logger log = LoggerFactory.getLogger( getClass() ); + // FIXME: include storage here too - perhaps a factory based on repository ID, or one per type to retrieve and // operate on a given repo within the storage API @@ -60,32 +65,17 @@ public class RepositorySession } public void save() + throws MetadataRepositoryException { - try - { - repository.save(); - } - catch ( MetadataRepositoryException e ) - { - // FIXME - throw new RuntimeException( e ); - } + repository.save(); dirty = false; } public void revert() + throws MetadataRepositoryException { - try - { - repository.revert(); - } - catch ( MetadataRepositoryException e ) - { - // FIXME - throw new RuntimeException( e ); - } - + repository.revert(); dirty = false; } @@ -96,13 +86,24 @@ public class RepositorySession * exception occurs. */ public void close() + throws MetadataRepositoryException { - if ( dirty ) + try { - save(); + if ( dirty ) + { + save(); + } + } + catch ( MetadataRepositoryException e ) + { + // olamy use revert here ? + throw e; + } + finally + { + repository.close(); } - - repository.close(); } public void markDirty()