|
|
@ -7,7 +7,6 @@ using MediaBrowser.Model.Serialization;
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Data;
|
|
|
|
using System.Data;
|
|
|
|
using System.Data.SQLite;
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading;
|
|
|
@ -20,7 +19,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class SqliteItemRepository : IItemRepository
|
|
|
|
public class SqliteItemRepository : IItemRepository
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private SQLiteConnection _connection;
|
|
|
|
private IDbConnection _connection;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
|
@ -52,14 +51,14 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// The _save item command
|
|
|
|
/// The _save item command
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private SQLiteCommand _saveItemCommand;
|
|
|
|
private IDbCommand _saveItemCommand;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly string _criticReviewsPath;
|
|
|
|
private readonly string _criticReviewsPath;
|
|
|
|
|
|
|
|
|
|
|
|
private SqliteChapterRepository _chapterRepository;
|
|
|
|
private SqliteChapterRepository _chapterRepository;
|
|
|
|
|
|
|
|
|
|
|
|
private SQLiteCommand _deleteChildrenCommand;
|
|
|
|
private IDbCommand _deleteChildrenCommand;
|
|
|
|
private SQLiteCommand _saveChildrenCommand;
|
|
|
|
private IDbCommand _saveChildrenCommand;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
|
|
|
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
|
|
@ -136,29 +135,20 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
private void PrepareStatements()
|
|
|
|
private void PrepareStatements()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_saveItemCommand = new SQLiteCommand
|
|
|
|
_saveItemCommand = _connection.CreateCommand();
|
|
|
|
{
|
|
|
|
_saveItemCommand.CommandText = "replace into TypedBaseItems (guid, type, data) values (@1, @2, @3)";
|
|
|
|
CommandText = "replace into TypedBaseItems (guid, type, data) values (@1, @2, @3)"
|
|
|
|
_saveItemCommand.Parameters.Add(_saveItemCommand, "@1");
|
|
|
|
};
|
|
|
|
_saveItemCommand.Parameters.Add(_saveItemCommand, "@2");
|
|
|
|
|
|
|
|
_saveItemCommand.Parameters.Add(_saveItemCommand, "@3");
|
|
|
|
_saveItemCommand.Parameters.Add(new SQLiteParameter("@1"));
|
|
|
|
|
|
|
|
_saveItemCommand.Parameters.Add(new SQLiteParameter("@2"));
|
|
|
|
|
|
|
|
_saveItemCommand.Parameters.Add(new SQLiteParameter("@3"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_deleteChildrenCommand = new SQLiteCommand
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
CommandText = "delete from ChildrenIds where ParentId=@ParentId"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_deleteChildrenCommand.Parameters.Add(new SQLiteParameter("@ParentId"));
|
|
|
|
_deleteChildrenCommand = _connection.CreateCommand();
|
|
|
|
|
|
|
|
_deleteChildrenCommand.CommandText = "delete from ChildrenIds where ParentId=@ParentId";
|
|
|
|
|
|
|
|
_deleteChildrenCommand.Parameters.Add(_deleteChildrenCommand, "@ParentId");
|
|
|
|
|
|
|
|
|
|
|
|
_saveChildrenCommand = new SQLiteCommand
|
|
|
|
_saveChildrenCommand = _connection.CreateCommand();
|
|
|
|
{
|
|
|
|
_saveChildrenCommand.CommandText = "replace into ChildrenIds (ParentId, ItemId) values (@ParentId, @ItemId)";
|
|
|
|
CommandText = "replace into ChildrenIds (ParentId, ItemId) values (@ParentId, @ItemId)"
|
|
|
|
_saveChildrenCommand.Parameters.Add(_saveChildrenCommand, "@ParentId");
|
|
|
|
};
|
|
|
|
_saveChildrenCommand.Parameters.Add(_saveChildrenCommand, "@ItemId");
|
|
|
|
|
|
|
|
|
|
|
|
_saveChildrenCommand.Parameters.Add(new SQLiteParameter("@ParentId"));
|
|
|
|
|
|
|
|
_saveChildrenCommand.Parameters.Add(new SQLiteParameter("@ItemId"));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -205,7 +195,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|
|
|
|
|
|
|
|
|
|
|
await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
|
|
await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
SQLiteTransaction transaction = null;
|
|
|
|
IDbTransaction transaction = null;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -215,13 +205,13 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
|
|
_saveItemCommand.Parameters[0].Value = item.Id;
|
|
|
|
_saveItemCommand.GetParameter(0).Value = item.Id;
|
|
|
|
_saveItemCommand.Parameters[1].Value = item.GetType().FullName;
|
|
|
|
_saveItemCommand.GetParameter(1).Value = item.GetType().FullName;
|
|
|
|
_saveItemCommand.Parameters[2].Value = _jsonSerializer.SerializeToBytes(item);
|
|
|
|
_saveItemCommand.GetParameter(2).Value = _jsonSerializer.SerializeToBytes(item);
|
|
|
|
|
|
|
|
|
|
|
|
_saveItemCommand.Transaction = transaction;
|
|
|
|
_saveItemCommand.Transaction = transaction;
|
|
|
|
|
|
|
|
|
|
|
|
await _saveItemCommand.ExecuteNonQueryAsync(cancellationToken);
|
|
|
|
_saveItemCommand.ExecuteNonQuery();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
transaction.Commit();
|
|
|
|
transaction.Commit();
|
|
|
@ -274,8 +264,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|
|
|
using (var cmd = _connection.CreateCommand())
|
|
|
|
using (var cmd = _connection.CreateCommand())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cmd.CommandText = "select type,data from TypedBaseItems where guid = @guid";
|
|
|
|
cmd.CommandText = "select type,data from TypedBaseItems where guid = @guid";
|
|
|
|
var guidParam = cmd.Parameters.Add("@guid", DbType.Guid);
|
|
|
|
cmd.Parameters.Add(cmd, "@guid", DbType.Guid).Value = id;
|
|
|
|
guidParam.Value = id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow))
|
|
|
|
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult | CommandBehavior.SingleRow))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -446,7 +435,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cmd.CommandText = "select ItemId from ChildrenIds where ParentId = @ParentId";
|
|
|
|
cmd.CommandText = "select ItemId from ChildrenIds where ParentId = @ParentId";
|
|
|
|
|
|
|
|
|
|
|
|
cmd.Parameters.Add("@ParentId", DbType.Guid).Value = parentId;
|
|
|
|
cmd.Parameters.Add(cmd, "@ParentId", DbType.Guid).Value = parentId;
|
|
|
|
|
|
|
|
|
|
|
|
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
|
|
|
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -479,27 +468,28 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|
|
|
|
|
|
|
|
|
|
|
await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
|
|
await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
|
|
SQLiteTransaction transaction = null;
|
|
|
|
IDbTransaction transaction = null;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
transaction = _connection.BeginTransaction();
|
|
|
|
transaction = _connection.BeginTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
// First delete
|
|
|
|
// First delete
|
|
|
|
_deleteChildrenCommand.Parameters[0].Value = parentId;
|
|
|
|
_deleteChildrenCommand.GetParameter(0).Value = parentId;
|
|
|
|
_deleteChildrenCommand.Transaction = transaction;
|
|
|
|
_deleteChildrenCommand.Transaction = transaction;
|
|
|
|
await _deleteChildrenCommand.ExecuteNonQueryAsync(cancellationToken);
|
|
|
|
|
|
|
|
|
|
|
|
_deleteChildrenCommand.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var id in children)
|
|
|
|
foreach (var id in children)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
|
|
|
|
_saveChildrenCommand.Parameters[0].Value = parentId;
|
|
|
|
_saveChildrenCommand.GetParameter(0).Value = parentId;
|
|
|
|
_saveChildrenCommand.Parameters[1].Value = id;
|
|
|
|
_saveChildrenCommand.GetParameter(1).Value = id;
|
|
|
|
|
|
|
|
|
|
|
|
_saveChildrenCommand.Transaction = transaction;
|
|
|
|
_saveChildrenCommand.Transaction = transaction;
|
|
|
|
|
|
|
|
|
|
|
|
await _saveChildrenCommand.ExecuteNonQueryAsync(cancellationToken);
|
|
|
|
_saveChildrenCommand.ExecuteNonQuery();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
transaction.Commit();
|
|
|
|
transaction.Commit();
|
|
|
|