close repository service after usage

This commit is contained in:
Sebastian Sdorra
2012-06-23 13:58:18 +02:00
parent 3205780f07
commit ef00ad320b

View File

@@ -36,6 +36,7 @@ package sonia.scm.api.rest.resources;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.io.Closeables;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@@ -347,12 +348,13 @@ public class RepositoryResource
throws RepositoryException, IOException throws RepositoryException, IOException
{ {
Response response = null; Response response = null;
RepositoryService service = null;
try try
{ {
AssertUtil.assertIsNotNull(path); AssertUtil.assertIsNotNull(path);
service = servicefactory.create(id);
RepositoryService service = servicefactory.create(id);
BlameCommandBuilder builder = service.getBlameCommand(); BlameCommandBuilder builder = service.getBlameCommand();
if (!Strings.isNullOrEmpty(revision)) if (!Strings.isNullOrEmpty(revision))
@@ -383,6 +385,10 @@ public class RepositoryResource
{ {
response = Response.status(Response.Status.BAD_REQUEST).build(); response = Response.status(Response.Status.BAD_REQUEST).build();
} }
finally
{
Closeables.closeQuietly(service);
}
return response; return response;
} }
@@ -418,10 +424,12 @@ public class RepositoryResource
throws RepositoryException, IOException throws RepositoryException, IOException
{ {
Response response = null; Response response = null;
RepositoryService service = null;
try try
{ {
RepositoryService service = servicefactory.create(id); service = servicefactory.create(id);
BrowseCommandBuilder builder = service.getBrowseCommand(); BrowseCommandBuilder builder = service.getBrowseCommand();
if (!Strings.isNullOrEmpty(revision)) if (!Strings.isNullOrEmpty(revision))
@@ -453,6 +461,10 @@ public class RepositoryResource
{ {
response = Response.status(Response.Status.BAD_REQUEST).build(); response = Response.status(Response.Status.BAD_REQUEST).build();
} }
finally
{
Closeables.closeQuietly(service);
}
return response; return response;
} }
@@ -528,9 +540,12 @@ public class RepositoryResource
if (Util.isNotEmpty(id) && Util.isNotEmpty(revision)) if (Util.isNotEmpty(id) && Util.isNotEmpty(revision))
{ {
RepositoryService service = null;
try try
{ {
RepositoryService service = servicefactory.create(id); service = servicefactory.create(id);
Changeset changeset = service.getLogCommand().getChangeset(revision); Changeset changeset = service.getLogCommand().getChangeset(revision);
if (changeset != null) if (changeset != null)
@@ -550,6 +565,10 @@ public class RepositoryResource
{ {
response = Response.status(Response.Status.BAD_REQUEST).build(); response = Response.status(Response.Status.BAD_REQUEST).build();
} }
finally
{
Closeables.closeQuietly(service);
}
} }
else else
{ {
@@ -599,11 +618,14 @@ public class RepositoryResource
@QueryParam("limit") int limit) throws RepositoryException, IOException @QueryParam("limit") int limit) throws RepositoryException, IOException
{ {
Response response = null; Response response = null;
RepositoryService service = null;
try try
{ {
ChangesetPagingResult changesets = null; ChangesetPagingResult changesets = null;
RepositoryService service = servicefactory.create(id);
service = servicefactory.create(id);
LogCommandBuilder builder = service.getLogCommand(); LogCommandBuilder builder = service.getLogCommand();
if (!Strings.isNullOrEmpty(path)) if (!Strings.isNullOrEmpty(path))
@@ -636,6 +658,10 @@ public class RepositoryResource
{ {
response = Response.status(Response.Status.BAD_REQUEST).build(); response = Response.status(Response.Status.BAD_REQUEST).build();
} }
finally
{
Closeables.closeQuietly(service);
}
return response; return response;
} }
@@ -668,10 +694,12 @@ public class RepositoryResource
{ {
Response response = null; Response response = null;
StreamingOutput output = null; StreamingOutput output = null;
RepositoryService service = null;
try try
{ {
RepositoryService service = servicefactory.create(id); service = servicefactory.create(id);
CatCommandBuilder builder = service.getCatCommand(); CatCommandBuilder builder = service.getCatCommand();
if (!Strings.isNullOrEmpty(revision)) if (!Strings.isNullOrEmpty(revision))
@@ -700,6 +728,10 @@ public class RepositoryResource
logger.error("could not retrive content", ex); logger.error("could not retrive content", ex);
response = createErrorResonse(ex); response = createErrorResonse(ex);
} }
finally
{
Closeables.closeQuietly(service);
}
return response; return response;
} }
@@ -737,11 +769,13 @@ public class RepositoryResource
AssertUtil.assertIsNotEmpty(id); AssertUtil.assertIsNotEmpty(id);
AssertUtil.assertIsNotEmpty(revision); AssertUtil.assertIsNotEmpty(revision);
RepositoryService service = null;
Response response = null; Response response = null;
try try
{ {
RepositoryService service = servicefactory.create(id); service = servicefactory.create(id);
DiffCommandBuilder builder = service.getDiffCommand(); DiffCommandBuilder builder = service.getDiffCommand();
if (!Strings.isNullOrEmpty(revision)) if (!Strings.isNullOrEmpty(revision))
@@ -774,6 +808,10 @@ public class RepositoryResource
logger.error("could not create diff", ex); logger.error("could not create diff", ex);
response = createErrorResonse(ex); response = createErrorResonse(ex);
} }
finally
{
Closeables.closeQuietly(service);
}
return response; return response;
} }