소스 검색

update db inheritance

Luke Pulverenti 9 년 전
부모
커밋
0216742945

+ 15 - 45
MediaBrowser.Server.Implementations/Activity/ActivityRepository.cs

@@ -14,19 +14,17 @@ using System.Threading.Tasks;
 
 
 namespace MediaBrowser.Server.Implementations.Activity
 namespace MediaBrowser.Server.Implementations.Activity
 {
 {
-    public class ActivityRepository : IActivityRepository, IDisposable
+    public class ActivityRepository : BaseSqliteRepository, IActivityRepository
     {
     {
         private IDbConnection _connection;
         private IDbConnection _connection;
-        private readonly ILogger _logger;
-        private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1);
         private readonly IServerApplicationPaths _appPaths;
         private readonly IServerApplicationPaths _appPaths;
         private readonly CultureInfo _usCulture = new CultureInfo("en-US");
         private readonly CultureInfo _usCulture = new CultureInfo("en-US");
 
 
         private IDbCommand _saveActivityCommand;
         private IDbCommand _saveActivityCommand;
 
 
-        public ActivityRepository(ILogger logger, IServerApplicationPaths appPaths)
+        public ActivityRepository(ILogManager logManager, IServerApplicationPaths appPaths)
+            : base(logManager)
         {
         {
-            _logger = logger;
             _appPaths = appPaths;
             _appPaths = appPaths;
         }
         }
 
 
@@ -34,7 +32,7 @@ namespace MediaBrowser.Server.Implementations.Activity
         {
         {
             var dbFile = Path.Combine(_appPaths.DataPath, "activitylog.db");
             var dbFile = Path.Combine(_appPaths.DataPath, "activitylog.db");
 
 
-            _connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false);
+            _connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false);
 
 
             string[] queries = {
             string[] queries = {
 
 
@@ -47,7 +45,7 @@ namespace MediaBrowser.Server.Implementations.Activity
                                 "pragma shrink_memory"
                                 "pragma shrink_memory"
                                };
                                };
 
 
-            _connection.RunQueries(queries, _logger);
+            _connection.RunQueries(queries, Logger);
 
 
             PrepareStatements();
             PrepareStatements();
         }
         }
@@ -82,7 +80,7 @@ namespace MediaBrowser.Server.Implementations.Activity
                 throw new ArgumentNullException("entry");
                 throw new ArgumentNullException("entry");
             }
             }
 
 
-            await _writeLock.WaitAsync().ConfigureAwait(false);
+            await WriteLock.WaitAsync().ConfigureAwait(false);
 
 
             IDbTransaction transaction = null;
             IDbTransaction transaction = null;
 
 
@@ -119,7 +117,7 @@ namespace MediaBrowser.Server.Implementations.Activity
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
-                _logger.ErrorException("Failed to save record:", e);
+                Logger.ErrorException("Failed to save record:", e);
 
 
                 if (transaction != null)
                 if (transaction != null)
                 {
                 {
@@ -135,7 +133,7 @@ namespace MediaBrowser.Server.Implementations.Activity
                     transaction.Dispose();
                     transaction.Dispose();
                 }
                 }
 
 
-                _writeLock.Release();
+                WriteLock.Release();
             }
             }
         }
         }
 
 
@@ -264,45 +262,17 @@ namespace MediaBrowser.Server.Implementations.Activity
             return info;
             return info;
         }
         }
 
 
-        /// <summary>
-        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
-        /// </summary>
-        public void Dispose()
+        protected override void CloseConnection()
         {
         {
-            Dispose(true);
-            GC.SuppressFinalize(this);
-        }
-
-        private readonly object _disposeLock = new object();
-
-        /// <summary>
-        /// Releases unmanaged and - optionally - managed resources.
-        /// </summary>
-        /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
-        protected virtual void Dispose(bool dispose)
-        {
-            if (dispose)
+            if (_connection != null)
             {
             {
-                try
+                if (_connection.IsOpen())
                 {
                 {
-                    lock (_disposeLock)
-                    {
-                        if (_connection != null)
-                        {
-                            if (_connection.IsOpen())
-                            {
-                                _connection.Close();
-                            }
-
-                            _connection.Dispose();
-                            _connection = null;
-                        }
-                    }
-                }
-                catch (Exception ex)
-                {
-                    _logger.ErrorException("Error disposing database", ex);
+                    _connection.Close();
                 }
                 }
+
+                _connection.Dispose();
+                _connection = null;
             }
             }
         }
         }
     }
     }

+ 38 - 0
MediaBrowser.Server.Implementations/Persistence/BaseSqliteRepository.cs

@@ -1,6 +1,8 @@
 using MediaBrowser.Model.Logging;
 using MediaBrowser.Model.Logging;
 using System;
 using System;
+using System.Data;
 using System.Threading;
 using System.Threading;
+using System.Threading.Tasks;
 
 
 namespace MediaBrowser.Server.Implementations.Persistence
 namespace MediaBrowser.Server.Implementations.Persistence
 {
 {
@@ -14,12 +16,48 @@ namespace MediaBrowser.Server.Implementations.Persistence
             Logger = logManager.GetLogger(GetType().Name);
             Logger = logManager.GetLogger(GetType().Name);
         }
         }
 
 
+        private bool _disposed;
+        protected void CheckDisposed()
+        {
+            if (_disposed)
+            {
+                throw new ObjectDisposedException(GetType().Name + " has been disposed and cannot be accessed.");
+            }
+        }
+
         public void Dispose()
         public void Dispose()
         {
         {
+            _disposed = true;
             Dispose(true);
             Dispose(true);
             GC.SuppressFinalize(this);
             GC.SuppressFinalize(this);
         }
         }
 
 
+        protected async Task Vacuum(IDbConnection connection)
+        {
+            CheckDisposed();
+
+            await WriteLock.WaitAsync().ConfigureAwait(false);
+
+            try
+            {
+                using (var cmd = connection.CreateCommand())
+                {
+                    cmd.CommandText = "vacuum";
+                    cmd.ExecuteNonQuery();
+                }
+            }
+            catch (Exception e)
+            {
+                Logger.ErrorException("Failed to vacuum:", e);
+
+                throw;
+            }
+            finally
+            {
+                WriteLock.Release();
+            }
+        }
+
         private readonly object _disposeLock = new object();
         private readonly object _disposeLock = new object();
 
 
         /// <summary>
         /// <summary>

+ 109 - 158
MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs

@@ -26,12 +26,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
     /// <summary>
     /// <summary>
     /// Class SQLiteItemRepository
     /// Class SQLiteItemRepository
     /// </summary>
     /// </summary>
-    public class SqliteItemRepository : IItemRepository
+    public class SqliteItemRepository : BaseSqliteRepository, IItemRepository
     {
     {
         private IDbConnection _connection;
         private IDbConnection _connection;
 
 
-        private readonly ILogger _logger;
-
         private readonly TypeMapper _typeMapper = new TypeMapper();
         private readonly TypeMapper _typeMapper = new TypeMapper();
 
 
         /// <summary>
         /// <summary>
@@ -96,6 +94,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
         /// jsonSerializer
         /// jsonSerializer
         /// </exception>
         /// </exception>
         public SqliteItemRepository(IApplicationPaths appPaths, IJsonSerializer jsonSerializer, ILogManager logManager)
         public SqliteItemRepository(IApplicationPaths appPaths, IJsonSerializer jsonSerializer, ILogManager logManager)
+            : base(logManager)
         {
         {
             if (appPaths == null)
             if (appPaths == null)
             {
             {
@@ -110,8 +109,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
             _jsonSerializer = jsonSerializer;
             _jsonSerializer = jsonSerializer;
 
 
             _criticReviewsPath = Path.Combine(_appPaths.DataPath, "critic-reviews");
             _criticReviewsPath = Path.Combine(_appPaths.DataPath, "critic-reviews");
-
-            _logger = logManager.GetLogger(GetType().Name);
         }
         }
 
 
         private const string ChaptersTableName = "Chapters2";
         private const string ChaptersTableName = "Chapters2";
@@ -124,7 +121,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
         {
         {
             var dbFile = Path.Combine(_appPaths.DataPath, "library.db");
             var dbFile = Path.Combine(_appPaths.DataPath, "library.db");
 
 
-            _connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false);
+            _connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false);
 
 
             var createMediaStreamsTableCommand
             var createMediaStreamsTableCommand
                = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, IsCabac BIT NULL, CodecTag TEXT NULL, Comment TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))";
                = "create table if not exists mediastreams (ItemId GUID, StreamIndex INT, StreamType TEXT, Codec TEXT, Language TEXT, ChannelLayout TEXT, Profile TEXT, AspectRatio TEXT, Path TEXT, IsInterlaced BIT, BitRate INT NULL, Channels INT NULL, SampleRate INT NULL, IsDefault BIT, IsForced BIT, IsExternal BIT, Height INT NULL, Width INT NULL, AverageFrameRate FLOAT NULL, RealFrameRate FLOAT NULL, Level FLOAT NULL, PixelFormat TEXT, BitDepth INT NULL, IsAnamorphic BIT NULL, RefFrames INT NULL, IsCabac BIT NULL, CodecTag TEXT NULL, Comment TEXT NULL, PRIMARY KEY (ItemId, StreamIndex))";
@@ -158,76 +155,76 @@ namespace MediaBrowser.Server.Implementations.Persistence
                                 "pragma shrink_memory"
                                 "pragma shrink_memory"
                                };
                                };
 
 
-            _connection.RunQueries(queries, _logger);
+            _connection.RunQueries(queries, Logger);
 
 
-            _connection.AddColumn(_logger, "AncestorIds", "AncestorIdText", "Text");
+            _connection.AddColumn(Logger, "AncestorIds", "AncestorIdText", "Text");
             
             
-            _connection.AddColumn(_logger, "TypedBaseItems", "Path", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "StartDate", "DATETIME");
-            _connection.AddColumn(_logger, "TypedBaseItems", "EndDate", "DATETIME");
-            _connection.AddColumn(_logger, "TypedBaseItems", "ChannelId", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsMovie", "BIT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsSports", "BIT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsKids", "BIT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "CommunityRating", "Float");
-            _connection.AddColumn(_logger, "TypedBaseItems", "CustomRating", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IndexNumber", "INT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsLocked", "BIT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "Name", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "OfficialRating", "Text");
-
-            _connection.AddColumn(_logger, "TypedBaseItems", "MediaType", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "Overview", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "ParentIndexNumber", "INT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "PremiereDate", "DATETIME");
-            _connection.AddColumn(_logger, "TypedBaseItems", "ProductionYear", "INT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "ParentId", "GUID");
-            _connection.AddColumn(_logger, "TypedBaseItems", "Genres", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "ParentalRatingValue", "INT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "SchemaVersion", "INT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "SortName", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "RunTimeTicks", "BIGINT");
-
-            _connection.AddColumn(_logger, "TypedBaseItems", "OfficialRatingDescription", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "HomePageUrl", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "VoteCount", "INT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "DisplayMediaType", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "DateCreated", "DATETIME");
-            _connection.AddColumn(_logger, "TypedBaseItems", "DateModified", "DATETIME");
-
-            _connection.AddColumn(_logger, "TypedBaseItems", "ForcedSortName", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsOffline", "BIT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "LocationType", "Text");
-
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsSeries", "BIT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsLive", "BIT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsNews", "BIT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsPremiere", "BIT");
-
-            _connection.AddColumn(_logger, "TypedBaseItems", "EpisodeTitle", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsRepeat", "BIT");
-
-            _connection.AddColumn(_logger, "TypedBaseItems", "PreferredMetadataLanguage", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "PreferredMetadataCountryCode", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsHD", "BIT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "ExternalEtag", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "DateLastRefreshed", "DATETIME");
-
-            _connection.AddColumn(_logger, "TypedBaseItems", "DateLastSaved", "DATETIME");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsInMixedFolder", "BIT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "LockedFields", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "Studios", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "Audio", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "ExternalServiceId", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "Tags", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "IsFolder", "BIT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "InheritedParentalRatingValue", "INT");
-            _connection.AddColumn(_logger, "TypedBaseItems", "UnratedType", "Text");
-            _connection.AddColumn(_logger, "TypedBaseItems", "TopParentId", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "Path", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "StartDate", "DATETIME");
+            _connection.AddColumn(Logger, "TypedBaseItems", "EndDate", "DATETIME");
+            _connection.AddColumn(Logger, "TypedBaseItems", "ChannelId", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsMovie", "BIT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsSports", "BIT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsKids", "BIT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "CommunityRating", "Float");
+            _connection.AddColumn(Logger, "TypedBaseItems", "CustomRating", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IndexNumber", "INT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsLocked", "BIT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "Name", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "OfficialRating", "Text");
+
+            _connection.AddColumn(Logger, "TypedBaseItems", "MediaType", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "Overview", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "ParentIndexNumber", "INT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "PremiereDate", "DATETIME");
+            _connection.AddColumn(Logger, "TypedBaseItems", "ProductionYear", "INT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "ParentId", "GUID");
+            _connection.AddColumn(Logger, "TypedBaseItems", "Genres", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "ParentalRatingValue", "INT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "SchemaVersion", "INT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "SortName", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "RunTimeTicks", "BIGINT");
+
+            _connection.AddColumn(Logger, "TypedBaseItems", "OfficialRatingDescription", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "HomePageUrl", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "VoteCount", "INT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "DisplayMediaType", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "DateCreated", "DATETIME");
+            _connection.AddColumn(Logger, "TypedBaseItems", "DateModified", "DATETIME");
+
+            _connection.AddColumn(Logger, "TypedBaseItems", "ForcedSortName", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsOffline", "BIT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "LocationType", "Text");
+
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsSeries", "BIT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsLive", "BIT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsNews", "BIT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsPremiere", "BIT");
+
+            _connection.AddColumn(Logger, "TypedBaseItems", "EpisodeTitle", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsRepeat", "BIT");
+
+            _connection.AddColumn(Logger, "TypedBaseItems", "PreferredMetadataLanguage", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "PreferredMetadataCountryCode", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsHD", "BIT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "ExternalEtag", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "DateLastRefreshed", "DATETIME");
+
+            _connection.AddColumn(Logger, "TypedBaseItems", "DateLastSaved", "DATETIME");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsInMixedFolder", "BIT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "LockedFields", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "Studios", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "Audio", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "ExternalServiceId", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "Tags", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "IsFolder", "BIT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "InheritedParentalRatingValue", "INT");
+            _connection.AddColumn(Logger, "TypedBaseItems", "UnratedType", "Text");
+            _connection.AddColumn(Logger, "TypedBaseItems", "TopParentId", "Text");
 
 
             PrepareStatements();
             PrepareStatements();
 
 
-            new MediaStreamColumns(_connection, _logger).AddColumns();
+            new MediaStreamColumns(_connection, Logger).AddColumns();
 
 
             var chapterDbFile = Path.Combine(_appPaths.DataPath, "chapters.db");
             var chapterDbFile = Path.Combine(_appPaths.DataPath, "chapters.db");
             if (File.Exists(chapterDbFile))
             if (File.Exists(chapterDbFile))
@@ -256,11 +253,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
                                 "REPLACE INTO mediastreams("+columns+") SELECT "+columns+" FROM MediaInfoOld.mediastreams;"
                                 "REPLACE INTO mediastreams("+columns+") SELECT "+columns+" FROM MediaInfoOld.mediastreams;"
                                };
                                };
 
 
-                _connection.RunQueries(queries, _logger);
+                _connection.RunQueries(queries, Logger);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
-                _logger.ErrorException("Error migrating media info database", ex);
+                Logger.ErrorException("Error migrating media info database", ex);
             }
             }
             finally
             finally
             {
             {
@@ -280,11 +277,11 @@ namespace MediaBrowser.Server.Implementations.Persistence
                                 "REPLACE INTO "+ChaptersTableName+"(ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath) SELECT ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath FROM ChaptersOld.Chapters;"
                                 "REPLACE INTO "+ChaptersTableName+"(ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath) SELECT ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath FROM ChaptersOld.Chapters;"
                                };
                                };
 
 
-                _connection.RunQueries(queries, _logger);
+                _connection.RunQueries(queries, Logger);
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
-                _logger.ErrorException("Error migrating chapter database", ex);
+                Logger.ErrorException("Error migrating chapter database", ex);
             }
             }
             finally
             finally
             {
             {
@@ -300,15 +297,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
-                _logger.ErrorException("Error deleting file {0}", ex, file);
+                Logger.ErrorException("Error deleting file {0}", ex, file);
             }
             }
         }
         }
 
 
-        /// <summary>
-        /// The _write lock
-        /// </summary>
-        private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1);
-
         private readonly string[] _retriveItemColumns =
         private readonly string[] _retriveItemColumns =
         {
         {
             "type",
             "type",
@@ -583,7 +575,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
 
 
             CheckDisposed();
             CheckDisposed();
 
 
-            await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
+            await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
 
 
             IDbTransaction transaction = null;
             IDbTransaction transaction = null;
 
 
@@ -761,7 +753,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
-                _logger.ErrorException("Failed to save items:", e);
+                Logger.ErrorException("Failed to save items:", e);
 
 
                 if (transaction != null)
                 if (transaction != null)
                 {
                 {
@@ -777,7 +769,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
                     transaction.Dispose();
                     transaction.Dispose();
                 }
                 }
 
 
-                _writeLock.Release();
+                WriteLock.Release();
             }
             }
         }
         }
 
 
@@ -821,7 +813,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
 
 
             if (type == null)
             if (type == null)
             {
             {
-                _logger.Debug("Unknown type {0}", typeString);
+                Logger.Debug("Unknown type {0}", typeString);
 
 
                 return null;
                 return null;
             }
             }
@@ -836,7 +828,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
                 }
                 }
                 catch (SerializationException ex)
                 catch (SerializationException ex)
                 {
                 {
-                    _logger.ErrorException("Error deserializing item", ex);
+                    Logger.ErrorException("Error deserializing item", ex);
                 }
                 }
 
 
                 if (item == null)
                 if (item == null)
@@ -1237,7 +1229,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
 
 
             cancellationToken.ThrowIfCancellationRequested();
             cancellationToken.ThrowIfCancellationRequested();
 
 
-            await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
+            await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
 
 
             IDbTransaction transaction = null;
             IDbTransaction transaction = null;
 
 
@@ -1284,7 +1276,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
-                _logger.ErrorException("Failed to save chapters:", e);
+                Logger.ErrorException("Failed to save chapters:", e);
 
 
                 if (transaction != null)
                 if (transaction != null)
                 {
                 {
@@ -1300,62 +1292,21 @@ namespace MediaBrowser.Server.Implementations.Persistence
                     transaction.Dispose();
                     transaction.Dispose();
                 }
                 }
 
 
-                _writeLock.Release();
+                WriteLock.Release();
             }
             }
         }
         }
 
 
-        /// <summary>
-        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
-        /// </summary>
-        public void Dispose()
+        protected override void CloseConnection()
         {
         {
-            Dispose(true);
-            GC.SuppressFinalize(this);
-        }
-
-        private readonly object _disposeLock = new object();
-
-        private bool _disposed;
-        private void CheckDisposed()
-        {
-            if (_disposed)
+            if (_connection != null)
             {
             {
-                throw new ObjectDisposedException(GetType().Name + " has been disposed and cannot be accessed.");
-            }
-        }
-
-        /// <summary>
-        /// Releases unmanaged and - optionally - managed resources.
-        /// </summary>
-        /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
-        protected virtual void Dispose(bool dispose)
-        {
-            if (dispose)
-            {
-                _disposed = true;
-
-                try
-                {
-                    lock (_disposeLock)
-                    {
-                        _writeLock.Wait();
-
-                        if (_connection != null)
-                        {
-                            if (_connection.IsOpen())
-                            {
-                                _connection.Close();
-                            }
-
-                            _connection.Dispose();
-                            _connection = null;
-                        }
-                    }
-                }
-                catch (Exception ex)
+                if (_connection.IsOpen())
                 {
                 {
-                    _logger.ErrorException("Error disposing database", ex);
+                    _connection.Close();
                 }
                 }
+
+                _connection.Dispose();
+                _connection = null;
             }
             }
         }
         }
 
 
@@ -1399,7 +1350,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
 
 
                 cmd.Parameters.Add(cmd, "@ParentId", DbType.Guid).Value = parentId;
                 cmd.Parameters.Add(cmd, "@ParentId", DbType.Guid).Value = parentId;
 
 
-                //_logger.Debug(cmd.CommandText);
+                //Logger.Debug(cmd.CommandText);
 
 
                 using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
                 using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
                 {
                 {
@@ -1474,7 +1425,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
                     cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture);
                     cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture);
                 }
                 }
 
 
-                //_logger.Debug(cmd.CommandText);
+                //Logger.Debug(cmd.CommandText);
 
 
                 using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
                 using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
                 {
                 {
@@ -1526,7 +1477,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
 
 
                 cmd.CommandText += "; select count (guid) from TypedBaseItems" + whereTextWithoutPaging;
                 cmd.CommandText += "; select count (guid) from TypedBaseItems" + whereTextWithoutPaging;
 
 
-                _logger.Debug(cmd.CommandText);
+                Logger.Debug(cmd.CommandText);
 
 
                 var list = new List<BaseItem>();
                 var list = new List<BaseItem>();
                 var count = 0;
                 var count = 0;
@@ -1609,7 +1560,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
 
 
                 var list = new List<Guid>();
                 var list = new List<Guid>();
 
 
-                _logger.Debug(cmd.CommandText);
+                Logger.Debug(cmd.CommandText);
 
 
                 using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
                 using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
                 {
                 {
@@ -1662,7 +1613,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
                 var list = new List<Tuple<Guid, string>>();
                 var list = new List<Tuple<Guid, string>>();
                 var count = 0;
                 var count = 0;
 
 
-                _logger.Debug(cmd.CommandText);
+                Logger.Debug(cmd.CommandText);
 
 
                 using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                 using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                 {
                 {
@@ -1731,7 +1682,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
                 var list = new List<Guid>();
                 var list = new List<Guid>();
                 var count = 0;
                 var count = 0;
 
 
-                _logger.Debug(cmd.CommandText);
+                Logger.Debug(cmd.CommandText);
 
 
                 using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                 using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                 {
                 {
@@ -2075,7 +2026,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
                 return;
                 return;
             }
             }
             
             
-            await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
+            await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
 
 
             IDbTransaction transaction = null;
             IDbTransaction transaction = null;
 
 
@@ -2107,7 +2058,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
-                _logger.ErrorException("Error running query:", e);
+                Logger.ErrorException("Error running query:", e);
 
 
                 if (transaction != null)
                 if (transaction != null)
                 {
                 {
@@ -2123,7 +2074,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
                     transaction.Dispose();
                     transaction.Dispose();
                 }
                 }
 
 
-                _writeLock.Release();
+                WriteLock.Release();
             }
             }
         }
         }
 
 
@@ -2168,7 +2119,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
 
 
             CheckDisposed();
             CheckDisposed();
 
 
-            await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
+            await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
 
 
             IDbTransaction transaction = null;
             IDbTransaction transaction = null;
 
 
@@ -2219,7 +2170,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
-                _logger.ErrorException("Failed to save children:", e);
+                Logger.ErrorException("Failed to save children:", e);
 
 
                 if (transaction != null)
                 if (transaction != null)
                 {
                 {
@@ -2235,7 +2186,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
                     transaction.Dispose();
                     transaction.Dispose();
                 }
                 }
 
 
-                _writeLock.Release();
+                WriteLock.Release();
             }
             }
         }
         }
 
 
@@ -2253,7 +2204,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
 
 
             CheckDisposed();
             CheckDisposed();
 
 
-            await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
+            await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
 
 
             IDbTransaction transaction = null;
             IDbTransaction transaction = null;
 
 
@@ -2292,7 +2243,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
-                _logger.ErrorException("Failed to save children:", e);
+                Logger.ErrorException("Failed to save children:", e);
 
 
                 if (transaction != null)
                 if (transaction != null)
                 {
                 {
@@ -2308,7 +2259,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
                     transaction.Dispose();
                     transaction.Dispose();
                 }
                 }
 
 
-                _writeLock.Release();
+                WriteLock.Release();
             }
             }
         }
         }
 
 
@@ -2482,7 +2433,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
 
 
             var cancellationToken = CancellationToken.None;
             var cancellationToken = CancellationToken.None;
 
 
-            await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
+            await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
 
 
             IDbTransaction transaction = null;
             IDbTransaction transaction = null;
 
 
@@ -2528,7 +2479,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
-                _logger.ErrorException("Failed to save people:", e);
+                Logger.ErrorException("Failed to save people:", e);
 
 
                 if (transaction != null)
                 if (transaction != null)
                 {
                 {
@@ -2544,7 +2495,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
                     transaction.Dispose();
                     transaction.Dispose();
                 }
                 }
 
 
-                _writeLock.Release();
+                WriteLock.Release();
             }
             }
         }
         }
 
 
@@ -2631,7 +2582,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
 
 
             cancellationToken.ThrowIfCancellationRequested();
             cancellationToken.ThrowIfCancellationRequested();
 
 
-            await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
+            await WriteLock.WaitAsync(cancellationToken).ConfigureAwait(false);
 
 
             IDbTransaction transaction = null;
             IDbTransaction transaction = null;
 
 
@@ -2703,7 +2654,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
             }
             }
             catch (Exception e)
             catch (Exception e)
             {
             {
-                _logger.ErrorException("Failed to save media streams:", e);
+                Logger.ErrorException("Failed to save media streams:", e);
 
 
                 if (transaction != null)
                 if (transaction != null)
                 {
                 {
@@ -2719,7 +2670,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
                     transaction.Dispose();
                     transaction.Dispose();
                 }
                 }
 
 
-                _writeLock.Release();
+                WriteLock.Release();
             }
             }
         }
         }
 
 

+ 1 - 19
MediaBrowser.Server.Implementations/Sync/SyncRepository.cs

@@ -64,7 +64,7 @@ namespace MediaBrowser.Server.Implementations.Sync
 
 
             _connection.AddColumn(Logger, "SyncJobs", "Profile", "TEXT");
             _connection.AddColumn(Logger, "SyncJobs", "Profile", "TEXT");
             _connection.AddColumn(Logger, "SyncJobs", "Bitrate", "INT");
             _connection.AddColumn(Logger, "SyncJobs", "Bitrate", "INT");
-         
+
             PrepareStatements();
             PrepareStatements();
         }
         }
 
 
@@ -800,24 +800,6 @@ namespace MediaBrowser.Server.Implementations.Sync
             return item;
             return item;
         }
         }
 
 
-        private bool _disposed;
-        private void CheckDisposed()
-        {
-            if (_disposed)
-            {
-                throw new ObjectDisposedException(GetType().Name + " has been disposed and cannot be accessed.");
-            }
-        }
-
-        protected override void Dispose(bool dispose)
-        {
-            if (dispose)
-            {
-                _disposed = true;
-            }
-            base.Dispose(dispose);
-        }
-
         protected override void CloseConnection()
         protected override void CloseConnection()
         {
         {
             if (_connection != null)
             if (_connection != null)

+ 1 - 1
MediaBrowser.Server.Startup.Common/ApplicationHost.cs

@@ -692,7 +692,7 @@ namespace MediaBrowser.Server.Startup.Common
 
 
         private async Task<IActivityRepository> GetActivityLogRepository()
         private async Task<IActivityRepository> GetActivityLogRepository()
         {
         {
-            var repo = new ActivityRepository(LogManager.GetLogger("ActivityRepository"), ServerConfigurationManager.ApplicationPaths);
+            var repo = new ActivityRepository(LogManager, ServerConfigurationManager.ApplicationPaths);
 
 
             await repo.Initialize().ConfigureAwait(false);
             await repo.Initialize().ConfigureAwait(false);