mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Cache generated mapping file
- Created a modified version of FluentNHibernate, including [Serializable] on GenericEnumWrapper class for it --HG-- branch : dev
This commit is contained in:
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@@ -20,7 +20,6 @@ namespace Orchard.Data.Migration.Interpreters {
|
|||||||
private readonly ISession _session;
|
private readonly ISession _session;
|
||||||
private readonly Dialect _dialect;
|
private readonly Dialect _dialect;
|
||||||
private readonly List<string> _sqlStatements;
|
private readonly List<string> _sqlStatements;
|
||||||
private readonly IDataServicesProviderFactory _dataServicesProviderFactory;
|
|
||||||
private readonly ISessionFactoryHolder _sessionFactoryHolder;
|
private readonly ISessionFactoryHolder _sessionFactoryHolder;
|
||||||
private readonly IReportsCoordinator _reportsCoordinator;
|
private readonly IReportsCoordinator _reportsCoordinator;
|
||||||
|
|
||||||
@@ -30,21 +29,18 @@ namespace Orchard.Data.Migration.Interpreters {
|
|||||||
ShellSettings shellSettings,
|
ShellSettings shellSettings,
|
||||||
ISessionLocator sessionLocator,
|
ISessionLocator sessionLocator,
|
||||||
IEnumerable<ICommandInterpreter> commandInterpreters,
|
IEnumerable<ICommandInterpreter> commandInterpreters,
|
||||||
IDataServicesProviderFactory dataServicesProviderFactory,
|
|
||||||
ISessionFactoryHolder sessionFactoryHolder,
|
ISessionFactoryHolder sessionFactoryHolder,
|
||||||
IReportsCoordinator reportsCoordinator) {
|
IReportsCoordinator reportsCoordinator) {
|
||||||
_shellSettings = shellSettings;
|
_shellSettings = shellSettings;
|
||||||
_commandInterpreters = commandInterpreters;
|
_commandInterpreters = commandInterpreters;
|
||||||
_session = sessionLocator.For(typeof(DefaultDataMigrationInterpreter));
|
_session = sessionLocator.For(typeof(DefaultDataMigrationInterpreter));
|
||||||
_sqlStatements = new List<string>();
|
_sqlStatements = new List<string>();
|
||||||
_dataServicesProviderFactory = dataServicesProviderFactory;
|
|
||||||
_sessionFactoryHolder = sessionFactoryHolder;
|
_sessionFactoryHolder = sessionFactoryHolder;
|
||||||
_reportsCoordinator = reportsCoordinator;
|
_reportsCoordinator = reportsCoordinator;
|
||||||
|
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
|
|
||||||
var parameters = _sessionFactoryHolder.GetSessionFactoryParameters();
|
var configuration = _sessionFactoryHolder.GetConfiguration();
|
||||||
var configuration = _dataServicesProviderFactory.CreateProvider(parameters).BuildConfiguration(parameters);
|
|
||||||
_dialect = Dialect.GetDialect(configuration.Properties);
|
_dialect = Dialect.GetDialect(configuration.Properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
using NHibernate;
|
using System.IO;
|
||||||
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
|
using NHibernate;
|
||||||
|
using NHibernate.Cfg;
|
||||||
using Orchard.Data.Providers;
|
using Orchard.Data.Providers;
|
||||||
using Orchard.Environment.Configuration;
|
using Orchard.Environment.Configuration;
|
||||||
using Orchard.Environment.ShellBuilders.Models;
|
using Orchard.Environment.ShellBuilders.Models;
|
||||||
@@ -9,6 +12,7 @@ using Orchard.Logging;
|
|||||||
namespace Orchard.Data {
|
namespace Orchard.Data {
|
||||||
public interface ISessionFactoryHolder : ISingletonDependency {
|
public interface ISessionFactoryHolder : ISingletonDependency {
|
||||||
ISessionFactory GetSessionFactory();
|
ISessionFactory GetSessionFactory();
|
||||||
|
Configuration GetConfiguration();
|
||||||
SessionFactoryParameters GetSessionFactoryParameters();
|
SessionFactoryParameters GetSessionFactoryParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,6 +23,7 @@ namespace Orchard.Data {
|
|||||||
private readonly IAppDataFolder _appDataFolder;
|
private readonly IAppDataFolder _appDataFolder;
|
||||||
|
|
||||||
private ISessionFactory _sessionFactory;
|
private ISessionFactory _sessionFactory;
|
||||||
|
private Configuration _configuration;
|
||||||
|
|
||||||
public SessionFactoryHolder(
|
public SessionFactoryHolder(
|
||||||
ShellSettings shellSettings,
|
ShellSettings shellSettings,
|
||||||
@@ -46,17 +51,46 @@ namespace Orchard.Data {
|
|||||||
return _sessionFactory;
|
return _sessionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Configuration GetConfiguration() {
|
||||||
|
lock ( this ) {
|
||||||
|
if ( _configuration == null ) {
|
||||||
|
_configuration = BuildConfiguration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _configuration;
|
||||||
|
}
|
||||||
|
|
||||||
private ISessionFactory BuildSessionFactory() {
|
private ISessionFactory BuildSessionFactory() {
|
||||||
Logger.Debug("Building session factory");
|
Logger.Debug("Building session factory");
|
||||||
|
|
||||||
|
var config = GetConfiguration();
|
||||||
|
return config.BuildSessionFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Configuration BuildConfiguration() {
|
||||||
var parameters = GetSessionFactoryParameters();
|
var parameters = GetSessionFactoryParameters();
|
||||||
|
|
||||||
var sessionFactory = _dataServicesProviderFactory
|
Configuration config = null;
|
||||||
.CreateProvider(parameters)
|
var bf = new BinaryFormatter();
|
||||||
.BuildConfiguration(parameters)
|
|
||||||
.BuildSessionFactory();
|
|
||||||
|
|
||||||
return sessionFactory;
|
var filename = _appDataFolder.MapPath(_appDataFolder.Combine("Sites", "mappings.bin"));
|
||||||
|
if(_appDataFolder.FileExists(filename)) {
|
||||||
|
Logger.Debug("Loading mappings from cached file");
|
||||||
|
using ( var stream = File.OpenRead(filename) ) {
|
||||||
|
config = bf.Deserialize(stream) as Configuration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Logger.Debug("Generating mappings and cached file");
|
||||||
|
config = _dataServicesProviderFactory
|
||||||
|
.CreateProvider(parameters)
|
||||||
|
.BuildConfiguration(parameters);
|
||||||
|
|
||||||
|
using ( var stream = File.OpenWrite(filename) ) {
|
||||||
|
bf.Serialize(stream, config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SessionFactoryParameters GetSessionFactoryParameters() {
|
public SessionFactoryParameters GetSessionFactoryParameters() {
|
||||||
|
|||||||
Reference in New Issue
Block a user