aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Persistence/SqliteFileOrganizationRepository.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-01-22 12:05:06 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-01-22 12:05:06 -0500
commit9d40b684bf6af4e987e226c78c11d6daf6f5cd9b (patch)
tree937312aa29772d0e042929798e936710fbc7c74c /MediaBrowser.Server.Implementations/Persistence/SqliteFileOrganizationRepository.cs
parentcf1dac60f632646fa6ccdc715eee9fa5cf240bf3 (diff)
#680 - episode organization
Diffstat (limited to 'MediaBrowser.Server.Implementations/Persistence/SqliteFileOrganizationRepository.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Persistence/SqliteFileOrganizationRepository.cs53
1 files changed, 52 insertions, 1 deletions
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteFileOrganizationRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteFileOrganizationRepository.cs
index e20139e08..4463ac6f3 100644
--- a/MediaBrowser.Server.Implementations/Persistence/SqliteFileOrganizationRepository.cs
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteFileOrganizationRepository.cs
@@ -27,6 +27,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
private IDbCommand _saveResultCommand;
private IDbCommand _deleteResultCommand;
+ private IDbCommand _deleteAllCommand;
public SqliteFileOrganizationRepository(ILogManager logManager, IServerApplicationPaths appPaths)
{
@@ -85,6 +86,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
_deleteResultCommand.CommandText = "delete from organizationresults where ResultId = @ResultId";
_deleteResultCommand.Parameters.Add(_saveResultCommand, "@ResultId");
+
+ _deleteAllCommand = _connection.CreateCommand();
+ _deleteAllCommand.CommandText = "delete from organizationresults";
}
public async Task SaveResult(FileOrganizationResult result, CancellationToken cancellationToken)
@@ -188,7 +192,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
catch (Exception e)
{
- _logger.ErrorException("Failed to save FileOrganizationResult:", e);
+ _logger.ErrorException("Failed to delete FileOrganizationResult:", e);
if (transaction != null)
{
@@ -208,6 +212,53 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
}
+ public async Task DeleteAll()
+ {
+ await _writeLock.WaitAsync().ConfigureAwait(false);
+
+ IDbTransaction transaction = null;
+
+ try
+ {
+ transaction = _connection.BeginTransaction();
+
+ _deleteAllCommand.Transaction = transaction;
+
+ _deleteAllCommand.ExecuteNonQuery();
+
+ transaction.Commit();
+ }
+ catch (OperationCanceledException)
+ {
+ if (transaction != null)
+ {
+ transaction.Rollback();
+ }
+
+ throw;
+ }
+ catch (Exception e)
+ {
+ _logger.ErrorException("Failed to delete results", e);
+
+ if (transaction != null)
+ {
+ transaction.Rollback();
+ }
+
+ throw;
+ }
+ finally
+ {
+ if (transaction != null)
+ {
+ transaction.Dispose();
+ }
+
+ _writeLock.Release();
+ }
+ }
+
public QueryResult<FileOrganizationResult> GetResults(FileOrganizationResultQuery query)
{
if (query == null)