Refactoring DefaultDataMigrationInterpreter to remove an early Transaction resolution

--HG--
branch : 1.x
extra : transplant_source : %E2%0DSw%17%5E%17%22D%BDLhy%B5%5Bk%A9%08%EB%F0
This commit is contained in:
Sebastien Ros
2012-02-04 21:39:15 -08:00
parent ef66c75cf7
commit 06ee641608
2 changed files with 6 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ using System.Text;
using NHibernate; using NHibernate;
using NHibernate.Dialect; using NHibernate.Dialect;
using NHibernate.SqlTypes; using NHibernate.SqlTypes;
using Orchard.ContentManagement.Records;
using Orchard.Data.Migration.Schema; using Orchard.Data.Migration.Schema;
using Orchard.Environment.Configuration; using Orchard.Environment.Configuration;
using Orchard.Localization; using Orchard.Localization;
@@ -16,8 +17,8 @@ using Orchard.Reports.Services;
namespace Orchard.Data.Migration.Interpreters { namespace Orchard.Data.Migration.Interpreters {
public class DefaultDataMigrationInterpreter : AbstractDataMigrationInterpreter, IDataMigrationInterpreter { public class DefaultDataMigrationInterpreter : AbstractDataMigrationInterpreter, IDataMigrationInterpreter {
private readonly ShellSettings _shellSettings; private readonly ShellSettings _shellSettings;
private readonly ISessionLocator _sessionLocator;
private readonly IEnumerable<ICommandInterpreter> _commandInterpreters; private readonly IEnumerable<ICommandInterpreter> _commandInterpreters;
private readonly ISession _session;
private readonly Dialect _dialect; private readonly Dialect _dialect;
private readonly List<string> _sqlStatements; private readonly List<string> _sqlStatements;
private readonly ISessionFactoryHolder _sessionFactoryHolder; private readonly ISessionFactoryHolder _sessionFactoryHolder;
@@ -32,8 +33,8 @@ namespace Orchard.Data.Migration.Interpreters {
ISessionFactoryHolder sessionFactoryHolder, ISessionFactoryHolder sessionFactoryHolder,
IReportsCoordinator reportsCoordinator) { IReportsCoordinator reportsCoordinator) {
_shellSettings = shellSettings; _shellSettings = shellSettings;
_sessionLocator = sessionLocator;
_commandInterpreters = commandInterpreters; _commandInterpreters = commandInterpreters;
_session = sessionLocator.For(typeof(DefaultDataMigrationInterpreter));
_sqlStatements = new List<string>(); _sqlStatements = new List<string>();
_sessionFactoryHolder = sessionFactoryHolder; _sessionFactoryHolder = sessionFactoryHolder;
_reportsCoordinator = reportsCoordinator; _reportsCoordinator = reportsCoordinator;
@@ -335,7 +336,8 @@ namespace Orchard.Data.Migration.Interpreters {
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "Nothing comes from user input.")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "Nothing comes from user input.")]
private void RunPendingStatements() { private void RunPendingStatements() {
var connection = _session.Connection; var session = _sessionLocator.For(typeof(ContentItemRecord));
var connection = session.Connection;
foreach (var sqlStatement in _sqlStatements) { foreach (var sqlStatement in _sqlStatements) {
Logger.Debug(sqlStatement); Logger.Debug(sqlStatement);

View File

@@ -31,19 +31,14 @@ namespace Orchard.Data {
_transactionManager.Demand(); _transactionManager.Demand();
Logger.Information("Openning database session"); Logger.Information("Openning database session");
_session = sessionFactory.OpenSession(new SessionInterceptor(this)); _session = sessionFactory.OpenSession(new SessionInterceptor());
} }
return _session; return _session;
} }
class SessionInterceptor : IInterceptor { class SessionInterceptor : IInterceptor {
private readonly SessionLocator _sessionLocator;
private ISession _session; private ISession _session;
public SessionInterceptor(SessionLocator sessionLocator) {
_sessionLocator = sessionLocator;
}
bool IInterceptor.OnLoad(object entity, object id, object[] state, string[] propertyNames, IType[] types) { bool IInterceptor.OnLoad(object entity, object id, object[] state, string[] propertyNames, IType[] types) {
return false; return false;
} }