From 613f4296e395b0442984e472a996eaadc07915fe Mon Sep 17 00:00:00 2001 From: cvium Date: Mon, 21 Aug 2023 12:13:32 +0200 Subject: loading works --- Emby.Server.Implementations/Data/ConnectionPool.cs | 79 ---------------------- 1 file changed, 79 deletions(-) delete mode 100644 Emby.Server.Implementations/Data/ConnectionPool.cs (limited to 'Emby.Server.Implementations/Data/ConnectionPool.cs') diff --git a/Emby.Server.Implementations/Data/ConnectionPool.cs b/Emby.Server.Implementations/Data/ConnectionPool.cs deleted file mode 100644 index 5ea7e934f..000000000 --- a/Emby.Server.Implementations/Data/ConnectionPool.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections.Concurrent; -using SQLitePCL.pretty; - -namespace Emby.Server.Implementations.Data; - -/// -/// A pool of SQLite Database connections. -/// -public sealed class ConnectionPool : IDisposable -{ - private readonly BlockingCollection _connections = new(); - private bool _disposed; - - /// - /// Initializes a new instance of the class. - /// - /// The number of database connection to create. - /// Factory function to create the database connections. - public ConnectionPool(int count, Func factory) - { - for (int i = 0; i < count; i++) - { - _connections.Add(factory.Invoke()); - } - } - - /// - /// Gets a database connection from the pool if one is available, otherwise blocks. - /// - /// A database connection. - public ManagedConnection GetConnection() - { - if (_disposed) - { - ThrowObjectDisposedException(); - } - - return new ManagedConnection(_connections.Take(), this); - - static void ThrowObjectDisposedException() - { - throw new ObjectDisposedException(nameof(ConnectionPool)); - } - } - - /// - /// Return a database connection to the pool. - /// - /// The database connection to return. - public void Return(SQLiteDatabaseConnection connection) - { - if (_disposed) - { - connection.Dispose(); - return; - } - - _connections.Add(connection); - } - - /// - public void Dispose() - { - if (_disposed) - { - return; - } - - foreach (var connection in _connections) - { - connection.Dispose(); - } - - _connections.Dispose(); - - _disposed = true; - } -} -- cgit v1.2.3