mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-21 15:02:17 +01:00
added close method to repository service
This commit is contained in:
@@ -43,6 +43,11 @@ import sonia.scm.repository.PreProcessorUtil;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.spi.RepositoryServiceProvider;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* From the {@link RepositoryService} it is possible to access all commands for
|
||||
* a single {@link Repository}. The {@link RepositoryService} is only access
|
||||
@@ -53,12 +58,17 @@ import sonia.scm.repository.spi.RepositoryServiceProvider;
|
||||
* the command is not supported the method will trow a
|
||||
* {@link CommandNotSupportedException}. It is possible to check if the command
|
||||
* is supported by the {@link RepositoryService} with the
|
||||
* {@link RepositoryService#isSupported(Command)} method.
|
||||
* {@link RepositoryService#isSupported(Command)} method.<br />
|
||||
* <br />
|
||||
*
|
||||
* <b>Warning:</b> You should always close the connection to the repository
|
||||
* after work is finished. For closing the connection to the repository use the
|
||||
* {@link #close()} method.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.17
|
||||
*/
|
||||
public final class RepositoryService
|
||||
public final class RepositoryService implements Closeable
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -88,6 +98,37 @@ public final class RepositoryService
|
||||
this.preProcessorUtil = preProcessorUtil;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Closes the connection to the repository and releases all locks
|
||||
* and resources. This method should be called in a finally block e.g.:
|
||||
*
|
||||
* <pre><code>
|
||||
* RepositoryService service = null;
|
||||
* try {
|
||||
* service = factory.create("repositoryId");
|
||||
* // do something with the service
|
||||
* } finally {
|
||||
* if ( service != null ){
|
||||
* service.close();
|
||||
* }
|
||||
* }
|
||||
* </code></pre>
|
||||
*/
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
try
|
||||
{
|
||||
provider.close();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error("cound not close repository service provider", ex);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,6 +40,9 @@ import sonia.scm.repository.api.CommandNotSupportedException;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -47,7 +50,7 @@ import java.util.Set;
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.17
|
||||
*/
|
||||
public abstract class RepositoryServiceProvider
|
||||
public abstract class RepositoryServiceProvider implements Closeable
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -58,6 +61,25 @@ public abstract class RepositoryServiceProvider
|
||||
*/
|
||||
public abstract Set<Command> getSupportedCommands();
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The default implementation of this method does nothing. If you need to
|
||||
* free resources, close connections or release locks than you have to
|
||||
* override this method.
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
|
||||
// should be implmentented from a service provider
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user