From 8ce222a10cbac061891356928b2d3e18766a6b36 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 28 Aug 2011 20:05:31 -0700 Subject: [PATCH] Should fix the transaction issues in petapoco, we are getting to far petapoco master which I don't like. --- NzbDrone.Core/CentralDispatch.cs | 10 +++++----- NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs | 21 +++++++------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/NzbDrone.Core/CentralDispatch.cs b/NzbDrone.Core/CentralDispatch.cs index c53f96dc7..f4ce5ba1b 100644 --- a/NzbDrone.Core/CentralDispatch.cs +++ b/NzbDrone.Core/CentralDispatch.cs @@ -74,11 +74,11 @@ namespace NzbDrone.Core Logger.Debug("Binding Ninject's Kernel"); _kernel = new StandardKernel(); - _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString)).InRequestScope(); - _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto(); - _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto(); - _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString, false)).WhenInjectedInto().InSingletonScope(); - _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString)).WhenInjectedInto().InRequestScope(); + _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString)).InTransientScope(); + //_kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto(); + //_kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto(); + //_kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString, false)).WhenInjectedInto().InSingletonScope(); + _kernel.Bind().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString)).WhenInjectedInto().InSingletonScope(); } } diff --git a/NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs b/NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs index 3497f2794..e0027035f 100644 --- a/NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs +++ b/NzbDrone.Core/Datastore/PetaPoco/PetaPoco.cs @@ -342,7 +342,6 @@ namespace PetaPoco // Common initialization private void CommonConstruct() { - _transactionDepth = 0; ForceDateTimesToUtc = true; EnableAutoSelect = true; @@ -407,6 +406,7 @@ namespace PetaPoco OnConnectionClosing(_sharedConnection); _sharedConnection.Dispose(); _sharedConnection = null; + _transaction = null; } } @@ -441,15 +441,11 @@ namespace PetaPoco // Use `using (var scope=db.Transaction) { scope.Complete(); }` to ensure correct semantics public void BeginTransaction(IsolationLevel? isolationLevel) { - _transactionDepth++; + OpenSharedConnection(); + _transaction = isolationLevel == null ? _sharedConnection.BeginTransaction() : _sharedConnection.BeginTransaction(isolationLevel.Value); + _transactionCancelled = false; + OnBeginTransaction(); - if (_transactionDepth == 1) - { - OpenSharedConnection(); - _transaction = isolationLevel == null ? _sharedConnection.BeginTransaction() : _sharedConnection.BeginTransaction(isolationLevel.Value); - _transactionCancelled = false; - OnBeginTransaction(); - } } @@ -473,15 +469,13 @@ namespace PetaPoco public void AbortTransaction() { _transactionCancelled = true; - if ((--_transactionDepth) == 0) - CleanupTransaction(); + CleanupTransaction(); } // Complete the transaction public void CompleteTransaction() { - if ((--_transactionDepth) == 0) - CleanupTransaction(); + CleanupTransaction(); } // Helper to handle named parameters from object properties @@ -2524,7 +2518,6 @@ namespace PetaPoco DbProviderFactory _factory; IDbConnection _sharedConnection; IDbTransaction _transaction; - int _transactionDepth; bool _transactionCancelled; string _lastSql; object[] _lastArgs;