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
This commit is contained in:
Olivier Lamy 2012-02-25 20:45:46 +00:00
parent 31e5bf8148
commit 578d4c9858
1 changed files with 24 additions and 23 deletions

View File

@ -19,6 +19,9 @@ package org.apache.archiva.metadata.repository;
* under the License. * 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 * The repository session provides a single interface to accessing Archiva repositories. It provides access to three
* resources: * resources:
@ -40,6 +43,8 @@ public class RepositorySession
private boolean dirty; 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 // 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 // operate on a given repo within the storage API
@ -60,32 +65,17 @@ public class RepositorySession
} }
public void save() public void save()
{ throws MetadataRepositoryException
try
{ {
repository.save(); repository.save();
}
catch ( MetadataRepositoryException e )
{
// FIXME
throw new RuntimeException( e );
}
dirty = false; dirty = false;
} }
public void revert() public void revert()
{ throws MetadataRepositoryException
try
{ {
repository.revert(); repository.revert();
}
catch ( MetadataRepositoryException e )
{
// FIXME
throw new RuntimeException( e );
}
dirty = false; dirty = false;
} }
@ -96,14 +86,25 @@ public class RepositorySession
* exception occurs. * exception occurs.
*/ */
public void close() public void close()
throws MetadataRepositoryException
{
try
{ {
if ( dirty ) if ( dirty )
{ {
save(); save();
} }
}
catch ( MetadataRepositoryException e )
{
// olamy use revert here ?
throw e;
}
finally
{
repository.close(); repository.close();
} }
}
public void markDirty() public void markDirty()
{ {